Open tarasprystavskyj opened 8 years ago
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 );
} );`
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);
Does this also work with JSON FIles using THREE.ObjectLoader();?
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.
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
Does it support stl file?
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--------------------
}
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
This may work (I hope so)
Le mer. 27 janv. 2021 à 01:58, liangchao notifications@github.com a écrit :
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
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/chandlerprall/ThreeCSG/issues/25#issuecomment-767933523, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACW6XDNLQOITPN6ZVG2GPXDS35QKTANCNFSM4B46L7OA .
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?