diff --git a/index.html b/index.html
index 084f28a9..48d28f02 100644
--- a/index.html
+++ b/index.html
@@ -5673,14 +5673,7 @@
-
+
+
+
+
+
+
+
+
+ Sun Color:
@@ -7913,7 +7920,7 @@
-
+
@@ -7949,14 +7956,14 @@
-
+
-
+
diff --git a/libs/LoopSubdivision.js b/libs/LoopSubdivision.js
index 6328bd70..c1c2c6d9 100644
--- a/libs/LoopSubdivision.js
+++ b/libs/LoopSubdivision.js
@@ -67,47 +67,46 @@
//
/////////////////////////////////////////////////////////////////////////////////////
+const loopSubdivision = {};
+(()=>{
+ ///// Constants
+ const POSITION_DECIMALS = 2;
-///// Constants
+ ///// Local Variables
-const POSITION_DECIMALS = 2;
+ const _average = new THREE.Vector3();
+ const _center = new THREE.Vector3();
+ const _midpoint = new THREE.Vector3();
+ const _normal = new THREE.Vector3();
+ const _temp = new THREE.Vector3();
-///// Local Variables
+ const _vector0 = new THREE.Vector3(); // .Vector4();
+ const _vector1 = new THREE.Vector3(); // .Vector4();
+ const _vector2 = new THREE.Vector3(); // .Vector4();
+ const _vec0to1 = new THREE.Vector3();
+ const _vec1to2 = new THREE.Vector3();
+ const _vec2to0 = new THREE.Vector3();
-const _average = new THREE.Vector3();
-const _center = new THREE.Vector3();
-const _midpoint = new THREE.Vector3();
-const _normal = new THREE.Vector3();
-const _temp = new THREE.Vector3();
+ const _position = [
+ new THREE.Vector3(),
+ new THREE.Vector3(),
+ new THREE.Vector3(),
+ ];
-const _vector0 = new THREE.Vector3(); // .Vector4();
-const _vector1 = new THREE.Vector3(); // .Vector4();
-const _vector2 = new THREE.Vector3(); // .Vector4();
-const _vec0to1 = new THREE.Vector3();
-const _vec1to2 = new THREE.Vector3();
-const _vec2to0 = new THREE.Vector3();
+ const _vertex = [
+ new THREE.Vector3(),
+ new THREE.Vector3(),
+ new THREE.Vector3(),
+ ];
-const _position = [
- new THREE.Vector3(),
- new THREE.Vector3(),
- new THREE.Vector3(),
-];
+ const _triangle = new THREE.Triangle();
-const _vertex = [
- new THREE.Vector3(),
- new THREE.Vector3(),
- new THREE.Vector3(),
-];
+ /////////////////////////////////////////////////////////////////////////////////////
+ ///// Loop Subdivision Surface
+ /////////////////////////////////////////////////////////////////////////////////////
-const _triangle = new THREE.Triangle();
-
-/////////////////////////////////////////////////////////////////////////////////////
-///// Loop Subdivision Surface
-/////////////////////////////////////////////////////////////////////////////////////
-
-/** Loop subdivision surface modifier for use with modern three.js BufferGeometry */
-class LoopSubdivision {
+ /** Loop subdivision surface modifier for use with modern three.js BufferGeometry */
/////////////////////////////////////////////////////////////////////////////////////
///// Modify
@@ -128,8 +127,8 @@ class LoopSubdivision {
* @param {Boolean} flatOnly - If true, subdivision generates triangles, but does not modify positions
* @param {Number} maxTriangles - If geometry contains more than this many triangles, subdivision will not continue
*/
- static modify(bufferGeometry, iterations = 1, params = {}) {
- if (arguments.length > 3) console.warn(`LoopSubdivision.modify() now uses a parameter object. See readme for more info!`);
+ function modify(bufferGeometry, iterations = 1, params = {}) {
+ if (arguments.length > 3) console.warn(`modify() now uses a parameter object. See readme for more info!`);
if (typeof params !== 'object') params = {};
@@ -141,12 +140,12 @@ class LoopSubdivision {
if (params.maxTriangles === undefined) params.maxTriangles = Infinity;
///// Geometries
- if (! verifyGeometry(bufferGeometry)) return bufferGeometry;
+ if (!verifyGeometry(bufferGeometry)) return bufferGeometry;
let modifiedGeometry = bufferGeometry.clone();
///// Presplit
if (params.split) {
- const splitGeometry = LoopSubdivision.edgeSplit(modifiedGeometry)
+ const splitGeometry = edgeSplit(modifiedGeometry)
modifiedGeometry.dispose();
modifiedGeometry = splitGeometry;
}
@@ -159,9 +158,9 @@ class LoopSubdivision {
// Subdivide
if (params.flatOnly) {
- subdividedGeometry = LoopSubdivision.flat(modifiedGeometry);
+ subdividedGeometry = flat(modifiedGeometry);
} else {
- subdividedGeometry = LoopSubdivision.smooth(modifiedGeometry, params);
+ subdividedGeometry = smooth(modifiedGeometry, params);
}
// Copy and Resize Groups
@@ -178,7 +177,8 @@ class LoopSubdivision {
///// Return New Geometry
return modifiedGeometry;
}
-
+ loopSubdivision.modify = modify;
+ console.log("Hello World");
/////////////////////////////////////////////////////////////////////////////////////
///// Split Hypotenuse
////////////////////
@@ -188,10 +188,10 @@ class LoopSubdivision {
* Starts by splitting at longest shared edge, followed by splitting from that new center edge point to the
* center of any other shared edges.
*/
- static edgeSplit(geometry) {
+ function edgeSplit(geometry) {
///// Geometries
- if (! verifyGeometry(geometry)) return geometry;
+ if (!verifyGeometry(geometry)) return geometry;
const existing = (geometry.index !== null) ? geometry.toNonIndexed() : geometry.clone();
const split = new THREE.BufferGeometry();
@@ -219,8 +219,8 @@ class LoopSubdivision {
// Verify Area
const triangleSize = _triangle.set(_vector0, _vector1, _vector2).getArea();
- triangleExist.push(! fuzzy(triangleSize, 0));
- if (! triangleExist[i / 3]) {
+ triangleExist.push(!fuzzy(triangleSize, 0));
+ if (!triangleExist[i / 3]) {
triangleEdgeHashes.push([]);
continue;
}
@@ -243,11 +243,11 @@ class LoopSubdivision {
const index = i / 3;
for (let j = 0; j < hashes.length; j++) {
// Attach Triangle Index to Edge Hash
- if (! edgeHashToTriangle[hashes[j]]) edgeHashToTriangle[hashes[j]] = [];
+ if (!edgeHashToTriangle[hashes[j]]) edgeHashToTriangle[hashes[j]] = [];
edgeHashToTriangle[hashes[j]].push(index);
// Edge Length
- if (! edgeLength[hashes[j]]) {
+ if (!edgeLength[hashes[j]]) {
if (j === 0 || j === 1) edgeLength[hashes[j]] = _vector0.distanceTo(_vector1);
if (j === 2 || j === 3) edgeLength[hashes[j]] = _vector1.distanceTo(_vector2);
if (j === 4 || j === 5) edgeLength[hashes[j]] = _vector2.distanceTo(_vector0);
@@ -255,13 +255,13 @@ class LoopSubdivision {
}
// Triangle Edge Reference
- triangleEdgeHashes.push([ hashes[0], hashes[2], hashes[4] ]);
+ triangleEdgeHashes.push([hashes[0], hashes[2], hashes[4]]);
}
///// Build Geometry, Set Attributes
attributeList.forEach((attributeName) => {
const attribute = existing.getAttribute(attributeName);
- if (! attribute) return;
+ if (!attribute) return;
const floatArray = splitAttribute(attribute, attributeName);
split.setAttribute(attributeName, new THREE.BufferAttribute(floatArray, attribute.itemSize));
});
@@ -292,7 +292,7 @@ class LoopSubdivision {
const arrayLength = (vertexCount * attribute.itemSize) * newTriangles;
const floatArray = new attribute.array.constructor(arrayLength);
- const processGroups = (attributeName === 'position' && ! morph && existing.groups.length > 0);
+ const processGroups = (attributeName === 'position' && !morph && existing.groups.length > 0);
let groupStart = undefined, groupMaterial = undefined;
let index = 0;
@@ -301,7 +301,7 @@ class LoopSubdivision {
for (let i = 0; i < vertexCount; i += 3) {
// Verify Triangle is Valid
- if (! triangleExist[i / 3]) {
+ if (!triangleExist[i / 3]) {
skipped += 3;
continue;
}
@@ -329,7 +329,7 @@ class LoopSubdivision {
if (sharedCount === 0) {
setTriangle(floatArray, index, step, _vector0, _vector1, _vector2); index += (step * 3);
- // Shared Edges
+ // Shared Edges
} else {
const length0to1 = edgeLength[edgeHash0to1];
const length1to2 = edgeLength[edgeHash1to2];
@@ -431,10 +431,10 @@ class LoopSubdivision {
////////////////////
/** Applies one iteration of Loop (flat) subdivision (1 triangle split into 4 triangles) */
- static flat(geometry) {
+ function flat(geometry) {
///// Geometries
- if (! verifyGeometry(geometry)) return geometry;
+ if (!verifyGeometry(geometry)) return geometry;
const existing = (geometry.index !== null) ? geometry.toNonIndexed() : geometry.clone();
const loop = new THREE.BufferGeometry();
@@ -445,9 +445,9 @@ class LoopSubdivision {
///// Build Geometry
attributeList.forEach((attributeName) => {
const attribute = existing.getAttribute(attributeName);
- if (! attribute) return;
+ if (!attribute) return;
- loop.setAttribute(attributeName, LoopSubdivision.flatAttribute(attribute, vertexCount));
+ loop.setAttribute(attributeName, flatAttribute(attribute, vertexCount));
});
///// Morph Attributes
@@ -457,9 +457,9 @@ class LoopSubdivision {
const morphAttribute = morphAttributes[attributeName];
// Process Array of Float32BufferAttributes
- for (let i = 0, l = morphAttribute.length; i < l; i++) {
+ for (let i = 0, l = morphAttribute.length; i < l; i++) {
if (morphAttribute[i].count !== vertexCount) continue;
- array.push(LoopSubdivision.flatAttribute(morphAttribute[i], vertexCount));
+ array.push(flatAttribute(morphAttribute[i], vertexCount));
}
loop.morphAttributes[attributeName] = array;
}
@@ -470,7 +470,7 @@ class LoopSubdivision {
return loop;
}
- static flatAttribute(attribute, vertexCount) {
+ function flatAttribute(attribute, vertexCount) {
const newTriangles = 4;
const arrayLength = (vertexCount * attribute.itemSize) * newTriangles;
const floatArray = new attribute.array.constructor(arrayLength);
@@ -504,7 +504,7 @@ class LoopSubdivision {
////////////////////
/** Applies one iteration of Loop (smooth) subdivision (1 triangle split into 4 triangles) */
- static smooth(geometry, params = {}) {
+ function smooth(geometry, params = {}) {
if (typeof params !== 'object') params = {};
@@ -513,34 +513,34 @@ class LoopSubdivision {
if (params.preserveEdges === undefined) params.preserveEdges = false;
///// Geometries
- if (! verifyGeometry(geometry)) return geometry;
+ if (!verifyGeometry(geometry)) return geometry;
const existing = (geometry.index !== null) ? geometry.toNonIndexed() : geometry.clone();
- const flat = LoopSubdivision.flat(existing);
+ const flatGeometry = flat(existing);
const loop = new THREE.BufferGeometry();
///// Attributes
const attributeList = gatherAttributes(existing);
const vertexCount = existing.attributes.position.count;
const posAttribute = existing.getAttribute('position');
- const flatPosition = flat.getAttribute('position');
+ const flatPosition = flatGeometry.getAttribute('position');
const hashToIndex = {}; // Position hash mapped to index values of same position
const existingNeighbors = {}; // Position hash mapped to existing vertex neighbors
const flatOpposites = {}; // Position hash mapped to new edge point opposites
const existingEdges = {};
function addNeighbor(posHash, neighborHash, index) {
- if (! existingNeighbors[posHash]) existingNeighbors[posHash] = {};
- if (! existingNeighbors[posHash][neighborHash]) existingNeighbors[posHash][neighborHash] = [];
+ if (!existingNeighbors[posHash]) existingNeighbors[posHash] = {};
+ if (!existingNeighbors[posHash][neighborHash]) existingNeighbors[posHash][neighborHash] = [];
existingNeighbors[posHash][neighborHash].push(index);
}
function addOpposite(posHash, index) {
- if (! flatOpposites[posHash]) flatOpposites[posHash] = [];
+ if (!flatOpposites[posHash]) flatOpposites[posHash] = [];
flatOpposites[posHash].push(index);
}
function addEdgePoint(posHash, edgeHash) {
- if (! existingEdges[posHash]) existingEdges[posHash] = new Set();
+ if (!existingEdges[posHash]) existingEdges[posHash] = new Set();
existingEdges[posHash].add(edgeHash);
}
@@ -579,16 +579,16 @@ class LoopSubdivision {
}
///// Flat Position to Index Map
- for (let i = 0; i < flat.attributes.position.count; i++) {
+ for (let i = 0; i < flatGeometry.attributes.position.count; i++) {
const posHash = hashFromVector(_temp.fromBufferAttribute(flatPosition, i));
- if (! hashToIndex[posHash]) hashToIndex[posHash] = [];
+ if (!hashToIndex[posHash]) hashToIndex[posHash] = [];
hashToIndex[posHash].push(i);
}
///// Build Geometry, Set Attributes
attributeList.forEach((attributeName) => {
const existingAttribute = existing.getAttribute(attributeName);
- const flatAttribute = flat.getAttribute(attributeName);
+ const flatAttribute = flatGeometry.getAttribute(attributeName);
if (existingAttribute === undefined || flatAttribute === undefined) return;
const floatArray = subdivideAttribute(attributeName, existingAttribute, flatAttribute);
@@ -605,7 +605,7 @@ class LoopSubdivision {
for (let i = 0, l = morphAttribute.length; i < l; i++) {
if (morphAttribute[i].count !== vertexCount) continue;
const existingAttribute = morphAttribute[i];
- const flatAttribute = LoopSubdivision.flatAttribute(morphAttribute[i], morphAttribute[i].count)
+ const flatAttribute = flatAttribute(morphAttribute[i], morphAttribute[i].count)
const floatArray = subdivideAttribute(attributeName, existingAttribute, flatAttribute);
array.push(new THREE.BufferAttribute(floatArray, flatAttribute.itemSize));
@@ -615,7 +615,7 @@ class LoopSubdivision {
loop.morphTargetsRelative = existing.morphTargetsRelative;
///// Clean Up
- flat.dispose();
+ flatGeometry.dispose();
existing.dispose();
return loop;
@@ -623,17 +623,17 @@ class LoopSubdivision {
// Loop Subdivide Function
function subdivideAttribute(attributeName, existingAttribute, flatAttribute) {
- const arrayLength = (flat.attributes.position.count * flatAttribute.itemSize);
+ const arrayLength = (flatGeometry.attributes.position.count * flatAttribute.itemSize);
const floatArray = new existingAttribute.array.constructor(arrayLength);
// Process Triangles
let index = 0;
- for (let i = 0; i < flat.attributes.position.count; i += 3) {
+ for (let i = 0; i < flatGeometry.attributes.position.count; i += 3) {
// Process Triangle Points
for (let v = 0; v < 3; v++) {
- if (attributeName === 'uv' && ! params.uvSmooth) {
+ if (attributeName === 'uv' && !params.uvSmooth) {
_vertex[v].fromBufferAttribute(flatAttribute, i + v);
@@ -676,14 +676,14 @@ class LoopSubdivision {
for (const edgeHash of edgeSet) {
if (flatOpposites[edgeHash].length % 2 !== 0) hasPair = false;
}
- if (! hasPair) continue;
+ if (!hasPair) continue;
}
// Number of Neighbors
const k = Object.keys(neighbors).length;
///// Loop's Formula
- const beta = 1 / k * ((5/8) - Math.pow((3/8) + (1/4) * Math.cos(2 * Math.PI / k), 2));
+ const beta = 1 / k * ((5 / 8) - Math.pow((3 / 8) + (1 / 4) * Math.cos(2 * Math.PI / k), 2));
///// Warren's Formula
// const beta = (k > 3) ? 3 / (8 * k) : ((k === 3) ? 3 / 16 : 0);
@@ -708,7 +708,7 @@ class LoopSubdivision {
_vertex[v].add(_average);
}
- ///// Newly Added Edge Vertex
+ ///// Newly Added Edge Vertex
} else if (opposites && opposites.length === 2) {
const k = opposites.length;
const beta = 0.125; /* 1/8 */
@@ -734,93 +734,95 @@ class LoopSubdivision {
}
-}
-/////////////////////////////////////////////////////////////////////////////////////
-///// Local Functions, Hash
-/////////////////////////////////////////////////////////////////////////////////////
-const _positionShift = Math.pow(10, POSITION_DECIMALS);
+ /////////////////////////////////////////////////////////////////////////////////////
+ ///// Local Functions, Hash
+ /////////////////////////////////////////////////////////////////////////////////////
-/** Compares two numbers to see if they're almost the same */
-function fuzzy(a, b, tolerance = 0.00001) {
- return ((a < (b + tolerance)) && (a > (b - tolerance)));
-}
+ const _positionShift = Math.pow(10, POSITION_DECIMALS);
-/** Generates hash strong from Number */
-function hashFromNumber(num, shift = _positionShift) {
- let roundedNumber = round(num * shift);
- if (roundedNumber == 0) roundedNumber = 0; /* prevent -0 (signed 0 can effect Math.atan2(), etc.) */
- return `${roundedNumber}`;
-}
-
-/** Generates hash strong from Vector3 */
-function hashFromVector(vector, shift = _positionShift) {
- return `${hashFromNumber(vector.x, shift)},${hashFromNumber(vector.y, shift)},${hashFromNumber(vector.z, shift)}`;
-}
-
-function round(x) {
- return (x + ((x > 0) ? 0.5 : -0.5)) << 0;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////
-///// Local Functions, Geometry
-/////////////////////////////////////////////////////////////////////////////////////
-
-function calcNormal(target, vec1, vec2, vec3) {
- _temp.subVectors(vec1, vec2);
- target.subVectors(vec2, vec3);
- target.cross(_temp).normalize();
-}
-
-function gatherAttributes(geometry) {
- const desired = [ 'position', 'normal', 'uv' ];
- const contains = Object.keys(geometry.attributes);
- const attributeList = Array.from(new Set(desired.concat(contains)));
- return attributeList;
-}
-
-function setTriangle(positions, index, step, vec0, vec1, vec2) {
- if (step >= 1) {
- positions[index + 0 + (step * 0)] = vec0.x;
- positions[index + 0 + (step * 1)] = vec1.x;
- positions[index + 0 + (step * 2)] = vec2.x;
- }
- if (step >= 2) {
- positions[index + 1 + (step * 0)] = vec0.y;
- positions[index + 1 + (step * 1)] = vec1.y;
- positions[index + 1 + (step * 2)] = vec2.y;
- }
- if (step >= 3) {
- positions[index + 2 + (step * 0)] = vec0.z;
- positions[index + 2 + (step * 1)] = vec1.z;
- positions[index + 2 + (step * 2)] = vec2.z;
- }
- if (step >= 4) {
- positions[index + 3 + (step * 0)] = vec0.w;
- positions[index + 3 + (step * 1)] = vec1.w;
- positions[index + 3 + (step * 2)] = vec2.w;
- }
-}
-
-function verifyGeometry(geometry) {
- if (geometry === undefined) {
- console.warn(`LoopSubdivision: Geometry provided is undefined`);
- return false;
+ /** Compares two numbers to see if they're almost the same */
+ function fuzzy(a, b, tolerance = 0.00001) {
+ return ((a < (b + tolerance)) && (a > (b - tolerance)));
}
- if (! geometry.isBufferGeometry) {
- console.warn(`LoopSubdivision: Geometry provided is not 'BufferGeometry' type`);
- return false;
+ /** Generates hash strong from Number */
+ function hashFromNumber(num, shift = _positionShift) {
+ let roundedNumber = round(num * shift);
+ if (roundedNumber == 0) roundedNumber = 0; /* prevent -0 (signed 0 can effect Math.atan2(), etc.) */
+ return `${roundedNumber}`;
}
- if (geometry.attributes.position === undefined) {
- console.warn(`LoopSubdivision: Geometry provided missing required 'position' attribute`);
- return false;
+ /** Generates hash strong from Vector3 */
+ function hashFromVector(vector, shift = _positionShift) {
+ return `${hashFromNumber(vector.x, shift)},${hashFromNumber(vector.y, shift)},${hashFromNumber(vector.z, shift)}`;
}
- if (geometry.attributes.normal === undefined) {
- geometry.computeVertexNormals();
+ function round(x) {
+ return (x + ((x > 0) ? 0.5 : -0.5)) << 0;
}
- return true;
-}
+
+ /////////////////////////////////////////////////////////////////////////////////////
+ ///// Local Functions, Geometry
+ /////////////////////////////////////////////////////////////////////////////////////
+
+ function calcNormal(target, vec1, vec2, vec3) {
+ _temp.subVectors(vec1, vec2);
+ target.subVectors(vec2, vec3);
+ target.cross(_temp).normalize();
+ }
+
+ function gatherAttributes(geometry) {
+ const desired = ['position', 'normal', 'uv'];
+ const contains = Object.keys(geometry.attributes);
+ const attributeList = Array.from(new Set(desired.concat(contains)));
+ return attributeList;
+ }
+
+ function setTriangle(positions, index, step, vec0, vec1, vec2) {
+ if (step >= 1) {
+ positions[index + 0 + (step * 0)] = vec0.x;
+ positions[index + 0 + (step * 1)] = vec1.x;
+ positions[index + 0 + (step * 2)] = vec2.x;
+ }
+ if (step >= 2) {
+ positions[index + 1 + (step * 0)] = vec0.y;
+ positions[index + 1 + (step * 1)] = vec1.y;
+ positions[index + 1 + (step * 2)] = vec2.y;
+ }
+ if (step >= 3) {
+ positions[index + 2 + (step * 0)] = vec0.z;
+ positions[index + 2 + (step * 1)] = vec1.z;
+ positions[index + 2 + (step * 2)] = vec2.z;
+ }
+ if (step >= 4) {
+ positions[index + 3 + (step * 0)] = vec0.w;
+ positions[index + 3 + (step * 1)] = vec1.w;
+ positions[index + 3 + (step * 2)] = vec2.w;
+ }
+ }
+
+ function verifyGeometry(geometry) {
+ if (geometry === undefined) {
+ console.warn(`LoopSubdivision: Geometry provided is undefined`);
+ return false;
+ }
+
+ if (!geometry.isBufferGeometry) {
+ console.warn(`LoopSubdivision: Geometry provided is not 'BufferGeometry' type`);
+ return false;
+ }
+
+ if (geometry.attributes.position === undefined) {
+ console.warn(`LoopSubdivision: Geometry provided missing required 'position' attribute`);
+ return false;
+ }
+
+ if (geometry.attributes.normal === undefined) {
+ geometry.computeVertexNormals();
+ }
+ return true;
+ }
+
+})()
diff --git a/modules/ui/3d.js b/modules/ui/3d.js
index 7131fb9e..c8621a2d 100644
--- a/modules/ui/3d.js
+++ b/modules/ui/3d.js
@@ -5,7 +5,7 @@ window.ThreeD = (function () {
scale: 50,
lightness: 0.7,
shadow: 0.5,
- sun: {x: 300, y: 1500, z: 800},
+ sun: {x: 100, y: 600, z: 1000},
rotateMesh: 0,
rotateGlobe: 0.5,
skyColor: "#9ecef5",
@@ -15,7 +15,8 @@ window.ThreeD = (function () {
wireframe: 0,
resolution: 2,
resolutionScale: 3,
- sunColor: "#ffffff"
+ sunColor: "#cccccc",
+ subdivide: 0
};
// set variables
@@ -95,7 +96,11 @@ window.ThreeD = (function () {
const setScale = function (scale) {
options.scale = scale;
- geometry.vertices.forEach((v, i) => (v.z = getMeshHeight(i)));
+ let vertices = geometry.getAttribute('position');
+ for(let i = 0; i < vertices.count; i++){
+ vertices.setZ(i,getMeshHeight(i));
+ }
+ geometry.setAttribute('position',vertices);
geometry.verticesNeedUpdate = true;
geometry.computeVertexNormals();
geometry.verticesNeedUpdate = false;
@@ -163,6 +168,12 @@ window.ThreeD = (function () {
}
};
+ const toggle3dSubdivision = function(){
+ console.log("toggle 3d subdivision");
+ options.subdivide = !options.subdivide;
+ redraw();
+ }
+
const toggleWireframe = function () {
options.wireframe = !options.wireframe;
redraw();
@@ -222,7 +233,7 @@ window.ThreeD = (function () {
Renderer = new THREE.WebGLRenderer({canvas, antialias: true, preserveDrawingBuffer: true});
Renderer.setSize(canvas.width, canvas.height);
Renderer.shadowMap.enabled = true;
- Renderer.shadowMap.type = THREE.PCFSoftShadowMap;
+ // Renderer.shadowMap.type = THREE.PCFSoftShadowMap;
if (options.extendedWater) extendWater(graphWidth, graphHeight);
createMesh(graphWidth, graphHeight, grid.cellsX, grid.cellsY);
@@ -480,9 +491,8 @@ window.ThreeD = (function () {
material = new THREE.MeshLambertMaterial();
material.wireframe = true;
}else{
- material = new THREE.MeshStandardMaterial();
+ material = new THREE.MeshLambertMaterial();
material.map = texture;
- material.roughness = 0.9;
material.transparent = true;
}
@@ -493,14 +503,24 @@ window.ThreeD = (function () {
for(let i = 0; i < vertices.count; i++){
vertices.setZ(i,getMeshHeight(i));
}
- // vertices.forEach((v, i) => (v.z = getMeshHeight(i)));
geometry.setAttribute('position',vertices);
geometry.computeVertexNormals();
//This takes too long
- const smoothGeometry = LoopSubdivision.modify(geometry,1,undefined);
if (mesh) scene.remove(mesh);
- mesh = new THREE.Mesh(smoothGeometry, material);
+ if(options.subdivide){
+ const subdivideParams = {
+ split: true,
+ uvSmooth: false,
+ preserveEdges: true,
+ flatOnly: false,
+ maxTriangles: Infinity
+ };
+ const smoothGeometry = loopSubdivision.modify(geometry,1,subdivideParams);
+ mesh = new THREE.Mesh(smoothGeometry, material);
+ }else{
+ mesh = new THREE.Mesh(geometry, material);
+ }
mesh.rotation.x = -Math.PI / 2;
mesh.castShadow = true;
mesh.receiveShadow = true;
@@ -704,6 +724,7 @@ window.ThreeD = (function () {
setSun,
setRotation,
toggleLabels,
+ toggle3dSubdivision,
toggleWireframe,
toggleSky,
setResolution,
diff --git a/modules/ui/options.js b/modules/ui/options.js
index 8139210b..ad41c234 100644
--- a/modules/ui/options.js
+++ b/modules/ui/options.js
@@ -1070,8 +1070,9 @@ function toggle3dOptions() {
document.getElementById("options3dMeshSky").addEventListener("input", changeColors);
document.getElementById("options3dMeshWater").addEventListener("input", changeColors);
document.getElementById("options3dGlobeResolution").addEventListener("change", changeResolution);
- document.getElementById("options3dMeshWireframeMode").addEventListener("change",toggleWireframe3d);
+ // document.getElementById("options3dMeshWireframeMode").addEventListener("change",toggleWireframe3d);
document.getElementById("options3dSunColor").addEventListener("input", changeSunColor);
+ document.getElementById("options3dSubdivide").addEventListener("change",toggle3dSubdivision);
function updateValues() {
@@ -1094,6 +1095,7 @@ function toggle3dOptions() {
options3dMeshWater.value = ThreeD.options.waterColor;
options3dGlobeResolution.value = ThreeD.options.resolution;
options3dSunColor.value = ThreeD.options.sunColor;
+ options3dSubdivide.value = ThreeD.options.subdivide;
console.log("options3dSunColor.value =",ThreeD.options.sunColor);
}
@@ -1134,10 +1136,15 @@ function toggle3dOptions() {
ThreeD.toggleLabels();
}
- function toggleWireframe3d() {
- ThreeD.toggleWireframe();
+ function toggle3dSubdivision(){
+ console.log(options.subdivide);
+ ThreeD.toggle3dSubdivision();
}
+ // function toggleWireframe3d() {
+ // ThreeD.toggleWireframe();
+ // }
+
function toggleSkyMode() {
const hide = ThreeD.options.extendedWater;
options3dColorSection.style.display = hide ? "none" : "block";
diff --git a/versioning.js b/versioning.js
index 44b03b2a..523dea9e 100644
--- a/versioning.js
+++ b/versioning.js
@@ -1,7 +1,7 @@
"use strict";
// version and caching control
-const version = "1.89.34"; // generator version, update each time
+const version = "1.89.35"; // generator version, update each time
{
document.title += " v" + version;