Skip to content

Commit

Permalink
Merge pull request #409 from dmurdoch/shapenum
Browse files Browse the repository at this point in the history
Use "shapenum", not "indices" in sprite attributes.
  • Loading branch information
dmurdoch authored Feb 13, 2024
2 parents 84ea872 + 79dbf95 commit 09462bd
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion R/enum.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ rgl.enum( attrib, vertices=1, normals=2, colors=3, texcoords=4, dim=5,
texts=6, cex=7, adj=8, radii=9, centers=10, ids=11,
usermatrix=12, types=13, flags=14, offsets=15,
family=16, font=17, pos=18, fogscale=19, axes=20,
indices=21)
indices=21, shapenum=22)

rgl.enum.pixfmt <- function(fmt)
rgl.enum( fmt, png=0 )
Expand Down
2 changes: 1 addition & 1 deletion R/getscene.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ scene3d <- function(minimal = TRUE) {
attribs <- c("vertices", "colors", "texcoords", "dim",
"texts", "cex", "adj", "radii", "ids",
"usermatrix", "types", "offsets", "centers",
"family", "font", "pos", "axes", "indices", "normals")
"family", "font", "pos", "axes", "indices", "normals", "shapenum")
for (a in attribs)
if (rgl.attrib.count(id, a))
result[[a]] <- rgl.attrib(id, a)
Expand Down
5 changes: 3 additions & 2 deletions R/scene.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ rgl.attrib.ncol.values <- c(vertices=3, normals=3, colors=4, texcoords=2, dim=2,
texts=1, cex=1, adj=3, radii=1, centers=3, ids=1,
usermatrix=4, types=1, flags=1, offsets=1,
family=1, font=1, pos=1, fogscale=1, axes=3,
indices=1)
indices=1, shapenum=1)

rgl.attrib.info <- function( id = ids3d("all", 0)$id, attribs = NULL, showAll = FALSE) {
ncol <- rgl.attrib.ncol.values
Expand Down Expand Up @@ -206,7 +206,8 @@ rgl.attrib <- function( id, attrib, first=1,
"pos", # pos
"fogscale", # fogscale
c("x", "y", "z"), # axes
"vertex" # indices
"vertex", # indices
"shape"
)[[attrib]]
if (attrib == 14 && count) # flags
if (id %in% ids3d("lights", subscene = 0)$id)
Expand Down
6 changes: 3 additions & 3 deletions inst/htmlwidgets/lib/rglClass/init.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,14 +864,14 @@
} else
obj.offset = 0;

obj.indices = rglwidgetClass.flatten(obj.indices);
var shapenum = rglwidgetClass.flatten(obj.shapenum);
obj.shapelens = [];
obj.shapefirst = [];
obj.shapefirst.push(0);
len = 0;
current = 0;
for (i = 0; i < obj.indices.length; i++) {
if (obj.indices[i] === obj.indices[current]) {
for (i = 0; i < shapenum.length; i++) {
if (shapenum[i] === shapenum[current]) {
len++;
} else {
obj.shapelens.push(len);
Expand Down
5 changes: 3 additions & 2 deletions man/sprites.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ Entries will be recycled as needed.
If any coordinate is \code{NA}, the sprite is not plotted.

The id values of the shapes may be retrieved after plotting
using \code{rgl.attrib(id, "ids")}, the associated vertex
is retrievable in \code{rgl.attrib(id, "indices")}, and
using \code{rgl.attrib(id, "ids")}, the associated entry
in \code{shapes}
is retrievable in \code{rgl.attrib(id, "shapenum")}, and
the user matrix is retrieved using \code{rgl.attrib(id, "usermatrix")}.
}
\note{
Expand Down
1 change: 1 addition & 0 deletions src/SceneNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ typedef int ObjID;
#define FOGSCALE 19
#define AXES 20
#define INDICES 21
#define SHAPENUM 22

typedef unsigned int AttribID;

Expand Down
4 changes: 2 additions & 2 deletions src/SpriteSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ int SpriteSet::getAttributeCount(SceneNode* subscene, AttribID attrib)
case VERTICES: return vertex.size();
case RADII: return size.size();
case IDS:
case INDICES:
case SHAPENUM:
case TYPES: return static_cast<int>(shapes.size());
case USERMATRIX: {
if (!shapes.size()) return 0;
Expand Down Expand Up @@ -356,7 +356,7 @@ void SpriteSet::getAttribute(SceneNode* subscene, AttribID attrib, int first, in
ind++;
}
return;
case INDICES:
case SHAPENUM:
ind = 1;
for (int i = 0; i < shapelens.size(); i++) {
res++;
Expand Down
Binary file modified tests/testthat/testdata/r3d.rds
Binary file not shown.

0 comments on commit 09462bd

Please sign in to comment.