Problem with Rotation
MichaelHilgers opened this issue · 4 comments
Hello,
i have a problem with substract, union an intersect when the parent Groups of a mesh are rotated.
The position of the meshs in World are not apply before doing the substract.
Please view my code Sample:
`
private csgSample(){
var scene = this.baseScene.scene;
const camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1000
)
camera.position.x = 0.5
camera.position.y = 2
camera.position.z = 2.5
camera.up.set(0, 0, 1);
this.baseScene.camera = camera;
this.baseScene.controls = new OrbitControls(camera, this.baseScene.renderer.domElement);
//create a cube and sphere and intersect them
const cubeMesh = new THREE.Mesh(
new THREE.BoxGeometry(2, 2, 2),
new THREE.MeshPhongMaterial({ color: 0xff0000,
opacity: 0.5,
transparent:true, })
)
const sphereMesh = new THREE.Mesh(
new THREE.SphereGeometry(1.45, 8, 8),
new THREE.MeshPhongMaterial({ color: 0x0000ff ,
opacity: 0.5,
transparent:true,})
)
var g = new THREE.Group();
g.position.set(0.5, 0, 0.5);
g.rotation.x = 15;
cubeMesh.position.set(0, 0, 1);
g.add(cubeMesh);
scene.add(g)
sphereMesh.position.set(0, 0, 0)
scene.add(sphereMesh)
scene.updateMatrix();
scene.updateMatrixWorld(true);
var meshResult = CSG.subtract( cubeMesh, sphereMesh);
meshResult.material = new THREE.MeshPhongMaterial({
color: 0xff00ff
})
//g.add(meshResult);
meshResult.position.set(0, 0, -5)
scene.add(meshResult)
scene.updateMatrix();
scene.updateMatrixWorld(true);
What i doing wrong?
Thanks
I think attaching the mesh to a group might be breaking things... probably a bug..:)
but could you try with attaching the mesh to the scene instead and setting its rotation/position to verify?
Thanks for reporting this..
Ok great.. Appreciate you researching it for me!
I will add this to my to-do list for the next major release. If this is a showstopping issue for you, we can discuss it further.. I'm leaving this open for now so that others with the same issue can find it.
Thanks again!
Привет
Я исправил это, удалив объект из родителя и прикрепив его к сцене. После этого работает.
Hi
i have fix it, by removing the object from parent and attaching to scene. After this, it works.
thank you, it works!
text from image:
private reparentObject3D (object, oldParent, newParent)
{
object.matrixWorld.decompose(object.position, object.quaternion, object.scale);
oldParent.remove(object);
newParent.add(object);
object.parent = newParent;
object.updateMatrix();
object.updateMatrixWorld();
}