在使用shape生成面,或者再拉升时,如果使用贴图就会不正常显示;经过查找了解到大多数解决方案都是针对Geometry的uv更新,所以在论坛查找方法自己处理了一个方法意外解决了这个问题,但拉升成体时Z轴的更新出现了问题。。。还需要继续研究
reMapUv(obj) {
// geometry.computeBoundingBox();
// console.log(geometry);
let temp=new THREE.Group()
temp.add(obj.clone())
let box = new THREE.Box3().setFromObject(temp)
var max = box.max,
min = box.min;
var offset = new THREE.Vector3(0 - min.x, 0 - min.y, 0 - min.z);
var range = new THREE.Vector3(max.x - min.x, max.y - min.y, max.z - min.z);
var uvAttribute = obj.geometry.attributes.uv;
for ( var i = 0; i < uvAttribute.count; i ++ ) {
var u = uvAttribute.getX( i );
var v = uvAttribute.getY( i );
var z = uvAttribute.getZ( i );
// do something with uv
u=(u+offset.x)/range.x
v=(v+offset.y)/range.y
// something error
// z=(z+offset.z)/range.z
z=(z+offset.y)/range.y
// write values back to attribute
uvAttribute.setXYZ( i, u, v, z);
// uvAttribute.setZ(i,z)
}
uvAttribute.needsUpdate = true;
}
|