1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-13 14:05:35 +02:00

hasCollisions

This commit is contained in:
syuilo
2026-04-15 11:54:38 +09:00
parent c426f95bee
commit 5104bafe95
79 changed files with 86 additions and 104 deletions

View File

@@ -337,7 +337,7 @@ export type ObjectDef<OpSc extends OptionsSchema = OptionsSchema> = {
default: GetOptionsSchemaValues<OpSc>;
};
placement: 'top' | 'side' | 'bottom' | 'wall' | 'ceiling' | 'floor';
noCollisions?: boolean;
hasCollisions?: boolean;
//groupingMeshes: string[]; // multi-materialなメッシュは複数のメッシュに分割されるが、それだと不便な場合に追加の親メッシュでグルーピングするための指定
isChair?: boolean;
treatLoaderResult?: (loaderResult: BABYLON.AssetContainer) => void;
@@ -379,43 +379,14 @@ function getMeshesBoundingBox(meshes: BABYLON.Mesh[]): BABYLON.BoundingBox {
}
function enableObjectCollision(meshes: BABYLON.Mesh[]) {
let hasCollisionMesh = false;
for (const mesh of meshes) {
if (mesh.name.includes('__COLLISION__')) {
hasCollisionMesh = true;
break;
mesh.checkCollisions = true;
//mesh.isVisible = true; // debug
} else {
mesh.checkCollisions = false;
}
}
if (hasCollisionMesh) {
for (const mesh of meshes) {
if (mesh.name.includes('__COLLISION__')) {
mesh.checkCollisions = true;
//mesh.isVisible = true; // debug
} else {
mesh.checkCollisions = false;
}
}
return;
}
// なんかうまくいかない
//const boundingInfo = getMeshesBoundingBox(meshes.filter(m => m.isEnabled() && m.isVisible));
//const collider = meshes.find(m => m.name.includes('__COLLISION_AUTO_GENERATED_INTERNALY__'))!;
//if (collider == null) return;
////collider.position.y = ((boundingInfo.maximum.y + boundingInfo.minimum.y) / 2) / WORLD_SCALE;
//collider.scaling = new BABYLON.Vector3(
// (boundingInfo.maximum.x - boundingInfo.minimum.x) || 1,
// (boundingInfo.maximum.y - boundingInfo.minimum.y) || 1,
// (boundingInfo.maximum.z - boundingInfo.minimum.z) || 1,
//);
//collider.checkCollisions = true;
//collider.isVisible = true;
for (const mesh of meshes) {
mesh.checkCollisions = true;
}
}
export type RoomEngineEvents = {
@@ -1191,7 +1162,6 @@ export class RoomEngine extends EventEmitter<RoomEngineEvents> {
options: any;
}) {
const def = getObjectDef(args.type);
const collisionsDisabled = def.placement === 'ceiling' || def.noCollisions;
const root = new BABYLON.TransformNode(`object_${args.id}_${args.type}`, this.scene);
@@ -1402,7 +1372,7 @@ export class RoomEngine extends EventEmitter<RoomEngineEvents> {
if (!this.scene.meshes.includes(mesh)) this.scene.addMesh(mesh);
}
if (!collisionsDisabled) {
if (def.hasCollisions) {
enableObjectCollision(meshes);
}
});
@@ -1442,7 +1412,7 @@ export class RoomEngine extends EventEmitter<RoomEngineEvents> {
model.bakeMesh();
if (!collisionsDisabled) {
if (def.hasCollisions) {
enableObjectCollision(root.getChildMeshes());
}
@@ -1710,7 +1680,6 @@ export class RoomEngine extends EventEmitter<RoomEngineEvents> {
const id = genId();
const def = getObjectDef(type);
const collisionsDisabled = def.placement === 'ceiling' || def.noCollisions;
const options = deepClone(def.options.default);
@@ -1750,7 +1719,7 @@ export class RoomEngine extends EventEmitter<RoomEngineEvents> {
// todo
},
onDone: () => { // todo: sticky状態などを引数でもらうようにしたい
if (!collisionsDisabled) {
if (def.hasCollisions) {
enableObjectCollision(root.getChildMeshes());
}

View File

@@ -21,7 +21,7 @@ export const a4Case = defineObject({
},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: ({ options, model }) => {
const bodyMesh = model.findMesh('__X_BODY__');
const bodyMaterial = bodyMesh.material as BABYLON.PBRMaterial;

View File

@@ -13,7 +13,7 @@ export const aircon = defineObject({
default: {},
},
placement: 'wall',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -15,7 +15,7 @@ export const aquarium = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: ({ scene, root }) => {
return {
onInited: () => {

View File

@@ -26,7 +26,7 @@ export const aromaReedDiffuser = defineObject({
},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: ({ options, model }) => {
const bottleMesh = model.findMesh('__X_BOTTLE__');
const bottleMaterial = bottleMesh.material as BABYLON.PBRMaterial;

View File

@@ -13,7 +13,7 @@ export const banknote = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -15,7 +15,7 @@ export const beamLamp = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: ({ room, root, scene }) => {
return {
onInited: () => {

View File

@@ -21,6 +21,7 @@ export const bed = defineObject({
},
},
placement: 'floor',
hasCollisions: true,
createInstance: ({ options, model }) => {
const bodyMesh = model.findMesh('__X_BODY__');
const bodyMaterial = bodyMesh.material as BABYLON.PBRMaterial;

View File

@@ -40,7 +40,7 @@ export const blind = defineObject({
},
},
placement: 'bottom',
noCollisions: true,
hasCollisions: false,
createInstance: ({ options, model }) => {
const temp = createOverridedStates({
angle: () => options.angle,

View File

@@ -45,7 +45,7 @@ export const book = defineObject({
},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: ({ options, model }) => {
const bodyMesh = model.findMesh('__X_BODY__');

View File

@@ -23,7 +23,7 @@ export const books = defineObject({
},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: ({ scene, options, model }) => {
const coverMaterial = model.findMaterial('__X_COVER__');

View File

@@ -21,7 +21,7 @@ export const cactusS = defineObject({
},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: ({ options, model }) => {
const potMesh = model.findMesh('__X_POT__');
const potMaterial = potMesh.material as BABYLON.PBRMaterial;

View File

@@ -22,6 +22,7 @@ export const cardboardBox = defineObject({
},
},
placement: 'top',
hasCollisions: true,
createInstance: ({ scene, options, model }) => {
return {
onInited: () => {

View File

@@ -14,7 +14,7 @@ export const ceilingFanLight = defineObject({
default: {},
},
placement: 'ceiling',
noCollisions: true,
hasCollisions: false,
receiveShadows: false,
castShadows: false,
createInstance: ({ scene, model }) => {

View File

@@ -26,6 +26,7 @@ export const chair = defineObject({
},
},
placement: 'floor',
hasCollisions: true,
isChair: true,
createInstance: ({ model, options }) => {
const primaryMesh = model.findMesh('__X_PRIMARY__');

View File

@@ -13,7 +13,7 @@ export const coffeeCup = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -21,6 +21,7 @@ export const colorBox = defineObject({
},
},
placement: 'floor',
hasCollisions: true,
createInstance: ({ options, model }) => {
const bodyMesh = model.findMesh('__X_BODY__');
const bodyMaterial = bodyMesh.material as BABYLON.PBRMaterial;

View File

@@ -15,7 +15,7 @@ export const cupNoodle = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: ({ scene, root }) => {
let yugeDispose: (() => void) | null = null;

View File

@@ -13,7 +13,7 @@ export const custardPudding = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -42,6 +42,7 @@ export const desk = defineObject({
},
},
placement: 'floor',
hasCollisions: true,
createInstance: ({ options, model }) => {
const frameMaterial = model.findMaterial('__X_FRAME__');
const boardMaterial = model.findMaterial('__X_BOARD__');

View File

@@ -47,6 +47,7 @@ export const desktopPc = defineObject({
},
},
placement: 'top',
hasCollisions: true,
createInstance: ({ options, model, root, scene, room }) => {
const light1 = new BABYLON.SpotLight('', new BABYLON.Vector3(0, cm(10), cm(22)), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, room?.lightContainer != null);
light1.parent = root;

View File

@@ -13,7 +13,7 @@ export const djMixer = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -36,7 +36,7 @@ export const djPlayer = defineObject({
},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: async ({ model, options, scene }) => {
const screenMesh = model.findMesh('__X_SCREEN__');
const screenMaterial = model.findMaterial('__X_SCREEN__');

View File

@@ -13,7 +13,7 @@ export const ductTape = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -13,7 +13,7 @@ export const emptyBento = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -13,7 +13,7 @@ export const energyDrink = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -13,7 +13,7 @@ export const envelope = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -13,7 +13,7 @@ export const facialTissue = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -13,7 +13,7 @@ export const hangingTShirt = defineObject({
default: {},
},
placement: 'side',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -13,7 +13,7 @@ export const icosahedron = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -32,6 +32,7 @@ const base = defineObjectClass({
},
},
placement: 'floor',
hasCollisions: true,
createInstance: ({ options, model }) => {
const frameMaterial = model.findMaterial('__X_FRAME__');
const boardMaterial = model.findMaterial('__X_BOARD__');

View File

@@ -50,6 +50,7 @@ export const ironFrameTable = defineObject({
},
},
placement: 'top',
hasCollisions: true,
createInstance: ({ options, model, stickyMarkerMeshUpdated }) => {
const frameMaterial = model.findMaterial('__X_FRAME__');
const boardMaterial = model.findMaterial('__X_BOARD__');

View File

@@ -13,7 +13,7 @@ export const keyboard = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -54,7 +54,7 @@ export const laptopPc = defineObject({
},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: async ({ room, scene, options, model }) => {
const matrix = model.root.getWorldMatrix(true);
const scale = new BABYLON.Vector3();

View File

@@ -14,7 +14,7 @@ export const lavaLamp = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: ({ room, scene, root }) => {
return {
onInited: () => {

View File

@@ -13,7 +13,7 @@ export const miPlate = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -13,7 +13,7 @@ export const miPlateDisplayed = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -13,7 +13,7 @@ export const milk = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -13,7 +13,7 @@ export const mixer = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -21,7 +21,7 @@ export const monitorSpeaker = defineObject({
},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: ({ options, model }) => {
const bodyMesh = model.findMesh('__X_BODY__');
const bodyMaterial = bodyMesh.material as BABYLON.PBRMaterial;

View File

@@ -13,7 +13,7 @@ export const monstera = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -15,7 +15,7 @@ export const mug = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: ({ scene, root }) => {
let yugeDispose: (() => void) | null = null;

View File

@@ -21,7 +21,7 @@ export const newtonsCradle = defineObject({
},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: ({ options, model }) => {
const frameMaterial = model.findMaterial('__X_FRAME__');

View File

@@ -13,6 +13,7 @@ export const pachira = defineObject({
default: {},
},
placement: 'top',
hasCollisions: true,
createInstance: () => {
return {
interactions: {},

View File

@@ -26,7 +26,7 @@ export const petBottle = defineObject({
},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: ({ model, options }) => {
const capMesh = model.findMesh('__X_CAP__');
const liquidMesh = model.findMesh('__X_LIQUID__');

View File

@@ -21,6 +21,7 @@ export const piano = defineObject({
},
},
placement: 'floor',
hasCollisions: true,
createInstance: ({ options, model }) => {
const bodyMaterial = model.findMaterial('__X_BODY__');

View File

@@ -83,7 +83,7 @@ export const pictureFrame = defineObject({
},
},
placement: 'side',
noCollisions: true,
hasCollisions: false,
createInstance: async ({ scene, options, model }) => {
const frameMesh = model.findMesh('__X_FRAME__');
frameMesh.rotationQuaternion = null;

View File

@@ -13,7 +13,7 @@ export const pizza = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -13,7 +13,7 @@ export const plant = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -48,7 +48,7 @@ export const poster = defineObject({
},
},
placement: 'side',
noCollisions: true,
hasCollisions: false,
createInstance: async ({ scene, options, model }) => {
const pictureMesh = model.findMesh('__X_PICTURE__');
pictureMesh.rotationQuaternion = null;

View File

@@ -13,7 +13,7 @@ export const powerStrip = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -14,7 +14,7 @@ export const radiometer = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: ({ scene, model }) => {
const vanes = model.findTransformNode('__X_VANES__');
model.bakeExcludeMeshes = [...vanes.getChildMeshes()];

View File

@@ -42,7 +42,7 @@ export const randomBooks = defineObject({
},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: ({ options, model, scene, id }) => {
const bodyMesh = model.findMesh('__X_BODY__');
const tex = new BABYLON.Texture('/client-assets/room/objects/random-books/texture.png', scene, {

View File

@@ -13,7 +13,7 @@ export const rolledUpPoster = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -13,7 +13,7 @@ export const roundRug = defineObject({
default: {},
},
placement: 'floor',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -13,7 +13,7 @@ export const router = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -13,7 +13,7 @@ export const siphon = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -13,7 +13,7 @@ export const snakeplant = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -26,7 +26,7 @@ export const speaker = defineObject({
},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: ({ options, model }) => {
const outerMesh = model.findMesh('__X_COVER__');
const outerMaterial = outerMesh.material as BABYLON.PBRMaterial;

View File

@@ -13,7 +13,7 @@ export const sprayer = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -13,6 +13,7 @@ export const steelRack = defineObject({
default: {},
},
placement: 'floor',
hasCollisions: true,
createInstance: () => {
return {
interactions: {},

View File

@@ -13,7 +13,7 @@ export const tabletopCalendar = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -33,7 +33,7 @@ export const tabletopDigitalClock = defineObject({
},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: ({ root, room, options, model, scene }) => {
const light = new BABYLON.SpotLight('', new BABYLON.Vector3(0, cm(3), cm(1)), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, room?.lightContainer != null);
light.parent = root;

View File

@@ -28,7 +28,7 @@ export const tabletopFlag = defineObject({
},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: async ({ model, options, scene }) => {
const flagMesh = model.findMesh('__X_FLAG__');
const flagMaterial = model.findMaterial('__X_FLAG__');

View File

@@ -48,7 +48,7 @@ export const tabletopGlassPictureFrame = defineObject({
},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: async ({ scene, options, model }) => {
const pictureMesh = model.findMesh('__X_PICTURE__');
const frameMesh = model.findMesh('__X_FRAME__');

View File

@@ -50,7 +50,7 @@ export const tabletopIronFrameStand = defineObject({
},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: ({ options, model }) => {
const frameMaterial = model.findMaterial('__X_FRAME__');
const boardMaterial = model.findMaterial('__X_BOARD__');

View File

@@ -83,7 +83,7 @@ export const tabletopPictureFrame = defineObject({
},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: async ({ scene, options, model }) => {
const frameMesh = model.findMesh('__X_FRAME__');
frameMesh.rotationQuaternion = null;

View File

@@ -48,7 +48,7 @@ export const tapestry = defineObject({
},
},
placement: 'side',
noCollisions: true,
hasCollisions: false,
createInstance: async ({ scene, options, model }) => {
const pictureMesh = model.findMesh('__X_PICTURE__');
pictureMesh.rotationQuaternion = null;

View File

@@ -13,7 +13,7 @@ export const tetrapod = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -30,6 +30,7 @@ export const tv = defineObject({
},
},
placement: 'top',
hasCollisions: true,
createInstance: ({ options, room, model, scene }) => {
const matrix = model.root.getWorldMatrix(true);
const scale = new BABYLON.Vector3();

View File

@@ -13,7 +13,7 @@ export const twistedCubeObjet = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -13,7 +13,7 @@ export const usedTissue = defineObject({
default: {},
},
placement: 'top',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},

View File

@@ -44,7 +44,7 @@ export const wallCanvas = defineObject({
},
},
placement: 'side',
noCollisions: true,
hasCollisions: false,
createInstance: async ({ scene, options, model }) => {
const canvasMesh = model.findMesh('__X_CANVAS__');
canvasMesh.rotationQuaternion = null;

View File

@@ -21,7 +21,7 @@ export const wallClock = defineObject({
},
},
placement: 'side',
noCollisions: true,
hasCollisions: false,
createInstance: ({ room, root, options, model }) => {
const hourHand = model.findMesh('HandH');
const minuteHand = model.findMesh('HandM');

View File

@@ -48,7 +48,7 @@ export const wallGlassPictureFrame = defineObject({
},
},
placement: 'wall',
noCollisions: true,
hasCollisions: false,
createInstance: async ({ scene, options, model }) => {
const pictureMesh = model.findMesh('__X_PICTURE__');
const frameMesh = model.findMesh('__X_FRAME__');

View File

@@ -45,7 +45,7 @@ export const wallMirror = defineObject({
},
},
placement: 'side',
noCollisions: true,
hasCollisions: false,
createInstance: async ({ options, model }) => {
const frameMaterial = model.findMaterial('__X_FRAME__');
const frameMesh = model.findMesh('__X_FRAME__');

View File

@@ -40,6 +40,7 @@ export const woodRingFloorLamp = defineObject({
},
},
placement: 'floor',
hasCollisions: true,
createInstance: ({ room, scene, options, model }) => {
const shadeMaterial = model.findMaterial('__X_SHADE__');

View File

@@ -52,7 +52,7 @@ export const woodRingsPendantLight = defineObject({
},
},
placement: 'ceiling',
noCollisions: true,
hasCollisions: false,
createInstance: ({ room, scene, options, model }) => {
const shadeMaterial = model.findMaterial('__X_SHADE__');

View File

@@ -13,7 +13,7 @@ export const woodSoundAbsorbingPanel = defineObject({
default: {},
},
placement: 'side',
noCollisions: true,
hasCollisions: false,
createInstance: () => {
return {
interactions: {},