function* create_globe() {
let this_width = width < 600 ? width : 600;
let height = this_width;
let container = d3
.create("div")
.style("width", this_width.toString() + "px")
.style("height", height.toString() + "px");
let scene = container
.append("x3d")
.attr("width", this_width.toString() + "px")
.attr("height", height.toString() + "px")
.append("scene");
let r = (2 * Math.PI) / 3;
r = r.toString();
let d = 1 / Math.sqrt(3);
d = d.toString();
let ddd = d + " " + d + " " + d;
scene
.append("viewpoint")
.attr("position", "4 0 0")
.attr("orientation", ddd + " " + r);
scene
.append("directionalLight")
.attr("direction", "-0.5 1 0")
.attr("on", "TRUE")
.attr("intensity", "0.75");
let tilt = scene
.append("transform")
.attr("id", "tilt")
.attr("rotation", "1 0 0 0.2");
let rotation = tilt.append("transform").attr("id", "rotation");
let sphere_shape = rotation.append("shape");
sphere_shape
.append("appearance")
.append("material")
.attr("diffuseColor", "0.63 0.73 0.85")
.attr("shininess", "0.1");
sphere_shape
.append("sphere")
.attr("subdivision", "256,256")
.attr("radius", "0.999");
for (let cnt = 0; cnt < land.pts.length; cnt++) {
let pt_string = "";
let color_string = "";
land.pts[cnt].forEach(function (lnglat) {
let lnglat_sphere_string = lnglat_to_globe(lnglat, { r: 1.6 });
pt_string = pt_string + lnglat_sphere_string + ", ";
color_string = color_string + shade(lnglat[2] / M) + ", ";
});
let index_string = "";
land.triangles[cnt].forEach(function (ijk) {
let i = ijk[0];
let j = ijk[1];
let k = ijk[2];
index_string = index_string + `${i} ${j} ${k} -1 `;
});
let land_shape = rotation.append("shape");
let indexedFaceSet = land_shape
.append("indexedFaceset")
.attr("coordIndex", index_string)
.attr("creaseAngle", "0");
indexedFaceSet.append("coordinate").attr("point", pt_string);
indexedFaceSet.append("Color").attr("color", color_string);
let mesh = rotation.append("shape").attr("class", "mesh");
mesh.append("appearance").append("material").attr("transparency", 1);
mesh
.append("IndexedLineSet")
.attr("coordIndex", index_string)
.append("Coordinate")
.attr("point", pt_string);
}
let pt_string = "";
let index_string = "";
d = Math.PI / 12;
let dd = Math.PI / 144;
let cnt = 0;
for (let lng = -Math.PI; lng <= Math.PI; lng = lng + d) {
for (let lat = -Math.PI / 2; lat <= Math.PI / 2; lat = lat + dd) {
pt_string = pt_string + lnglat_to_globe([lng, lat]) + ", ";
index_string = `${index_string} ${cnt++}`;
}
index_string = index_string + " -1";
}
for (let lat = -Math.PI / 2; lat <= Math.PI / 2; lat = lat + d) {
for (let lng = -Math.PI; lng <= Math.PI; lng = lng + dd) {
pt_string = pt_string + lnglat_to_globe([lng, lat]) + ", ";
index_string = `${index_string} ${cnt++}`;
}
index_string = index_string + " -1";
}
let graticule = rotation.append("shape").attr("class", "graticule");
graticule.append("appearance").append("material").attr("transparency", 0);
graticule
.append("IndexedLineSet")
.attr("coordIndex", index_string)
.append("Coordinate")
.attr("point", pt_string);
yield container.node();
x3dom.reload();
}