Skip to content

Commit

Permalink
Texture on sphere now working. Fixes #360.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmurdoch committed Apr 19, 2023
1 parent 29c70cc commit d114704
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 1,5 @@
Package: rgl
Version: 1.1.12
Version: 1.1.13
Title: 3D Visualization Using OpenGL
Authors@R: c(person("Duncan", "Murdoch", role = c("aut", "cre"),
email = "[email protected]"),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 29,7 @@ warnings in recent R versions.
* `getShaders()` was broken in 1.1.3.
* `arc3d()` can now handle "arcs" that are straight lines along
a radius (issue #357).
* Spheres did not show textures correctly (issue #360).


# rgl 1.1.3
Expand Down
39 changes: 16 additions & 23 deletions inst/htmlwidgets/lib/rglClass/init.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,46 61,39 @@
*/
rglwidgetClass.prototype.initSphere = function(sections, segments) {
var v = [], phi = [], theta = [], it = [], centers = [],
i, j, k, ind, mod1, pole, result = {};
i, j, k, ind, result = {};

for (i = 0; i < sections - 1; i ) {
phi.push((i 1)/sections - 0.5);
for (i = 0; i <= sections; i ) {
phi.push(i/sections - 0.5);
}

for (j = 0; j < segments; j ) {
for (j = 0; j <= segments; j ) {
theta.push(2*j/segments);
for (i = 0; i < sections - 1; i ) {
for (i = 0; i <= sections; i ) {
/* These are [x,y,z,s,t]: */
v.push([Math.sin(Math.PI*theta[j]) * Math.cos(Math.PI*phi[i]),
Math.sin(Math.PI*phi[i]),
Math.cos(Math.PI*theta[j]) * Math.cos(Math.PI*phi[i]),
theta[j]/2,
phi[i] 0.5]);
// console.log("xyzst=" v[v.length-1]);
}
}
pole = v.length;
v.push([0, -1, 0, 0, 0]);
v.push([0, 1, 0, 0, 1]);
result.values = new Float32Array(rglwidgetClass.flatten(v));
result.vertexCount = v.length;

mod1 = segments*(sections - 1);
for (j = 0; j < segments; j ) {
for (i = 0; i < sections - 2; i ) {
ind = i (sections - 1)*j;
it.push([ind % mod1,
(ind sections - 1) % mod1,
(ind sections) % mod1]);
it.push([ind % mod1,
(ind sections) % mod1,
(ind 1) % mod1]);
for (i = 0; i < sections; i ) {
ind = i (sections 1)*j;
if (i > 0) // Not south pole
it.push([ind,
ind sections 1,
ind 1]);
if (i < sections - 1) // Not north pole
it.push([ind sections 1,
ind sections 2,
ind 1]);
}
it.push([pole,
((j 1)*(sections - 1)) % mod1,
((j 1)*(sections - 1) - sections 1) % mod1]);
it.push([pole 1,
((j 1)*(sections - 1) - 1) % mod1,
((j 1)*(sections - 1) sections - 2) % mod1]);
}
result.it = new Uint16Array(rglwidgetClass.flatten(it));

Expand Down

0 comments on commit d114704

Please sign in to comment.