Generalize terrain weight handling using stored paint weight count
This commit is contained in:
@@ -6,9 +6,9 @@ import type {
|
|||||||
} from "../core/terrain-brush";
|
} from "../core/terrain-brush";
|
||||||
import {
|
import {
|
||||||
getOrCreateTerrainFoliageMask,
|
getOrCreateTerrainFoliageMask,
|
||||||
|
getTerrainStoredPaintWeightCount,
|
||||||
isTerrainFoliageMaskEmpty,
|
isTerrainFoliageMaskEmpty,
|
||||||
markTerrainRenderSamplesDirty,
|
markTerrainRenderSamplesDirty,
|
||||||
TERRAIN_LAYER_COUNT,
|
|
||||||
updateTerrainBoundsCacheAfterHeightPatch,
|
updateTerrainBoundsCacheAfterHeightPatch,
|
||||||
type Terrain,
|
type Terrain,
|
||||||
type TerrainSampleBounds
|
type TerrainSampleBounds
|
||||||
@@ -124,7 +124,9 @@ export function applyTerrainBrushPatchToDocument(
|
|||||||
renderDirtyBounds = mergeTerrainSampleIndexIntoBounds(
|
renderDirtyBounds = mergeTerrainSampleIndexIntoBounds(
|
||||||
renderDirtyBounds,
|
renderDirtyBounds,
|
||||||
terrain,
|
terrain,
|
||||||
Math.floor(entry.index / (TERRAIN_LAYER_COUNT - 1))
|
Math.floor(
|
||||||
|
entry.index / getTerrainStoredPaintWeightCount(terrain.layers.length)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
getTerrainPaintWeightSampleOffset,
|
getTerrainPaintWeightSampleOffset,
|
||||||
getTerrainSampleIndex,
|
getTerrainSampleIndex,
|
||||||
getTerrainSampleLayerWeights,
|
getTerrainSampleLayerWeights,
|
||||||
TERRAIN_LAYER_COUNT,
|
getTerrainStoredPaintWeightCount,
|
||||||
type Terrain
|
type Terrain
|
||||||
} from "../document/terrains";
|
} from "../document/terrains";
|
||||||
import { createTerrainBrushPatchFromTerrains } from "./terrain-brush";
|
import { createTerrainBrushPatchFromTerrains } from "./terrain-brush";
|
||||||
@@ -185,14 +185,12 @@ function getRoadPaintLayerIndex(path: ScenePath, terrain: Terrain): number | nul
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createRoadTargetWeights(
|
function createRoadTargetWeights(
|
||||||
|
terrain: Terrain,
|
||||||
layerIndex: number
|
layerIndex: number
|
||||||
): [number, number, number, number] {
|
): number[] {
|
||||||
return [
|
return terrain.layers.map((_, currentLayerIndex) =>
|
||||||
layerIndex === 0 ? 1 : 0,
|
currentLayerIndex === layerIndex ? 1 : 0
|
||||||
layerIndex === 1 ? 1 : 0,
|
);
|
||||||
layerIndex === 2 ? 1 : 0,
|
|
||||||
layerIndex === 3 ? 1 : 0
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyRoadPaintWeights(
|
function applyRoadPaintWeights(
|
||||||
@@ -204,14 +202,13 @@ function applyRoadPaintWeights(
|
|||||||
changedPaintWeightIndices: Set<number>
|
changedPaintWeightIndices: Set<number>
|
||||||
) {
|
) {
|
||||||
const currentWeights = getTerrainSampleLayerWeights(terrain, sampleX, sampleZ);
|
const currentWeights = getTerrainSampleLayerWeights(terrain, sampleX, sampleZ);
|
||||||
const targetWeights = createRoadTargetWeights(layerIndex);
|
const targetWeights = createRoadTargetWeights(terrain, layerIndex);
|
||||||
const offset = getTerrainPaintWeightSampleOffset(terrain, sampleX, sampleZ);
|
const offset = getTerrainPaintWeightSampleOffset(terrain, sampleX, sampleZ);
|
||||||
|
const storedWeightCount = getTerrainStoredPaintWeightCount(
|
||||||
|
terrain.layers.length
|
||||||
|
);
|
||||||
|
|
||||||
for (
|
for (let layerOffset = 0; layerOffset < storedWeightCount; layerOffset += 1) {
|
||||||
let layerOffset = 0;
|
|
||||||
layerOffset < TERRAIN_LAYER_COUNT - 1;
|
|
||||||
layerOffset += 1
|
|
||||||
) {
|
|
||||||
const paintWeightIndex = offset + layerOffset;
|
const paintWeightIndex = offset + layerOffset;
|
||||||
const currentWeight = currentWeights[layerOffset + 1] ?? 0;
|
const currentWeight = currentWeights[layerOffset + 1] ?? 0;
|
||||||
const nextWeight = lerp(
|
const nextWeight = lerp(
|
||||||
|
|||||||
Reference in New Issue
Block a user