Add foliage mask support to terrain mesh generation
This commit is contained in:
@@ -479,7 +479,8 @@ function buildTerrainLodLevelMeshData(
|
|||||||
endSampleX: number,
|
endSampleX: number,
|
||||||
endSampleZ: number,
|
endSampleZ: number,
|
||||||
level: number,
|
level: number,
|
||||||
stride: number
|
stride: number,
|
||||||
|
options: TerrainMeshBuildOptions
|
||||||
): TerrainLodLevelMeshData {
|
): TerrainLodLevelMeshData {
|
||||||
const sampleXs = createLodSampleCoordinates(
|
const sampleXs = createLodSampleCoordinates(
|
||||||
startSampleX,
|
startSampleX,
|
||||||
@@ -494,6 +495,7 @@ function buildTerrainLodLevelMeshData(
|
|||||||
const positions: number[] = [];
|
const positions: number[] = [];
|
||||||
const uvs: number[] = [];
|
const uvs: number[] = [];
|
||||||
const layerWeights: number[] = [];
|
const layerWeights: number[] = [];
|
||||||
|
const foliageMaskWeights: number[] = [];
|
||||||
const indices: number[] = [];
|
const indices: number[] = [];
|
||||||
|
|
||||||
for (const sampleZ of sampleZs) {
|
for (const sampleZ of sampleZs) {
|
||||||
@@ -505,7 +507,9 @@ function buildTerrainLodLevelMeshData(
|
|||||||
0,
|
0,
|
||||||
positions,
|
positions,
|
||||||
uvs,
|
uvs,
|
||||||
layerWeights
|
layerWeights,
|
||||||
|
foliageMaskWeights,
|
||||||
|
options
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -553,7 +557,9 @@ function buildTerrainLodLevelMeshData(
|
|||||||
positions,
|
positions,
|
||||||
uvs,
|
uvs,
|
||||||
layerWeights,
|
layerWeights,
|
||||||
indices
|
foliageMaskWeights,
|
||||||
|
indices,
|
||||||
|
options
|
||||||
);
|
);
|
||||||
pushTerrainLodSkirtSegment(
|
pushTerrainLodSkirtSegment(
|
||||||
terrain,
|
terrain,
|
||||||
@@ -565,7 +571,9 @@ function buildTerrainLodLevelMeshData(
|
|||||||
positions,
|
positions,
|
||||||
uvs,
|
uvs,
|
||||||
layerWeights,
|
layerWeights,
|
||||||
indices
|
foliageMaskWeights,
|
||||||
|
indices,
|
||||||
|
options
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -580,7 +588,9 @@ function buildTerrainLodLevelMeshData(
|
|||||||
positions,
|
positions,
|
||||||
uvs,
|
uvs,
|
||||||
layerWeights,
|
layerWeights,
|
||||||
indices
|
foliageMaskWeights,
|
||||||
|
indices,
|
||||||
|
options
|
||||||
);
|
);
|
||||||
pushTerrainLodSkirtSegment(
|
pushTerrainLodSkirtSegment(
|
||||||
terrain,
|
terrain,
|
||||||
@@ -592,13 +602,16 @@ function buildTerrainLodLevelMeshData(
|
|||||||
positions,
|
positions,
|
||||||
uvs,
|
uvs,
|
||||||
layerWeights,
|
layerWeights,
|
||||||
indices
|
foliageMaskWeights,
|
||||||
|
indices,
|
||||||
|
options
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const typedPositions = new Float32Array(positions);
|
const typedPositions = new Float32Array(positions);
|
||||||
const typedUvs = new Float32Array(uvs);
|
const typedUvs = new Float32Array(uvs);
|
||||||
const typedLayerWeights = new Float32Array(layerWeights);
|
const typedLayerWeights = new Float32Array(layerWeights);
|
||||||
|
const typedFoliageMaskWeights = new Float32Array(foliageMaskWeights);
|
||||||
const typedIndices = new Uint32Array(indices);
|
const typedIndices = new Uint32Array(indices);
|
||||||
const geometry = new BufferGeometry();
|
const geometry = new BufferGeometry();
|
||||||
|
|
||||||
@@ -608,6 +621,10 @@ function buildTerrainLodLevelMeshData(
|
|||||||
"terrainLayerWeights",
|
"terrainLayerWeights",
|
||||||
new BufferAttribute(typedLayerWeights, TERRAIN_LAYER_COUNT)
|
new BufferAttribute(typedLayerWeights, TERRAIN_LAYER_COUNT)
|
||||||
);
|
);
|
||||||
|
geometry.setAttribute(
|
||||||
|
"terrainFoliageMask",
|
||||||
|
new BufferAttribute(typedFoliageMaskWeights, 1)
|
||||||
|
);
|
||||||
geometry.setIndex(new BufferAttribute(typedIndices, 1));
|
geometry.setIndex(new BufferAttribute(typedIndices, 1));
|
||||||
geometry.computeVertexNormals();
|
geometry.computeVertexNormals();
|
||||||
geometry.computeBoundingBox();
|
geometry.computeBoundingBox();
|
||||||
@@ -625,6 +642,7 @@ function buildTerrainLodLevelMeshData(
|
|||||||
normals,
|
normals,
|
||||||
uvs: typedUvs,
|
uvs: typedUvs,
|
||||||
layerWeights: typedLayerWeights,
|
layerWeights: typedLayerWeights,
|
||||||
|
foliageMaskWeights: typedFoliageMaskWeights,
|
||||||
indices: typedIndices,
|
indices: typedIndices,
|
||||||
skirtVertexCount: typedPositions.length / 3 - skirtStartVertexCount
|
skirtVertexCount: typedPositions.length / 3 - skirtStartVertexCount
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user