interactive objects integration
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { Group, Vector3, Matrix4, Mesh, Quaternion, PlaneGeometry, MeshStandardMaterial, DoubleSide, CanvasTexture, SRGBColorSpace } from 'three';
|
||||
import { Group, Vector3, Matrix4, Mesh, Quaternion, PlaneGeometry, MeshStandardMaterial, DoubleSide} from 'three';
|
||||
import { InteractiveObject } from '../InteractiveObject';
|
||||
import Utils from '@/lib/Utils';
|
||||
|
||||
class MazeObject {
|
||||
constructor(engine, def, params = {}){
|
||||
@@ -39,7 +38,7 @@ class MazeObject {
|
||||
if (typeof size == 'number'){
|
||||
size = { width: 0.1, height:1, depth:size/2 }
|
||||
}
|
||||
let po = engine.phy.add(
|
||||
let po = engine.physics.add(
|
||||
{position: v}, 'fixed', false, undefined, 'cuboid',
|
||||
{ ...size, isSensor, userData }
|
||||
)
|
||||
@@ -51,13 +50,6 @@ class MazeObject {
|
||||
}
|
||||
|
||||
function addRoom(elements, def, offsetZ){
|
||||
// e = [
|
||||
// o.floor.clone(),
|
||||
// o.door.clone(),
|
||||
// o[def.r ? 'door' : 'wall'].clone(),
|
||||
// o[def.f ? 'door' : 'wall'].clone(),
|
||||
// o[def.l ? 'door' : 'wall'].clone()
|
||||
// ];
|
||||
|
||||
let e = elements.map(e=>o[e].clone())
|
||||
|
||||
@@ -106,9 +98,6 @@ class MazeObject {
|
||||
let offsetZ = 0, e;
|
||||
def.len = def.len || 0;
|
||||
if (step == 0) {
|
||||
// e = o.door.clone();
|
||||
// e.rotateY(_tf.rotation.f);
|
||||
// mazeMeshes.push(e);
|
||||
addRoom(['floor', 'wall', 'wall', 'door', 'wall'], def, -context.wallSize)
|
||||
}
|
||||
if (def.userData?.answer !== undefined){
|
||||
@@ -121,15 +110,6 @@ class MazeObject {
|
||||
root.add(t);
|
||||
}
|
||||
offsetZ = def.len * context.tubeSize;
|
||||
//if (!def.len) offsetZ = -.275;
|
||||
//room.getWorldQuaternion(quat);
|
||||
// const geometry = new BoxGeometry(2, 2, offsetZ);
|
||||
// const cube = new Mesh(geometry, o.tunnel.material)
|
||||
// cube.position.set(context.tubeSize / 2, 0.6, offsetZ/2)
|
||||
// root.add(cube);
|
||||
|
||||
// console.log(offsetZ, room.localToWorld(new Vector3(context.tubeSize / 2, 0.6, offsetZ/2)))
|
||||
|
||||
addPhysics(def.matrix, [context.tubeSize / 2, 0.6, offsetZ/2], offsetZ)
|
||||
addPhysics(def.matrix, [-context.tubeSize / 2, 0.6, offsetZ/2], offsetZ)
|
||||
|
||||
@@ -140,16 +120,12 @@ class MazeObject {
|
||||
//console.log('loadingggg', def.objects)
|
||||
def.objects?.forEach(async obj => {
|
||||
obj.room = room;
|
||||
// let go = new GameObject(obj, context);
|
||||
let go = new InteractiveObject(obj, context)
|
||||
let go = new InteractiveObject(obj, engine, context)
|
||||
await go.ready;
|
||||
go.object.scale.multiplyScalar(context.wallSize)
|
||||
go.object.position.multiplyScalar(context.wallSize)
|
||||
go.object.applyMatrix4(def.matrix);
|
||||
root.add(go.object);
|
||||
// go.ready.then(mesh => {
|
||||
// room.add(mesh);
|
||||
// });
|
||||
});
|
||||
|
||||
def.room = room;
|
||||
@@ -173,17 +149,8 @@ class MazeObject {
|
||||
o[e] = mazeAsset.scene.getObjectByName(e);
|
||||
//o[e].frustumCulled = false;
|
||||
o[e].scale.set(scale, scale, scale)
|
||||
// o[e].geometry.computeBoundingBox();
|
||||
// console.log(e, o[e].geometry.boundingBox)
|
||||
});
|
||||
this.mazeObject(def, room);
|
||||
// mazeMeshes.forEach(mesh=>{
|
||||
// //let mesh = new Mesh(mg, o.tunnel.material)
|
||||
// root.add(mesh);
|
||||
// //engine.phy.add(mesh, 'fixed')
|
||||
// })
|
||||
|
||||
//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
|
||||
@@ -191,8 +158,6 @@ class MazeObject {
|
||||
floor.rotation.set(Math.PI/2, 0, 0)
|
||||
floor.position.set((bbox.l + bbox.r)/2, 0.3, bbox.f/2);
|
||||
root.add(floor);
|
||||
//scene.add(new Mesh(BufferGeometryUtils.mergeGeometries(mazeGeometries, false), o.tunnel.material));
|
||||
//console.log(room);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user