kovacsv / occt-import-js

The emscripten interface for OpenCascade import functionalities.
GNU Lesser General Public License v2.1
141 stars 23 forks source link

Positioning of meshes is off #1

Closed GitHubDragonFly closed 2 years ago

GitHubDragonFly commented 2 years ago

Hi Viktor.

Just looking for some advice or suggestion related to using this library.

I managed to create a STEP viewer but when adding group of meshes then positioning is off and some meshes don't seem to be added as it is in your example when viewing it in Online 3D Viewer.

This is the short version of the code:

occtimportjs().then ( async function( occt ) {
            response = await fetch( URL.createObjectURL( selected_step_file ) );
            URL.revokeObjectURL( selected_step_file );
            buffer = await response.arrayBuffer ();
            fileBuffer = new Uint8Array( buffer );
            result = await occt.ReadStepFile( fileBuffer );

            if (result.success) {
              let mesh_count = 1;

              result.meshes.forEach( msh => {
                let geometry = new THREE.BufferGeometry();

                indices = Uint16Array.from( msh.index.array );
                geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
                geometry.setDrawRange( 0, indices.length );
                vertices = Float32Array.from( msh.attributes.position.array );
                geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
                normals = Float32Array.from( msh.attributes.normal.array );
                geometry.setAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
                geometry.normalizeNormals();
                geometry.center();

                let new_mesh = new THREE.Mesh( geometry, material );
                new_mesh.name = 'mesh_' + mesh_count;
                edges[ new_mesh.name ] = new THREE.LineSegments( new THREE.EdgesGeometry( new_mesh.geometry, 30 ), new THREE.LineBasicMaterial( { color: 0xA52A2A } ) );
                mesh_count += 1;

                mesh.add( new_mesh );

                geometry.dispose();
                new_mesh.geometry.dispose();
                new_mesh.material.dispose();
              });

              await addFileInScene();
            }
          });
kovacsv commented 2 years ago

This line looks strange, why do you need it?

geometry.center();
GitHubDragonFly commented 2 years ago

Cool, you found what was causing this issue right away (I don't really need that line).

Thank you.

kovacsv commented 2 years ago

You're welcome! 🙂