Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 19 additions & 31 deletions type_templates/glb.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@ export default e => {
const localPlayer = useLocalPlayer();

const srcUrl = ${this.srcUrl};

for (const {key, value} of components) {
app.setComponent(key, value);
}


// * true by default
let appHasPhysics = true;
const hasPhysicsComponent = app.hasComponent('physics');
if (hasPhysicsComponent) {
const physicsComponent = app.getComponent('physics');
appHasPhysics = physicsComponent;
}

app.glb = null;
const animationMixers = [];
const uvScrolls = [];
Expand Down Expand Up @@ -192,37 +201,16 @@ export default e => {
app.add(o);
o.updateMatrixWorld();

const _addPhysics = async physicsComponent => {
let physicsId;
switch (physicsComponent.type) {
case 'triangleMesh': {
physicsId = physics.addGeometry(o);
break;
}
case 'convexMesh': {
physicsId = physics.addConvexGeometry(o);
break;
}
default: {
physicsId = null;
break;
}
}
if (physicsId !== null) {
physicsIds.push(physicsId);
} else {
console.warn('glb unknown physics component', physicsComponent);
}
// * Physics
const _addPhysics = async () => {
const physicsId = physics.addGeometry(o);
physicsIds.push(physicsId);
};
let physicsComponent = app.getComponent('physics');
if (physicsComponent) {
if (physicsComponent === true) {
physicsComponent = {
type: 'triangleMesh',
};
}
_addPhysics(physicsComponent);

if (appHasPhysics) {
_addPhysics();
}

o.traverse(o => {
if (o.isMesh) {
o.frustumCulled = false;
Expand Down Expand Up @@ -325,4 +313,4 @@ export const contentId = ${this.contentId};
export const name = ${this.name};
export const description = ${this.description};
export const type = 'glb';
export const components = ${this.components};
export const components = ${this.components};