auto-git:
[change] src/viewport-three/viewport-host.ts
This commit is contained in:
@@ -385,6 +385,8 @@ interface ActiveTerrainBrushStroke {
|
|||||||
previewTerrain: Terrain;
|
previewTerrain: Terrain;
|
||||||
changed: boolean;
|
changed: boolean;
|
||||||
dirtyBounds: TerrainBrushDirtySampleBounds | null;
|
dirtyBounds: TerrainBrushDirtySampleBounds | null;
|
||||||
|
heightSampleIndices: Set<number>;
|
||||||
|
paintWeightIndices: Set<number>;
|
||||||
referenceHeight: number | null;
|
referenceHeight: number | null;
|
||||||
lastAppliedPoint: {
|
lastAppliedPoint: {
|
||||||
x: number;
|
x: number;
|
||||||
@@ -9504,6 +9506,8 @@ export class ViewportHost {
|
|||||||
): {
|
): {
|
||||||
changed: boolean;
|
changed: boolean;
|
||||||
dirtyBounds: TerrainBrushDirtySampleBounds | null;
|
dirtyBounds: TerrainBrushDirtySampleBounds | null;
|
||||||
|
heightSampleIndices: number[];
|
||||||
|
paintWeightIndices: number[];
|
||||||
lastAppliedPoint: {
|
lastAppliedPoint: {
|
||||||
x: number;
|
x: number;
|
||||||
z: number;
|
z: number;
|
||||||
@@ -9518,12 +9522,16 @@ export class ViewportHost {
|
|||||||
return {
|
return {
|
||||||
changed: false,
|
changed: false,
|
||||||
dirtyBounds: null,
|
dirtyBounds: null,
|
||||||
|
heightSampleIndices: [],
|
||||||
|
paintWeightIndices: [],
|
||||||
lastAppliedPoint: from
|
lastAppliedPoint: from
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let changed = false;
|
let changed = false;
|
||||||
let dirtyBounds: TerrainBrushDirtySampleBounds | null = null;
|
let dirtyBounds: TerrainBrushDirtySampleBounds | null = null;
|
||||||
|
const heightSampleIndices = new Set<number>();
|
||||||
|
const paintWeightIndices = new Set<number>();
|
||||||
let lastAppliedPoint = from;
|
let lastAppliedPoint = from;
|
||||||
const stepCount = Math.floor(distance / spacing);
|
const stepCount = Math.floor(distance / spacing);
|
||||||
const mergeDirtyBounds = (nextBounds: TerrainBrushDirtySampleBounds | null) => {
|
const mergeDirtyBounds = (nextBounds: TerrainBrushDirtySampleBounds | null) => {
|
||||||
@@ -9568,16 +9576,40 @@ export class ViewportHost {
|
|||||||
);
|
);
|
||||||
changed ||= result.changed;
|
changed ||= result.changed;
|
||||||
mergeDirtyBounds(result.dirtyBounds);
|
mergeDirtyBounds(result.dirtyBounds);
|
||||||
|
for (const sampleIndex of result.heightSampleIndices) {
|
||||||
|
heightSampleIndices.add(sampleIndex);
|
||||||
|
}
|
||||||
|
for (const paintWeightIndex of result.paintWeightIndices) {
|
||||||
|
paintWeightIndices.add(paintWeightIndex);
|
||||||
|
}
|
||||||
lastAppliedPoint = point;
|
lastAppliedPoint = point;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
changed,
|
changed,
|
||||||
dirtyBounds,
|
dirtyBounds,
|
||||||
|
heightSampleIndices: [...heightSampleIndices],
|
||||||
|
paintWeightIndices: [...paintWeightIndices],
|
||||||
lastAppliedPoint
|
lastAppliedPoint
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private mergeTerrainBrushStampIndices(
|
||||||
|
stroke: ActiveTerrainBrushStroke,
|
||||||
|
result: Pick<
|
||||||
|
ReturnType<typeof applyTerrainBrushStampInPlace>,
|
||||||
|
"heightSampleIndices" | "paintWeightIndices"
|
||||||
|
>
|
||||||
|
) {
|
||||||
|
for (const sampleIndex of result.heightSampleIndices) {
|
||||||
|
stroke.heightSampleIndices.add(sampleIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const paintWeightIndex of result.paintWeightIndices) {
|
||||||
|
stroke.paintWeightIndices.add(paintWeightIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private beginTerrainBrushStroke(event: PointerEvent): boolean {
|
private beginTerrainBrushStroke(event: PointerEvent): boolean {
|
||||||
if (
|
if (
|
||||||
!this.isTerrainBrushActive() ||
|
!this.isTerrainBrushActive() ||
|
||||||
@@ -9624,6 +9656,8 @@ export class ViewportHost {
|
|||||||
previewTerrain,
|
previewTerrain,
|
||||||
changed: initialStamp.changed,
|
changed: initialStamp.changed,
|
||||||
dirtyBounds: initialStamp.dirtyBounds,
|
dirtyBounds: initialStamp.dirtyBounds,
|
||||||
|
heightSampleIndices: new Set(initialStamp.heightSampleIndices),
|
||||||
|
paintWeightIndices: new Set(initialStamp.paintWeightIndices),
|
||||||
referenceHeight,
|
referenceHeight,
|
||||||
lastAppliedPoint: {
|
lastAppliedPoint: {
|
||||||
x: hit.point.x,
|
x: hit.point.x,
|
||||||
@@ -9675,6 +9709,10 @@ export class ViewportHost {
|
|||||||
segmentResult.lastAppliedPoint.z !==
|
segmentResult.lastAppliedPoint.z !==
|
||||||
this.activeTerrainBrushStroke.lastAppliedPoint.z
|
this.activeTerrainBrushStroke.lastAppliedPoint.z
|
||||||
) {
|
) {
|
||||||
|
this.mergeTerrainBrushStampIndices(
|
||||||
|
this.activeTerrainBrushStroke,
|
||||||
|
segmentResult
|
||||||
|
);
|
||||||
this.activeTerrainBrushStroke = {
|
this.activeTerrainBrushStroke = {
|
||||||
...this.activeTerrainBrushStroke,
|
...this.activeTerrainBrushStroke,
|
||||||
changed:
|
changed:
|
||||||
@@ -9728,6 +9766,22 @@ export class ViewportHost {
|
|||||||
let finalPreviewTerrain = this.activeTerrainBrushStroke.previewTerrain;
|
let finalPreviewTerrain = this.activeTerrainBrushStroke.previewTerrain;
|
||||||
let changed = this.activeTerrainBrushStroke.changed;
|
let changed = this.activeTerrainBrushStroke.changed;
|
||||||
let dirtyBounds = this.activeTerrainBrushStroke.dirtyBounds;
|
let dirtyBounds = this.activeTerrainBrushStroke.dirtyBounds;
|
||||||
|
const heightSampleIndices = new Set(activeStroke.heightSampleIndices);
|
||||||
|
const paintWeightIndices = new Set(activeStroke.paintWeightIndices);
|
||||||
|
const mergeStampIndices = (
|
||||||
|
result: Pick<
|
||||||
|
ReturnType<typeof applyTerrainBrushStampInPlace>,
|
||||||
|
"heightSampleIndices" | "paintWeightIndices"
|
||||||
|
>
|
||||||
|
) => {
|
||||||
|
for (const sampleIndex of result.heightSampleIndices) {
|
||||||
|
heightSampleIndices.add(sampleIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const paintWeightIndex of result.paintWeightIndices) {
|
||||||
|
paintWeightIndices.add(paintWeightIndex);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (!cancelled) {
|
if (!cancelled) {
|
||||||
const hit = this.getTerrainBrushHitAtClientPosition(
|
const hit = this.getTerrainBrushHitAtClientPosition(
|
||||||
@@ -9747,6 +9801,7 @@ export class ViewportHost {
|
|||||||
this.activeTerrainBrushStroke.referenceHeight
|
this.activeTerrainBrushStroke.referenceHeight
|
||||||
);
|
);
|
||||||
changed ||= segmentResult.changed;
|
changed ||= segmentResult.changed;
|
||||||
|
mergeStampIndices(segmentResult);
|
||||||
dirtyBounds = this.mergeTerrainBrushDirtyBounds(
|
dirtyBounds = this.mergeTerrainBrushDirtyBounds(
|
||||||
dirtyBounds,
|
dirtyBounds,
|
||||||
segmentResult.dirtyBounds
|
segmentResult.dirtyBounds
|
||||||
@@ -9766,6 +9821,7 @@ export class ViewportHost {
|
|||||||
this.activeTerrainBrushStroke.referenceHeight
|
this.activeTerrainBrushStroke.referenceHeight
|
||||||
);
|
);
|
||||||
changed ||= pointResult.changed;
|
changed ||= pointResult.changed;
|
||||||
|
mergeStampIndices(pointResult);
|
||||||
dirtyBounds = this.mergeTerrainBrushDirtyBounds(
|
dirtyBounds = this.mergeTerrainBrushDirtyBounds(
|
||||||
dirtyBounds,
|
dirtyBounds,
|
||||||
pointResult.dirtyBounds
|
pointResult.dirtyBounds
|
||||||
@@ -9777,7 +9833,8 @@ export class ViewportHost {
|
|||||||
const commit =
|
const commit =
|
||||||
!cancelled &&
|
!cancelled &&
|
||||||
dirtyBounds !== null &&
|
dirtyBounds !== null &&
|
||||||
changed;
|
changed &&
|
||||||
|
(heightSampleIndices.size > 0 || paintWeightIndices.size > 0);
|
||||||
const finalDirtyBounds = dirtyBounds;
|
const finalDirtyBounds = dirtyBounds;
|
||||||
const toolState = this.activeTerrainBrushStroke.toolState;
|
const toolState = this.activeTerrainBrushStroke.toolState;
|
||||||
this.activeTerrainBrushStroke = null;
|
this.activeTerrainBrushStroke = null;
|
||||||
@@ -9791,7 +9848,8 @@ export class ViewportHost {
|
|||||||
const patch = createTerrainBrushPatchFromTerrains({
|
const patch = createTerrainBrushPatchFromTerrains({
|
||||||
before: activeStroke.baseTerrain,
|
before: activeStroke.baseTerrain,
|
||||||
after: finalPreviewTerrain,
|
after: finalPreviewTerrain,
|
||||||
dirtyBounds: finalDirtyBounds!
|
heightSampleIndices,
|
||||||
|
paintWeightIndices
|
||||||
});
|
});
|
||||||
|
|
||||||
const committed =
|
const committed =
|
||||||
|
|||||||
Reference in New Issue
Block a user