Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to represent geometry with values read from JSON file in Three.js?
    text
    copied!<p>I've large group of five vertices in JSON which needs to represented as cone geometry shown below.</p> <p>Five vertices: {(x,y,z) , (a,b,c), (d,e,f), (g,h,i), (j,k,l) }, {(x1,y1,z1) , (a1,b1,c1), (d1,e1,f1), (g1,h1,i1), (j1,k1,l1) }.............. </p> <p><strong>NOTE: These cordinates are canvas cordinates.</strong></p> <p>Here is the diagram:</p> <p><img src="https://i.stack.imgur.com/zCfgF.png" alt="Cone"></p> <p>where these vertex values are read from JSON file and needed to make a geometry. These vertex values are unique to every single geometry. </p> <p>AFAIK, how to use three.js pre-defined geometry and custom geometry like below code. My question is how to represent the geometry using the values read from JSON file?</p> <pre><code> var cone; var geo = new THREE.Geometry(); var meshMaterial = new new THREE.MeshLambertMaterial( { color: 0xffffff }); geo.vertices.push( new THREE.Vector3( 0, 0, 0)); geo.vertices.push( new THREE.Vector3( -0.5, 0.5, 1)); geo.vertices.push( new THREE.Vector3( 0.5, 0.5, 1)); geo.vertices.push( new THREE.Vector3( -0.5, -0.5, 1)); geo.vertices.push(new THREE.Vector3( 0.5,-0.5, 1)); geo.faces.push( new THREE.Face3(0,1,2)); geo.faces.push( new THREE.Face3(4,3,0)); geo.faces.push( new THREE.Face3(3,1,0)); geo.faces.push( new THREE.Face3(0,2,4)); geo.faces.push( new THREE.Face3(2,1,4)); geo.faces.push( new THREE.Face3(1,3,4)); geo.computeFaceNormals(); cone = new THREE.Mesh(geo, meshMaterial); cone.doubleSided = true; cone.overdraw = true; //And finally we need (x,y,z) to set the position of this geometry to display on the canvas cone.position.set(x,y,z); </code></pre> <p>I've tried a lot, how to create geometry using values read from other files , But I didn't find anything, which initated me to post this question.</p> <p>P.S: Among these values {(x,y,z) , (a,b,c), (d,e,f), (g,h,i), (j,k,l) }, (x,y.z) should be position of the tip of the cone on the canvas while representing the cone. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload