Update scene document version and enhance box brush calculations
This commit is contained in:
@@ -6,7 +6,8 @@ import type { InteractionLink } from "../interactions/interaction-links";
|
|||||||
import { cloneMaterialRegistry, createStarterMaterialRegistry, type MaterialDef } from "../materials/starter-material-library";
|
import { cloneMaterialRegistry, createStarterMaterialRegistry, type MaterialDef } from "../materials/starter-material-library";
|
||||||
import { createDefaultWorldSettings, type WorldSettings } from "./world-settings";
|
import { createDefaultWorldSettings, type WorldSettings } from "./world-settings";
|
||||||
|
|
||||||
export const SCENE_DOCUMENT_VERSION = 17 as const;
|
export const SCENE_DOCUMENT_VERSION = 18 as const;
|
||||||
|
export const WHITEBOX_FLOAT_TRANSFORM_SCENE_DOCUMENT_VERSION = 18 as const;
|
||||||
export const PLAYER_START_COLLIDER_SETTINGS_SCENE_DOCUMENT_VERSION = 17 as const;
|
export const PLAYER_START_COLLIDER_SETTINGS_SCENE_DOCUMENT_VERSION = 17 as const;
|
||||||
export const IMPORTED_MODEL_COLLIDERS_SCENE_DOCUMENT_VERSION = 16 as const;
|
export const IMPORTED_MODEL_COLLIDERS_SCENE_DOCUMENT_VERSION = 16 as const;
|
||||||
export const ENTITY_NAMES_SCENE_DOCUMENT_VERSION = 15 as const;
|
export const ENTITY_NAMES_SCENE_DOCUMENT_VERSION = 15 as const;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { Euler, MathUtils, Vector3 } from "three";
|
||||||
|
|
||||||
import type { Vec3 } from "../core/vector";
|
import type { Vec3 } from "../core/vector";
|
||||||
import type { BoxBrush } from "../document/brushes";
|
import type { BoxBrush } from "../document/brushes";
|
||||||
|
|
||||||
@@ -15,33 +17,52 @@ export function getBoxBrushHalfSize(brush: BoxBrush): Vec3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getBoxBrushBounds(brush: BoxBrush): BoxBrushBounds {
|
export function getBoxBrushBounds(brush: BoxBrush): BoxBrushBounds {
|
||||||
const halfSize = getBoxBrushHalfSize(brush);
|
const corners = getBoxBrushCornerPositions(brush);
|
||||||
|
const firstCorner = corners[0];
|
||||||
|
const min = { ...firstCorner };
|
||||||
|
const max = { ...firstCorner };
|
||||||
|
|
||||||
|
for (const corner of corners.slice(1)) {
|
||||||
|
min.x = Math.min(min.x, corner.x);
|
||||||
|
min.y = Math.min(min.y, corner.y);
|
||||||
|
min.z = Math.min(min.z, corner.z);
|
||||||
|
max.x = Math.max(max.x, corner.x);
|
||||||
|
max.y = Math.max(max.y, corner.y);
|
||||||
|
max.z = Math.max(max.z, corner.z);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
min: {
|
min,
|
||||||
x: brush.center.x - halfSize.x,
|
max
|
||||||
y: brush.center.y - halfSize.y,
|
|
||||||
z: brush.center.z - halfSize.z
|
|
||||||
},
|
|
||||||
max: {
|
|
||||||
x: brush.center.x + halfSize.x,
|
|
||||||
y: brush.center.y + halfSize.y,
|
|
||||||
z: brush.center.z + halfSize.z
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getBoxBrushCornerPositions(brush: BoxBrush): Vec3[] {
|
export function getBoxBrushCornerPositions(brush: BoxBrush): Vec3[] {
|
||||||
const bounds = getBoxBrushBounds(brush);
|
const halfSize = getBoxBrushHalfSize(brush);
|
||||||
|
const rotation = new Euler(
|
||||||
return [
|
MathUtils.degToRad(brush.rotationDegrees.x),
|
||||||
{ x: bounds.min.x, y: bounds.min.y, z: bounds.min.z },
|
MathUtils.degToRad(brush.rotationDegrees.y),
|
||||||
{ x: bounds.max.x, y: bounds.min.y, z: bounds.min.z },
|
MathUtils.degToRad(brush.rotationDegrees.z),
|
||||||
{ x: bounds.min.x, y: bounds.max.y, z: bounds.min.z },
|
"XYZ"
|
||||||
{ x: bounds.max.x, y: bounds.max.y, z: bounds.min.z },
|
);
|
||||||
{ x: bounds.min.x, y: bounds.min.y, z: bounds.max.z },
|
const offsets = [
|
||||||
{ x: bounds.max.x, y: bounds.min.y, z: bounds.max.z },
|
new Vector3(-halfSize.x, -halfSize.y, -halfSize.z),
|
||||||
{ x: bounds.min.x, y: bounds.max.y, z: bounds.max.z },
|
new Vector3(halfSize.x, -halfSize.y, -halfSize.z),
|
||||||
{ x: bounds.max.x, y: bounds.max.y, z: bounds.max.z }
|
new Vector3(-halfSize.x, halfSize.y, -halfSize.z),
|
||||||
|
new Vector3(halfSize.x, halfSize.y, -halfSize.z),
|
||||||
|
new Vector3(-halfSize.x, -halfSize.y, halfSize.z),
|
||||||
|
new Vector3(halfSize.x, -halfSize.y, halfSize.z),
|
||||||
|
new Vector3(-halfSize.x, halfSize.y, halfSize.z),
|
||||||
|
new Vector3(halfSize.x, halfSize.y, halfSize.z)
|
||||||
];
|
];
|
||||||
|
|
||||||
|
return offsets.map((offset) => {
|
||||||
|
const rotatedOffset = offset.clone().applyEuler(rotation);
|
||||||
|
|
||||||
|
return {
|
||||||
|
x: brush.center.x + rotatedOffset.x,
|
||||||
|
y: brush.center.y + rotatedOffset.y,
|
||||||
|
z: brush.center.z + rotatedOffset.z
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user