各位好,引擎中似乎没有返回的地形的几何信息(geometricInfo)?我正在尝试对地形添加第三方物理库的支持,比如射线检测或者其他法向、面信息拓展等等,创建的其他内建模型或导入外部网格貌似都有这个数据。但地形我没有找到类似的字段,是否有方法可以在场景上支持获取地形(Teerain)的以下数据?
IGeometricInfo:
positions: new Float32Array(),
indices: new Uint8Array(),
boundingBox: { min: Vec3.ZERO, max: Vec3.ZERO },
1赞
找到了,从其他引擎搬运过来的。
getIndices (size){
let indices=[]
let subdivisionsX=size.width
let subdivisionsY=size.height
for (let row = 0; row < subdivisionsY; row++) {
for (let col = 0; col < subdivisionsX; col++) {
indices.push(col + 1 + (row + 1) * (subdivisionsX + 1));
indices.push(col + 1 + row * (subdivisionsX + 1));
indices.push(col + row * (subdivisionsX + 1));
indices.push(col + (row + 1) * (subdivisionsX + 1));
indices.push(col + 1 + (row + 1) * (subdivisionsX + 1));
indices.push(col + row * (subdivisionsX + 1));
}
}
return indices;
}
getPositions(size){
let positions=[]
for (let j = 0; j < size.height+1; ++j) {
for (let i = 0; i < size.width+1; ++i) {
const x = i;
const y = j;
const position = this.terrain.getPosition(x, y);
positions.push(position.x)
positions.push(position.y)
positions.push(position.z)
}
}
return positions
}
3赞
更完善的版本,上面的有点问题。
getIndices (size){
let indices=[]
let subdivisionsX=size[0]-1
let subdivisionsY=size[1]-1
for (let row = 0; row < subdivisionsY; row++) {
for (let col = 0; col < subdivisionsX; col++) {
const useg1 = subdivisionsX + 1;
const a = col + row * useg1;
const b = col + (row + 1) * useg1;
const c = (col + 1) + (row + 1) * useg1;
const d = (col + 1) + row * useg1;
indices.push(a, d, b);
indices.push(d, c, b);
}
}
return indices;
}
getPositions(size){
let positions=[]
for (let j = 0; j < size[0]; j++) {
for (let i = 0; i < size[1]; i++) {
const x = i;
const y = j;
const position = this.terrain.getPosition(x, y);
positions.push(position.x,position.y,position.z)
}
}
return positions
}
1赞