Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

work with obj or stl loaded geometry #25

Open
tarasprystavskyj opened this issue Mar 2, 2016 · 9 comments
Open

work with obj or stl loaded geometry #25

tarasprystavskyj opened this issue Mar 2, 2016 · 9 comments

Comments

@tarasprystavskyj
Copy link

whant to use that lib with obj or stl or other files loaded through three.js.

now lib shows me error "the geometry is not supported"

How can I do it with this lib?

@tarasprystavskyj
Copy link
Author

here is script I whant to make working
http://188.226.157.20/3d/canvas_page_for_obj_model.html
there you can see obj file type

Here is code I need to get working.
` var loader = new THREE.OBJMTLLoader();
loader.load( 'obj/shell_nte3.obj', 'obj/shell_nte3.mtl', function ( object ) {
object.children.forEach (function(child) {
});
var objectBSP = new ThreeBSP( object );
var materialNormal = new THREE.MeshNormalMaterial();

var sphereGeometry = new THREE.SphereGeometry( 60, 32, 32 );
var sphereMesh = new THREE.Mesh( sphereGeometry );
var sphereBSP = new ThreeBSP( sphereMesh );

var newBSP = sphereBSP.intersect( objectBSP ); //objectBSP //cubeBSP
var newMesh = newBSP.toMesh( materialNormal );
newMesh.position.set(-70, 60, -120);
scene.add( newMesh );

            } );`

@tarasprystavskyj
Copy link
Author

solved this isue. Can now provide fix to your lib.

object.traverse( function ( child ) {

                        if ( child.geometry !== undefined ) {
                            console.log( "found object.geometry" );
                            geometry = child.geometry;


                        }

                    } );

and then we can make ThreeBSP object of it
objectBSP = new ThreeBSP( geometry );

And whole code will look like this

var loader = new THREE.OBJMTLLoader();
                    loader.load( 'obj/'+filename+'.obj', 'obj/'+filename+'.mtl', function ( object ) {
                    var geometry;
                    var objectBSP;

                    object.traverse( function ( child ) {

                        if ( child.geometry !== undefined ) {
                            console.log( "found object.geometry" );
                            geometry = child.geometry;

                        }

                    } );

                    /*object.children.forEach (function(child) {
                        child.material.specular.setHex (0x595959);
                        child.material.color.setHex (0x959595);
                        child.material.ambient.setHex (0x959595);
                    });*/
                    //object.position.y = 0;
//                  object.position.x = 0;
//                  object.position.z = 0;
                    objects.push( mesh );

    function add_intersect(geometry)
    {
    objectBSP = new ThreeBSP( geometry );                
    var materialNormal = new THREE.MeshNormalMaterial();


    var sphereGeometry = new THREE.SphereGeometry( 15, 15, 15 );
    var sphereMesh = new THREE.Mesh( sphereGeometry );
    var sphereBSP = new ThreeBSP( sphereMesh );

    // Example #4 - Cube intersect Sphere
    //var newBSP = sphereBSP.intersect( objectBSP ); //objectBSP //cubeBSP
    var newMesh = newBSP.toMesh( materialNormal );
    newMesh.position.set(-70, 60, -120);


    //scene.add( sphereMesh  );
    //scene.add( object );
scene.add( newMesh );

    }   

    add_intersect(geometry);

@scotmos
Copy link

scotmos commented Mar 25, 2016

Does this also work with JSON FIles using THREE.ObjectLoader();?

@tarasprystavskyj
Copy link
Author

I suppose yes. Don't remember the details of case now. But as I understand three.js stores all loaded models in object with same semantics.

Besides now I can also say that these lib (threeBSP) is not the slowest way to intersect small file even for production. Compared results with compiled app - openscad.

@msahli2
Copy link

msahli2 commented Apr 5, 2018

Hi
it seems that ThreeCSG does not work with complex geometry loaded with neither ObjectLoader nor PlyLoader !
may I ask you what kind of OBJMTL are loading , and if you have some demo about , because the link above seems to be dead
Thanks

@liangchaob
Copy link

Does it support stl file?

@msahli2
Copy link

msahli2 commented Jan 12, 2021

Hi
This Works
var loader = new THREE.OBJLoader();
loader.load('https://anyfile.obj', function(obj) {
obj.traverse( function (child) { if (child instanceof THREE.Mesh) geometry = child.geometry; child.material = Shipmaterial; });

//Geo1 for  CGS  boolean Manipulation   we bave to Convert from BufferGeometry to geometry to allow boolean operations
	var geo = new THREE.Geometry().fromBufferGeometry( geometry );
	Geo1 = new THREE.Mesh( geo,  material1   );		
	Geo1 .rotation.x = -Math.PI/2 ; Geo1 .position.set(-x,0,0);  Geo1.renderOrder = 5;
            Geo1.updateMatrixWorld(true);

           //--------------boolean operations here--------------------
    }

@liangchaob
Copy link

Hi
This Works
var loader = new THREE.OBJLoader();
loader.load('https://anyfile.obj', function(obj) {
obj.traverse( function (child) { if (child instanceof THREE.Mesh) geometry = child.geometry; child.material = Shipmaterial; });

//Geo1 for  CGS  boolean Manipulation   we bave to Convert from BufferGeometry to geometry to allow boolean operations
	var geo = new THREE.Geometry().fromBufferGeometry( geometry );
	Geo1 = new THREE.Mesh( geo,  material1   );		
	Geo1 .rotation.x = -Math.PI/2 ; Geo1 .position.set(-x,0,0);  Geo1.renderOrder = 5;
            Geo1.updateMatrixWorld(true);

           //--------------boolean operations here--------------------
    }

Thanks, it Works for the simple geometry!
But my Chrome stuck when obj faces too much, how to solve

@msahli2
Copy link

msahli2 commented Jan 27, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants