Skip to content

Commit 05d85fc

Browse files
committed
ensure mounted when setting dirty to prevent false activate
1 parent 1b56828 commit 05d85fc

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

packages/website/verse/Object.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ export class Object extends Entity {
4848
this.quaternion = this.createNetworkProp('quaternion', new Quaternion().fromArray(props.quaternion || defaultQuaternion)) // prettier-ignore
4949
// this.quaternion.onChange = this.onQuaternionChange.bind(this)
5050

51-
this.root = new Nodes.group({
52-
id: '$root',
53-
})
51+
this.root = new Nodes.group({ id: '$root' })
5452
this.root.position.copy(this.position.value)
5553
this.root.quaternion.copy(this.quaternion.value)
5654

@@ -477,8 +475,8 @@ export class Object extends Entity {
477475
if (!node) return null
478476
return node.getProxy()
479477
},
480-
create(data) {
481-
const node = entity.createNode(data)
478+
create(type) {
479+
const node = entity.createNode({ type })
482480
return node.getProxy()
483481
},
484482
isAuthority() {
@@ -801,9 +799,7 @@ export class Object extends Entity {
801799
super.destroy()
802800
this.world.entities.setHot(this, false)
803801
this.nodes.forEach(node => {
804-
if (node.mounted) {
805-
node.unmount()
806-
}
802+
node.deactivate()
807803
})
808804
this.control?.release(false)
809805
this.control = null

packages/website/verse/extras/createColliderFactory.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ export function createColliderFactory(world, mesh) {
9191
actor = world.physics.physics.createRigidDynamic(transform)
9292
actor.setRigidBodyFlag(PHYSX.PxRigidBodyFlagEnum.eKINEMATIC, true)
9393
actor.setRigidBodyFlag(PHYSX.PxRigidBodyFlagEnum.eENABLE_CCD, false)
94-
} else {
94+
} else if (collision === 'static') {
9595
actor = world.physics.physics.createRigidStatic(transform)
9696
}
9797
actor.attachShape(shape)
9898
world.physics.scene.addActor(actor)
9999

100100
let untrack
101-
if (collision !== 'static') {
101+
if (collision === 'dynamic') {
102102
untrack = world.physics.track(actor, node?.onPhysicsMovement)
103103
}
104104

packages/website/verse/nodes/Box.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ export class Box extends Node {
131131
this.actor = this.ctx.world.physics.physics.createRigidDynamic(this.transform)
132132
this.actor.setRigidBodyFlag(PHYSX.PxRigidBodyFlagEnum.eKINEMATIC, true)
133133
this.actor.setRigidBodyFlag(PHYSX.PxRigidBodyFlagEnum.eENABLE_CCD, false)
134-
} else {
134+
} else if (this.collision === 'static') {
135135
this.actor = this.ctx.world.physics.physics.createRigidStatic(this.transform)
136136
}
137137
// this.actor.setMass(1)
138138
this.actor.attachShape(shape)
139139
this.ctx.world.physics.scene.addActor(this.actor)
140-
if (this.collision !== 'static') {
140+
if (this.collision === 'dynamic') {
141141
this.untrack = this.ctx.world.physics.track(this.actor, this.onPhysicsMovement)
142142
}
143143
}

packages/website/verse/nodes/Mesh.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { isBoolean } from 'lodash-es'
22

33
import { Node } from './Node'
44

5+
const collisionTypes = ['static', 'kinematic', 'dynamic']
6+
57
const defaults = {
68
visible: true,
79
collision: null,
@@ -17,7 +19,13 @@ export class Mesh extends Node {
1719
this.model = data.model
1820

1921
this.visible = isBoolean(data.visible) ? data.visible : defaults.visible
20-
this.collision = data.collision || defaults.collision
22+
23+
// todo: we should validate all options because the old collision=true does weird shit now
24+
// its best to only set if valid
25+
this.collision = defaults.collision
26+
if (collisionTypes.includes(data.collision)) {
27+
this.collision = data.collision
28+
}
2129
this.collisionLayer = data.collisionLayer || defaults.collisionLayer
2230

2331
this.mesh = null

packages/website/verse/nodes/Node.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ export class Node {
131131
}
132132

133133
setDirty() {
134+
// if we haven't mounted no track
135+
if (!this.mounted) return
134136
// if already dirty, either this or a parent is being tracked so we're good
135137
if (this.isDirty) return
136138
this.isDirty = true

0 commit comments

Comments
 (0)