refactoring meshUtils, added sceneScale, #74
This commit is contained in:
@@ -22,7 +22,6 @@
|
||||
|
||||
<script>
|
||||
import { GameEngine } from '@/lib/GameEngine.js';
|
||||
import { autoScale } from '@/lib/MeshUtils';
|
||||
let engine = null;
|
||||
|
||||
export default{
|
||||
@@ -81,7 +80,7 @@ export default{
|
||||
this.animations = gltf.animations.map(a => ({
|
||||
name: a.name, id: a.uuid
|
||||
}));
|
||||
autoScale(gltf.scene);
|
||||
engine.meshUtils.autoScale(gltf.scene);
|
||||
let bb = new engine.$.Box3().setFromObject(gltf.scene);
|
||||
engine.camera.position.set(bb.max.x, bb.max.y, bb.max.z*3);
|
||||
engine.orbitControls.target.set((bb.max.x + bb.min.x) / 2, (bb.max.y + bb.min.y) / 2, (bb.max.z + bb.min.z) / 2)
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { bottomOrigin } from "@/lib/MeshUtils";
|
||||
class CharacterObject{
|
||||
constructor(engine, data){
|
||||
return new Promise(async(resolve, reject)=>{
|
||||
this.source = await engine.load(data.$go.asset.name);
|
||||
this.object = bottomOrigin(this.source.scene);
|
||||
this.object = engine.meshUtils.bottomOrigin(this.source.scene);
|
||||
resolve(this);
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Color, Group, DoubleSide, RepeatWrapping, MeshStandardMaterial, VideoTexture } from "three"
|
||||
import { EventManager } from '@/lib/EventManager';
|
||||
import { centerOrigin, clearMaterial, clearObject } from "@/lib/MeshUtils";
|
||||
import Utils from "#/app/Utils";
|
||||
|
||||
class ClassicPuzzle extends EventManager {
|
||||
@@ -100,11 +99,11 @@ class ClassicPuzzle extends EventManager {
|
||||
done0.position.set(0,0,0);
|
||||
engine.draggable.remove(done0)
|
||||
container.add(dragZone);
|
||||
this.object = centerOrigin(container);
|
||||
this.object = engine.meshUtils.centerOrigin(container);
|
||||
this.dispose = () => {
|
||||
//console.log('disposing!!!!!!!')
|
||||
clearMaterial(defaultMaterial);
|
||||
clearObject(gltf.scene);
|
||||
engine.meshUtils.clearMaterial(defaultMaterial);
|
||||
engine.meshUtils.clearObject(gltf.scene);
|
||||
super.dispose();
|
||||
}
|
||||
resolve(this);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { getBoundingBox, getBoundingBoxCenterPoint, getBoundingBoxMaxLength, centerOrigin } from "@/lib/MeshUtils";
|
||||
import { EventManager } from '@/lib/EventManager';
|
||||
|
||||
class GenericObject extends EventManager{
|
||||
@@ -7,7 +6,7 @@ class GenericObject extends EventManager{
|
||||
super();
|
||||
return new Promise(async(resolve, reject)=>{
|
||||
this.source = await engine.load(data.$go.asset.name);
|
||||
this.object = centerOrigin(this.source.scene)
|
||||
this.object = engine.meshUtils.bottomOrigin(this.source.scene)
|
||||
|
||||
if (!data.exclude){
|
||||
engine.clickable.add(this.object, async e=>{
|
||||
@@ -17,9 +16,9 @@ class GenericObject extends EventManager{
|
||||
if (this.object._hud ){
|
||||
engine.dashboard.detach(this.object);
|
||||
}else{
|
||||
let bb = getBoundingBox(this.object);
|
||||
let scale = 0.5 * engine.dashboard.height/getBoundingBoxMaxLength(bb);
|
||||
let position = getBoundingBoxCenterPoint(bb, this.object.position).multiplyScalar(scale).negate()
|
||||
let bb = engine.meshUtils.getBoundingBox(this.object);
|
||||
let scale = 0.5 * engine.dashboard.height/engine.meshUtils.getBoundingBoxMaxLength(bb);
|
||||
let position = engine.meshUtils.getBoundingBoxCenterPoint(bb, this.object.position).multiplyScalar(scale).negate()
|
||||
|
||||
let placement = {
|
||||
quaternion: { x:0, y:0, z:0, w:0 },
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Vector3, AnimationMixer } from "three";
|
||||
import { assignMaterial } from "@/lib/MeshUtils";
|
||||
import { AnimationMixer } from "three";
|
||||
|
||||
class GltfObject {
|
||||
constructor(engine, obj) {
|
||||
@@ -13,7 +12,7 @@ class GltfObject {
|
||||
}
|
||||
});
|
||||
|
||||
assignMaterial(gltfObj, obj);
|
||||
engine.meshUtils.assignMaterial(gltfObj, obj);
|
||||
if (gltf.animations && gltf.animations.length) {
|
||||
let mixer = new AnimationMixer(gltfObj);
|
||||
engine.mixers.push(mixer);
|
||||
|
||||
@@ -19,7 +19,6 @@ import { SingleQuestion } from "./SingleQuestion";
|
||||
import { MazeQuizGame } from "./MazeQuizGame/MazeQuizGame";
|
||||
import { Particles } from "./Particles";
|
||||
import { SceneSwitcher } from "./SceneSwitcher";
|
||||
import { assignParams, wrapInGroup, getBoundingBoxMaxLength } from "@/lib/MeshUtils";
|
||||
import { GameEngine } from "@/lib/GameEngine";
|
||||
|
||||
const InteractiveObjectsImports = {
|
||||
@@ -79,11 +78,11 @@ class InteractiveObject extends EventManager{
|
||||
break;
|
||||
}
|
||||
if (obj.shouldBeLocked){
|
||||
this.object = wrapInGroup(this.object)
|
||||
this.object = engine.meshUtils.wrapInGroup(this.object)
|
||||
this.activator = new (obj.activationType == 'unlock' ? LockActivator : VisibilityActivator)(engine, this.object);
|
||||
this.activator.deactivate();
|
||||
}
|
||||
assignParams(this.object, obj);
|
||||
engine.meshUtils.assignParams(this.object, obj);
|
||||
if (obj.motion){
|
||||
engine.motionQueue.add({
|
||||
o: this.object, ...obj.motion
|
||||
@@ -124,7 +123,7 @@ class LockActivator{
|
||||
transparent: true, opacity:1, color: 0xaaaaaa
|
||||
})
|
||||
constructor(engine, group){
|
||||
const bckGeometry = new SphereGeometry(getBoundingBoxMaxLength(group.userData.bbox)/2,8,8)
|
||||
const bckGeometry = new SphereGeometry(engine.meshUtils.getBoundingBoxMaxLength(group.userData.bbox)/2,8,8)
|
||||
const bckMesh = new Mesh(bckGeometry, LockActivator.materialLocked);
|
||||
bckMesh.visible = false;
|
||||
group.add(bckMesh)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Group, Vector3, Matrix4, Quaternion, RepeatWrapping, Vector2} from 'three';
|
||||
import { InteractiveObject } from '../InteractiveObject';
|
||||
import { getBoundingBox, getBoundingBoxSize } from '@/lib/MeshUtils';
|
||||
|
||||
class MazeObject {
|
||||
constructor(engine, def, params){
|
||||
@@ -157,8 +156,8 @@ class MazeObject {
|
||||
o[e] = mazeAsset.scene.getObjectByName(e);
|
||||
if (o[e]){
|
||||
o[e].scale.setScalar(scale);
|
||||
let bb = getBoundingBox(o[e]);
|
||||
o[e].userData.size = getBoundingBoxSize(bb);
|
||||
let bb = engine.meshUtils.getBoundingBox(o[e]);
|
||||
o[e].userData.size = engine.meshUtils.getBoundingBoxSize(bb);
|
||||
}
|
||||
});
|
||||
this.mazeObject(def, room);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { BoxGeometry, Mesh, MeshStandardMaterial, Group, Vector3, CatmullRomCurve3, Color } from 'three';
|
||||
import { BoxGeometry, Mesh, MeshStandardMaterial, Group, Vector3, CatmullRomCurve3} from 'three';
|
||||
import { LineMaterial, LineGeometry, Line2 } from 'three/examples/jsm/Addons.js';
|
||||
import { centerOrigin, clearMaterial } from '@/lib/MeshUtils';
|
||||
import { EventManager } from '@/lib/EventManager';
|
||||
import Utils from '#/app/Utils';
|
||||
|
||||
@@ -109,10 +108,10 @@ class PairMatchingGame extends EventManager {
|
||||
|
||||
};
|
||||
|
||||
this.object = centerOrigin(container);
|
||||
this.object = engine.meshUtils.centerOrigin(container);
|
||||
|
||||
this.dispose = () => {
|
||||
clearMaterial(material);
|
||||
engine.meshUtils.clearMaterial(material);
|
||||
bm.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { BoxGeometry, Mesh, MeshBasicMaterial, Group, VideoTexture } from 'three';
|
||||
import { centerOrigin, clearMaterial } from '@/lib/MeshUtils';
|
||||
import { EventManager } from '@/lib/EventManager';
|
||||
|
||||
class PuzzleGame1 extends EventManager {
|
||||
@@ -123,11 +122,11 @@ class PuzzleGame1 extends EventManager {
|
||||
|
||||
engine.addEventListener('beforeRender', this.update)
|
||||
|
||||
this.object = centerOrigin(container);
|
||||
this.object = engine.meshUtils.centerOrigin(container);
|
||||
|
||||
this.dispose = () => {
|
||||
//console.log('disposing PG1')
|
||||
clearMaterial(material);
|
||||
engine.meshUtils.clearMaterial(material);
|
||||
bm.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { BoxGeometry, Mesh, MeshBasicMaterial, Group, VideoTexture } from 'three';
|
||||
import { centerOrigin } from '@/lib/MeshUtils';
|
||||
import { EventManager } from '@/lib/EventManager';
|
||||
|
||||
class PuzzleGame2 extends EventManager {
|
||||
@@ -166,7 +165,7 @@ class PuzzleGame2 extends EventManager {
|
||||
};
|
||||
engine.addEventListener('beforeRender', this.update)
|
||||
|
||||
this.object = centerOrigin(container)
|
||||
this.object = engine.meshUtils.centerOrigin(container)
|
||||
resolve(this)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Group, Color } from 'three';
|
||||
import { centerOrigin } from '@/lib/MeshUtils';
|
||||
import { EventManager } from '@/lib/EventManager';
|
||||
import { TextObject } from './TextObject';
|
||||
import Utils from '#/app/Utils';
|
||||
@@ -38,7 +37,7 @@ class SingleQuestion extends EventManager {
|
||||
}
|
||||
container.add(question.object);
|
||||
container.add(answers);
|
||||
this.object = centerOrigin(container);
|
||||
this.object = engine.meshUtils.centerOrigin(container);
|
||||
resolve(this);
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { MeshBasicMaterial, Color, DoubleSide } from "three";
|
||||
import { Text } from "troika-three-text";
|
||||
import { assignParams } from "@/lib/MeshUtils";
|
||||
|
||||
class TextObject {
|
||||
constructor(engine, obj) {
|
||||
@@ -21,7 +20,7 @@ class TextObject {
|
||||
txt.depthOffset = 0.1;
|
||||
//txt.outlineBlur = '50%';
|
||||
txt.color = new Color(0x0);
|
||||
assignParams(txt, obj)
|
||||
engine.meshUtils.assignParams(txt, obj)
|
||||
let m = new MeshBasicMaterial({
|
||||
// roughness: .73,
|
||||
// metalness: .37,
|
||||
|
||||
Reference in New Issue
Block a user