mercredi 4 décembre 2019

Rendering Complicated Models in Three.js

if some rockstar could look through my code real quick and tell me why I cant render/see my three.js model I'd be forever in your debt! I'll post the whole script, but I think some preliminary info is important. Basically, I have thousands of points that look like this:

472232.14363148 2943288.56768013 200.129142"
472237.03086105 2943289.62356560 200.119496"
472241.91809061 2943290.67945108 200.109851"
472246.80532018 2943291.73533656 200.100205"
...and so on...

and a bunch of faces that look like this:

["1021 1020 1061", "640 754 641", "1534 1633 1535", "4701 27 26", "654 753 655", ...and so on...

When I extracted all the data and configured it correctly I then push it to the geometry and try to add it to the scene but with no success. Here's the whole script:

var renderer = new THREE.WebGLRenderer();
  renderer.setSize( window.innerWidth, window.innerHeight );
  document.body.appendChild( renderer.domElement );

    var camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 1000 );
    camera.position.set( 0, 50, 50 );
    camera.lookAt( 0, 0, 0 );

    var scene = new THREE.Scene();

    var material = new THREE.MeshStandardMaterial( { color : 0x00cc00 } );

    var geometry = new THREE.Geometry();

    var points = bigData['LandXML']['Surfaces']['Surface']['Definition']['Pnts']['P']
    var faces = bigData['LandXML']['Surfaces']['Surface']['Definition']['Faces']['F']

  for(i=0;i<points.length;i++){
        var [point1,point2,point3] = points[i]['__text'].split(' ').map(Number)
        //point1 *= .00001
        //point2 *= .00001
        //point3 *= .00001
        geometry.vertices.push(new THREE.Vector3(point1,point2,point3))
    }

  for(i=0;i<faces.length;i++){
    console.log(faces[i]);
    var [face1,face2,face3] = faces[i].split(' ').map(Number)
    var face = new THREE.Face3(face1 - 1,face2 - 1, face3 - 1)
    geometry.faces.push(face)
  }

  scene.add( new THREE.Mesh( geometry, material ) );

You can see that in the for loop for the points, I have multiplied them by .00001 to scale the model because otherwise the numbers are so huge, if that makes sense. And I subtract 1 from each face because the data was not zero indexed. Anyways, if any coding superhero took the time to read this and has some insight, please help me out! Thanks!




Aucun commentaire:

Enregistrer un commentaire