1

In html, I use JSONLoader to load my obj(.js file exporting from Blender 2.66). After loading my obj, I use ThreeCSG to subtract a cube. The effect I want to achieve is like cross-section. Now csg operations work fine. The problem is that I can't remain the original color after csg operations.

For example, after A subtract B, I hope that the mesh remain the materials of A, somewhat similar to the image(a.subtract(b)) csg.js website shows. The difference is I hope it all red (A's materials). However, it may be more complicated because my obj has several colors and more complex geometry.

Here is a part of my code.

loader.load( "obj/blenderscene/FinFET2.4.js", createScene1 );

function createScene1( geometry, materials ) {

  mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) );

  var mesh_bsp = new ThreeBSP(mesh);
  var cube_geometry = new THREE.CubeGeometry( 2.5,7 , 7 );
  cube_geometry = new THREE.Mesh( cube_geometry ,new THREE.MeshLambertMaterial( { color: 0xff11ff, opacity: 0.9, shading: THREE.FlatShading, wireframe: true, wireframeLinewidth: 2, transparent: true } ) );

  var cube_bsp = new ThreeBSP( cube_geometry );
  var subtract_bsp = mesh_bsp.subtract( cube_bsp );

  var result = subtract_bsp.toMesh( new THREE.MeshFaceMaterial(materials) );
  result.geometry.computeVertexNormals();
  scene.add( result );
 }

The version of three.js is R55.

Sorry for my poor English.I really need some help.Hope you can understand what I mean.

Thank you all.

1 Answers1

2

set the material indexes correctly.

How to:

Add the cube material to the materials

loop over result.geometry.faces as searchFace

search for a face with same vertices as searchFace in geometry.faces

if found then add the materialindex of the face to searchFace

if not found, search for a face with 2 of the same vertices as searchFace in geometry.faces

if found then add the materialindex of the face to searchFace

if not found, search for a face with 1 of the same vertices as searchFace in geometry.faces

if found then add the materialindex of the face to searchFace

if not found add the material index of the cube material

Gero3
  • 2,817
  • 1
  • 22
  • 21
  • Thanks for your suggestion. It works very well in most situations. However, those faces in cross-section cannot display original color. For example, [the face in red](http://ppt.cc/70Ey) has no vertices in common with the faces of cubes. Are there other ways to solve this problem ? The idea that comes into my mind is using edges to make judgements. If it works, I will share with you. – user2666495 Aug 19 '13 at 16:02
  • I tried to check the face coordinates with the original one and setting the material index of each face to the original value. But its not working for me. – Deeps Oct 06 '17 at 14:32