Skip to content

Commit 3016481

Browse files
dmurdochcran-robot
authored andcommitted
version 0.110.2
1 parent 3bccbb4 commit 3016481

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+800
-544
lines changed

DESCRIPTION

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: rgl
2-
Version: 0.109.6
2+
Version: 0.110.2
33
Title: 3D Visualization Using OpenGL
44
Authors@R: c(person("Duncan", "Murdoch", role = c("aut", "cre"),
55
email = "murdoch.duncan@gmail.com"),
@@ -51,9 +51,9 @@ SystemRequirements: OpenGL and GLU Library (Required for display in R.
5151
BugReports: https://github.com/dmurdoch/rgl/issues
5252
VignetteBuilder: knitr, rmarkdown
5353
Biarch: true
54-
RoxygenNote: 7.1.2
54+
RoxygenNote: 7.2.0
5555
NeedsCompilation: yes
56-
Packaged: 2022-07-07 23:44:06 UTC; murdoch
56+
Packaged: 2022-09-05 13:37:46 UTC; murdoch
5757
Author: Duncan Murdoch [aut, cre],
5858
Daniel Adler [aut],
5959
Oleg Nenadic [ctb],
@@ -78,4 +78,4 @@ Author: Duncan Murdoch [aut, cre],
7878
Mike Stein [ctb]
7979
Maintainer: Duncan Murdoch <murdoch.duncan@gmail.com>
8080
Repository: CRAN
81-
Date/Publication: 2022-07-08 23:30:02 UTC
81+
Date/Publication: 2022-09-26 12:10:03 UTC

MD5

+52-53
Large diffs are not rendered by default.

NAMESPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export(rglwidget, renderRglwidget, rglwidgetOutput,
181181

182182
importFrom(htmlwidgets, createWidget, prependContent, saveWidget,
183183
shinyRenderWidget, shinyWidgetOutput, sizingPolicy)
184-
importFrom(htmltools, css, HTML, htmlDependency, img,
184+
importFrom(htmltools, css, HTML, htmlDependency, htmlPreserve, img,
185185
includeScript, tags, tagAppendAttributes,
186186
tagHasAttribute, tagList, browsable, resolveDependencies)
187187
importFrom(jsonlite, toJSON, base64_dec)

NEWS.md

+50
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,53 @@
1+
2+
# rgl 0.110.2
3+
4+
## Major changes
5+
6+
* Material property `"blend"` has been added, to allow
7+
various kinds of blending for semi-transparent objects
8+
(issue #245).
9+
10+
## Minor changes
11+
12+
* The `Buffer` object now handles reading of sparse
13+
accessors.
14+
* Low level drawing of primitives has been made more
15+
memory efficient. This is only likely to make a
16+
noticeable change with very large objects, where R
17+
was running out of memory because of unnecessary
18+
duplication. (Related to issue #260.)
19+
* Recycling of x, y and z vectors in several functions
20+
is more consistent.
21+
* The `polygon3d()` function now chooses coordinates
22+
automatically, as `triangulate()` does (PR #262.)
23+
* The `mtext3d()` and related functions such as
24+
`title3d()' now accept language objects
25+
other than expressions, as `plotmath3d()` always has
26+
(issue #273).
27+
28+
## Bug fixes
29+
30+
* The bounding box could be calculated incorrectly
31+
if data all had large values (issue #250).
32+
* Shiny displays failed to load the shaders (issue #249).
33+
* `transform3d()` failed due to missing argument (issue #253).
34+
* `readOBJ()` is now more flexible in what kinds of
35+
separators it will accept. (issue #258).
36+
* Failure to initialize could cause a segfault.
37+
* On non-macOS platforms, gray-scale textures failed
38+
to display, with a message about an invalid enumerant.
39+
* The third coordinate for `adj` that was added in 0.108.3
40+
was not rendered properly in `rglwidget()` displays of
41+
text. This sometimes caused text to disappear when it
42+
was near the far limit of the display (issue #269).
43+
* The X11 error fix in 0.109.6 could result in R
44+
freezing in `Rcmdr`.
45+
* Low level drawing functions are now more consistent
46+
about returning an invisible `NULL` if asked to plot zero
47+
items, rather than raising an error or crashing (issue #274).
48+
* Calling `axis3d()` with no ticks or labels no longer triggers
49+
an error, it now silently returns `NULL`.
50+
151
# rgl 0.109.6
252

353
## Minor changes

R/as.mesh3d.default.R

+4-8
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ as.mesh3d.default <- function(x, y = NULL, z = NULL,
1010
x <- rglId(ids3d()$id)
1111
return(as.mesh3d(x, ...))
1212
}
13-
xyz <- xyz.coords(x, y, z, recycle = TRUE)
14-
x <- xyz$x
15-
y <- xyz$y
16-
z <- xyz$z
13+
verts <- rgl.vertex(x, y, z)
1714
if (!missing(triangles)) {
1815
warning("Argument 'triangles' is deprecated; please use 'type' instead.")
1916
if (missing(type)) {
@@ -25,7 +22,7 @@ as.mesh3d.default <- function(x, y = NULL, z = NULL,
2522
}
2623
type <- match.arg(type, several.ok = TRUE)
2724
pcs <- c(triangles = 3, quads = 4, segments = 2, points = 1)
28-
nvert <- length(x)
25+
nvert <- ncol(verts)
2926
okay <- FALSE
3027
for (i in seq_along(type)) {
3128
if (nvert %% pcs[type[i]] == 0) {
@@ -36,8 +33,7 @@ as.mesh3d.default <- function(x, y = NULL, z = NULL,
3633
if (okay) type <- type[i]
3734
else stop("Wrong number of vertices")
3835

39-
verts <- rbind(x, y, z)
40-
indices <- matrix(seq_along(x), nrow = pcs[type])
36+
indices <- matrix(seq_len(nvert), nrow = pcs[type])
4137
if (merge) {
4238
if (!is.null(notEqual)) {
4339
dim <- dim(notEqual)
@@ -46,7 +42,7 @@ as.mesh3d.default <- function(x, y = NULL, z = NULL,
4642
notEqual <- notEqual | t(notEqual) # Make it symmetric
4743
} else
4844
notEqual <- matrix(FALSE, nvert, nvert)
49-
o <- order(x, y, z)
45+
o <- order(verts[1,], verts[2,], verts[3,])
5046
i1 <- seq_len(nvert)[o]
5147
for (i in seq_len(nvert)[-1]) {
5248
if (isTRUE(all.equal(verts[,i1[i-1]], verts[,i1[i]], tolerance = tolerance))

R/axes.R

+39-35
Original file line numberDiff line numberDiff line change
@@ -46,42 +46,43 @@ axis3d <- function(edge, at = NULL, labels = TRUE, tick = TRUE, line = 0,
4646
at <- pretty(range, nticks)
4747
at <- at[at >= range[1] & at <= range[2]]
4848
}
49-
50-
if (is.logical(labels)) {
51-
if (labels) labels <- format(at)
52-
else labels <- NA
53-
}
54-
55-
mpos <- matrix(NA,3,length(at))
56-
if (edge[1] == '+') mpos[1,] <- ranges$x[2]
57-
else mpos[1,] <- ranges$x[1]
58-
if (edge[2] == '+') mpos[2,] <- ranges$y[2]
59-
else mpos[2,] <- ranges$y[1]
60-
if (edge[3] == '+') mpos[3,] <- ranges$z[2]
61-
else mpos[3,] <- ranges$z[1]
62-
63-
ticksize <- 0.05*(mpos[,1]-c(mean(ranges$x),mean(ranges$y),mean(ranges$z)))
64-
ticksize[coord] <- 0
65-
66-
if (!is.null(pos)) mpos <- matrix(pos,3,length(at))
67-
mpos[coord,] <- at
68-
69-
x <- c(mpos[1,1],mpos[1,length(at)])
70-
y <- c(mpos[2,1],mpos[2,length(at)])
71-
z <- c(mpos[3,1],mpos[3,length(at)])
72-
if (tick) {
73-
x <- c(x,as.double(rbind(mpos[1,],mpos[1,]+ticksize[1])))
74-
y <- c(y,as.double(rbind(mpos[2,],mpos[2,]+ticksize[2])))
75-
z <- c(z,as.double(rbind(mpos[3,],mpos[3,]+ticksize[3])))
49+
if (length(at)) {
50+
if (is.logical(labels)) {
51+
if (labels) labels <- format(at)
52+
else labels <- NA
53+
}
54+
55+
mpos <- matrix(NA,3,length(at))
56+
if (edge[1] == '+') mpos[1,] <- ranges$x[2]
57+
else mpos[1,] <- ranges$x[1]
58+
if (edge[2] == '+') mpos[2,] <- ranges$y[2]
59+
else mpos[2,] <- ranges$y[1]
60+
if (edge[3] == '+') mpos[3,] <- ranges$z[2]
61+
else mpos[3,] <- ranges$z[1]
62+
63+
ticksize <- 0.05*(mpos[,1]-c(mean(ranges$x),mean(ranges$y),mean(ranges$z)))
64+
ticksize[coord] <- 0
65+
66+
if (!is.null(pos)) mpos <- matrix(pos,3,length(at))
67+
mpos[coord,] <- at
68+
69+
x <- c(mpos[1,1],mpos[1,length(at)])
70+
y <- c(mpos[2,1],mpos[2,length(at)])
71+
z <- c(mpos[3,1],mpos[3,length(at)])
72+
if (tick) {
73+
x <- c(x,as.double(rbind(mpos[1,],mpos[1,]+ticksize[1])))
74+
y <- c(y,as.double(rbind(mpos[2,],mpos[2,]+ticksize[2])))
75+
z <- c(z,as.double(rbind(mpos[3,],mpos[3,]+ticksize[3])))
76+
}
77+
result <- c(ticks=segments3d(x,y,z,...))
78+
79+
if (!all(is.na(labels)))
80+
result <- c(result, labels=text3d(mpos[1,]+3*ticksize[1],
81+
mpos[2,]+3*ticksize[2],
82+
mpos[3,]+3*ticksize[3],
83+
labels, ...))
84+
lowlevel(result)
7685
}
77-
result <- c(ticks=segments3d(x,y,z,...))
78-
79-
if (!all(is.na(labels)))
80-
result <- c(result, labels=text3d(mpos[1,]+3*ticksize[1],
81-
mpos[2,]+3*ticksize[2],
82-
mpos[3,]+3*ticksize[3],
83-
labels, ...))
84-
lowlevel(result)
8586
}
8687

8788
axes3d <- function(edges='bbox', labels=TRUE,
@@ -182,6 +183,9 @@ mtext3d <- function(text, edge, at = NULL, line = 0,
182183

183184
ranges <- .getRanges()
184185

186+
if (is.language(text))
187+
text <- as.expression(text)
188+
185189
newlen <- max(length(text),length(line),length(at))
186190
text <- rep(text, length.out = newlen)
187191
line <- rep(line, length.out = newlen)

R/buffer.R

+61-27
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,29 @@ Buffer <- R6Class("Buffer",
328328
private$accessors[[acc + 1]] <- unclass(accessor),
329329

330330
#' @description
331-
#' Read data given by accessor object.
331+
#' Read data given by accessor number.
332332
#'
333333
#' @param acc Accessor number.
334334
#'
335335
#' @return A vector or array as specified in the accessor. For the `MATn` types, the 3rd index
336336
#' indexes the element.
337337
#'
338-
readAccessor = function(acc) {
338+
readAccessor = function(acc) {
339+
if (acc + 1 > length(private$accessors))
340+
stop("No such accessor")
341+
accessor <- self$getAccessor(acc)
342+
self$readAccessor0(accessor)
343+
},
344+
345+
#' @description
346+
#' Read data given by accessor object.
347+
#'
348+
#' @param accessor Accessor object
349+
#'
350+
#' @return A vector or array as specified in the accessor. For the `MATn` types, the 3rd index
351+
#' indexes the element.
352+
#'
353+
readAccessor0 = function(accessor) {
339354
typenames <- c("5120" = "byte", "5121" = "unsigned_byte",
340355
"5122" = "short", "5123" = "unsigned_short",
341356
"5125" = "unsigned_int", "5126" = "float")
@@ -351,43 +366,62 @@ Buffer <- R6Class("Buffer",
351366
"5126" = TRUE)
352367
lens <- c(SCALAR = 1, VEC2 = 2, VEC3 = 3, VEC4 = 4,
353368
MAT2 = 4, MAT3 = 9, MAT4 = 16)
354-
if (acc + 1 > length(private$accessors))
355-
stop("No such accessor")
356-
accessor <- self$getAccessor(acc)
357-
view <- self$getBufferview(accessor$bufferView)
358-
con <- self$openBufferview(accessor$bufferView)
359369
ctype <- as.character(accessor$componentType)
360370
atype <- accessor$type
361371
type <- types[ctype]
362372
len <- lens[atype]
363373
size <- sizes[ctype]
364374
signed <- signeds[ctype]
365375
count <- accessor$count
366-
if (is.null(view$byteStride)) {
367-
skip <- 0
368-
} else
369-
skip <- len*size - view$byteStride
370-
if (is.null(byteOffset <- accessor$byteOffset))
371-
byteOffset <- 0
372-
start <- seek(con) + byteOffset
373-
374-
if (skip == 0) {
375-
seek(con, start)
376-
values <- readBin(con, type, n = len*count, size = size,
377-
signed = signed, endian = "little")
376+
if (is.null(accessor$bufferView)) {
377+
values <- numeric(count*len) # initialized to zero
378378
} else {
379-
values <- numeric(count*len)
380-
for (i in seq_len(count)) {
381-
seek(con, start + (i-1)*view$byteStride)
382-
values[(i-1)*len + seq_len(len)] <-
383-
readBin(con, type, n = len, size = size,
379+
view <- self$getBufferview(accessor$bufferView)
380+
con <- self$openBufferview(accessor$bufferView)
381+
if (is.null(view$byteStride)) {
382+
skip <- 0
383+
} else
384+
skip <- len*size - view$byteStride
385+
if (is.null(byteOffset <- accessor$byteOffset))
386+
byteOffset <- 0
387+
start <- seek(con) + byteOffset
388+
389+
if (skip == 0) {
390+
seek(con, start)
391+
values <- readBin(con, type, n = len*count, size = size,
392+
signed = signed, endian = "little")
393+
} else {
394+
values <- numeric(count*len)
395+
for (i in seq_len(count)) {
396+
seek(con, start + (i-1)*view$byteStride)
397+
values[(i-1)*len + seq_len(len)] <-
398+
readBin(con, type, n = len, size = size,
384399
signed = signed, endian = "little")
400+
}
401+
}
402+
if (ctype == "5125") { # fix up unsigned integers
403+
values[is.na(values)] <- 2^31
404+
values[values < 0] <- values[values < 0] + 2^32
385405
}
386406
}
387-
if (ctype == "5125") { # fix up unsigned integers
388-
values[is.na(values)] <- 2^31
389-
values[values < 0] <- values[values < 0] + 2^32
407+
if (!is.null(sparse <- accessor$sparse)) {
408+
indexobj <- sparse$indices
409+
indexobj$type <- "SCALAR"
410+
indexobj$count <- sparse$count
411+
index <- self$readAccessor0(indexobj)
412+
413+
valueobj <- sparse$values
414+
valueobj$type <- "SCALAR"
415+
valueobj$componentType <- accessor$componentType
416+
valueobj$count <- len*sparse$count
417+
newvalues <- self$readAccessor0(valueobj)
418+
419+
for (i in seq_len(sparse$count))
420+
for (j in seq_len(len))
421+
values[len*index[i] + j] <-
422+
newvalues[len*(i-1) + j]
390423
}
424+
391425
if (!is.null(accessor$normalized) && accessor$normalized)
392426
values <- switch(ctype,
393427
"5120" = (values + 128)/255 - 1, # byte

R/enum.R

+10
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,13 @@ rgl.enum(component, red=0, green=1, blue=2, alpha=3, depth=4, luminance=5)
6363
rgl.enum.depthtest <- function(depthtest)
6464
rgl.enum(depthtest, never=0, less=1, equal=2, lequal=3, greater=4,
6565
notequal=5, gequal=6, always= 7)
66+
67+
rgl.enum.blend <- function(blend)
68+
rgl.enum(blend, zero=0, one=1,
69+
src_color=2, one_minus_src_color=3,
70+
dst_color=4, one_minus_dst_color=5,
71+
src_alpha=6, one_minus_src_alpha=7,
72+
dst_alpha=8, one_minus_dst_alpha=9,
73+
constant_color=10, one_minus_constant_color=11,
74+
constant_alpha=12, one_minus_constant_alpha=13,
75+
src_alpha_saturate=14)

R/internal.R

+4-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ rgl.string <- function( x ) {
7171
# vertex data object
7272
#
7373

74-
rgl.vertex <- function(x,y=NULL,z=NULL) {
75-
xyz <- xyz.coords(x,y,z,recycle=TRUE)
74+
rgl.vertex <- function(x, y = NULL, z = NULL) {
75+
xyz <- xyz.coords(x, y, z, recycle=TRUE)
76+
# This is not the same as just rbind(xyz$x,xyz$y,xyz$z)!
77+
# xyz.coords puts all of named vector x into xyz$x
7678
return( matrix( rbind(xyz$x,xyz$y,xyz$z), nrow=3, dimnames=list( c("x","y","z"), NULL ) ) )
7779
}
7880

0 commit comments

Comments
 (0)