finish events
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Group, Vector3, Matrix4, Mesh, Quaternion, PlaneGeometry, MeshStandardMaterial, DoubleSide } from 'three';
|
||||
import { InteractiveObject } from '../InteractiveObject';
|
||||
import { ActiveEvents } from '@dimforge/rapier3d';
|
||||
|
||||
class MazeObject {
|
||||
constructor(engine, def, params = {}){
|
||||
@@ -32,16 +33,21 @@ class MazeObject {
|
||||
|
||||
let o = {};
|
||||
|
||||
function addPhysics(matrix, position, size, placement = 'side'){
|
||||
function addPhysics(matrix, position, size, placement = 'side', isSensor = false, userData){
|
||||
let quat = new Quaternion().setFromRotationMatrix(matrix);
|
||||
let v = new Vector3(...position).applyMatrix4(matrix);
|
||||
if (typeof size == 'number'){
|
||||
size = { width: 0.1, height:1, depth:size/2 }
|
||||
}
|
||||
let po = engine.phy.add(
|
||||
{position: v}, 'fixed', false, undefined, 'cuboid',{ width: 0.01, height:1, depth:size/2 }
|
||||
{position: v}, 'fixed', false, undefined, 'cuboid',
|
||||
{ ...size, isSensor, userData }
|
||||
)
|
||||
if (placement == 'front') {
|
||||
quat.multiply(new Quaternion(0, 0.7071068, 0, 0.7071068)) //rotate by 90deg
|
||||
}
|
||||
po.rigidBody.setRotation(quat, true)
|
||||
return po;
|
||||
}
|
||||
|
||||
function addRoom(elements, def, offsetZ){
|
||||
@@ -105,6 +111,9 @@ class MazeObject {
|
||||
// mazeMeshes.push(e);
|
||||
addRoom(['floor', 'wall', 'wall', 'door', 'wall'], def, -context.wallSize)
|
||||
}
|
||||
if (def.userData?.answer !== undefined){
|
||||
addPhysics(def.matrix, [0,0,0], context.wallSize, 'front', true, def.userData)
|
||||
}
|
||||
for (let i = 0; i < def.len; i++) {
|
||||
let t = o.tunnel.clone();
|
||||
t.position.set(0, 0, i * context.tubeSize);
|
||||
@@ -125,8 +134,10 @@ class MazeObject {
|
||||
addPhysics(def.matrix, [-context.tubeSize / 2, 0.6, offsetZ/2], offsetZ)
|
||||
|
||||
addRoom(['floor', 'door', def.r ? 'door' : 'wall', def.f ? 'door' : 'wall', def.l ? 'door' : 'wall'], def, offsetZ)
|
||||
|
||||
console.log('loadingggg', def.objects)
|
||||
if (def.userData?.qid !== undefined || def.userData?.finish){
|
||||
addPhysics(def.matrix, [0,0,offsetZ + context.wallSize/2], { width: context.wallSize/2, height: context.wallSize/2, depth: context.wallSize/2}, 'side', true, def.userData)
|
||||
}
|
||||
//console.log('loadingggg', def.objects)
|
||||
def.objects?.forEach(async obj => {
|
||||
obj.room = room;
|
||||
// let go = new GameObject(obj, context);
|
||||
@@ -172,7 +183,7 @@ class MazeObject {
|
||||
// //engine.phy.add(mesh, 'fixed')
|
||||
// })
|
||||
|
||||
console.log(bbox, 'bbox')
|
||||
//console.log(bbox, 'bbox')
|
||||
const floorGeometry = new PlaneGeometry(bbox.r - bbox.l + 10*scale, bbox.f + 10*scale);
|
||||
const floor = new Mesh(floorGeometry,new MeshStandardMaterial({
|
||||
roughness: 0, metalness:1, color: 0x00ffff, side: DoubleSide
|
||||
|
||||
Reference in New Issue
Block a user