我正在使用本地裁剪来允许我的用户在我的模型上放置裁剪平面。当他们添加裁剪平面时,我使用
PlaneHelper
可视化平面的位置。我似乎无法让 PlaneHelper 以我的模型为中心。它似乎总是以(0,0,0)
为中心。我的模型是从外部源加载的,所以我不能假设它们总是位于场景中间。大多数 ThreeJS 示例都涉及一个存在于场景中心的模型,因此 PlaneHelper 无需将其移动到任何地方即可工作。 (示例 1,示例 2)。
我希望 PlaneHelper 以模型为中心(在 MS Paint 中模拟):
我像这样创建
Plane
和PlaneHelper
:
//helper function to calculate the center of the model I'm adding a clipping plane to
const center = this.getCenter(this.models[0]);
//helper function to determine how big the PlaneHelper is supposed to be
const size = this.getMaxDimension(this.models[0]);
//Create a plane along the X axis, centered on the model, along with something to visualize the plane
const localPlane = new THREE.Plane(new Vector3(1, 0, 0), -center.x);
const helper = new THREE.PlaneHelper( localPlane, size * 2, 0xFF0000 );
this.scene.add(helper);
//Add the plane to my my model
this.models[0].material.forEach((m: Material) => {
if(!m.clippingPlanes){
m.clippingPlanes = [localPlane];
} else {
m.clippingPlanes.push(localPlane);
}
});
正如您在第一张图片中看到的,
PlaneHelper
不在模型的中心。如果我尝试设置 PlaneHelper 的位置,我可以在模型的中心正确地看到 PlaneHelper 的尾巴,但实际飞机呈现一个奇怪的角度并且实际上并没有移动。
helper.position.copy(center);
“移动”
PlaneHelper
使其以我的模型为中心的正确方法是什么?