Skip to content

Commit

Permalink
feat(troika-core): add requestRender method as nicer shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
lojjic committed Feb 14, 2021
1 parent d995a4d commit c79254c
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/troika-3d-text/src/facade/Text3DFacade.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Text3DFacade extends Object3DFacade {
mesh.geometry.boundingSphere.version++
this.afterUpdate()
this.notifyWorld('text3DSyncComplete')
this.notifyWorld('needsRender')
this.requestRender()
if (this.onSyncComplete) {
this.onSyncComplete()
}
Expand Down Expand Up @@ -112,7 +112,7 @@ class Text3DFacade extends Object3DFacade {
this.selectionStart = start
this.selectionEnd = end
this._updateSelection()
this.notifyWorld('needsRender')
this.requestRender()
})
} else {
if (selFacade) {
Expand Down
4 changes: 2 additions & 2 deletions packages/troika-3d-ui/src/facade/UIBlock3DFacade.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ function wheelHandler(e) {
facade.scrollLeft = scrollLeft
facade.scrollTop = scrollTop
facade.afterUpdate()
facade.notifyWorld('needsRender')
facade.requestRender()
e._didScroll = true
}
e.preventDefault()
Expand Down Expand Up @@ -446,7 +446,7 @@ function dragHandler(e) {
facade.scrollLeft = scrollLeft
facade.scrollTop = scrollTop
facade.afterUpdate()
facade.notifyWorld('needsRender')
facade.requestRender()
e._didScroll = true
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/troika-3d-ui/src/facade/UIImage3DFacade.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class UIImage3DFacade extends Object3DFacade {
material.map = texture
this.aspectRatio = texture.image.width / texture.image.height
this.afterUpdate()
this.notifyWorld('needsRender')
this.requestRender()
})
this._lastSrc = src
}
Expand Down
2 changes: 1 addition & 1 deletion packages/troika-3d-ui/src/flex-layout/FlexNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export const extendAsFlexNode = createClassExtender('flexNode', BaseFacadeClass
// Final afterUpdate on the whole subtree
this._hasActiveFlexRequest = false
this.afterUpdate()
this.notifyWorld('needsRender')
this.requestRender()
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/troika-3d/src/facade/WorldTextureProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function makeWorldTextureProvider(WrappedFacadeClass) {
// Trigger texture update whenever the inner world is rerendered
innerWorld.onAfterRender = () => {
this.worldTexture.needsUpdate = true
this.notifyWorld('needsRender')
this.requestRender()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/troika-core/src/facade/Animatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const extendAsAnimatable = createClassExtender('animatable', function(Bas
this.animation$runner = new Runner()
this.animation$runner.onTick = () => {
this.afterUpdate()
this.notifyWorld('needsRender')
this.requestRender()
}
}

Expand Down Expand Up @@ -297,7 +297,7 @@ export const extendAsAnimatable = createClassExtender('animatable', function(Bas
}
}
runner.onDone = () => {
this.notifyWorld('needsRender')
this.requestRender()
this.destructor()
}
} else {
Expand Down
10 changes: 9 additions & 1 deletion packages/troika-core/src/facade/Facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class Facade {
if (props && typeof props === 'object') {
assign(this, props)
this.afterUpdate()
this.notifyWorld('needsRender')
this.requestRender()
}
}

Expand Down Expand Up @@ -132,6 +132,14 @@ export default class Facade {
}
}

/**
* Notifies the top-level world manager that this object has changed in some way that affects its
* visible rendering, so a rendering frame will be scheduled.
*/
requestRender() {
this.notifyWorld('needsRender')
}

traverse(fn) {
fn(this)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/troika-core/src/facade/PointerStates.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const extendAsPointerStatesAware = createClassExtender('pointerStates', f
parent = parent.parent
}
highestFacade.afterUpdate()
highestFacade.notifyWorld('needsRender')
highestFacade.requestRender()
}

return PointerStatesAware
Expand Down
2 changes: 1 addition & 1 deletion packages/troika-xr/src/facade/teleport/TeleportControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class TeleportControls extends Object3DFacade {
this.targeting = true
markerConfig.x = tempVec3.x
markerConfig.z = tempVec3.z
this.notifyWorld('needsRender')
this.requestRender()
// For rotation, start with the current direction of the camera. Then rotate
// relative to that by the last controller stick/axis position.
tempQuat.setFromRotationMatrix(this.getCameraFacade().threeObject.matrixWorld)
Expand Down

0 comments on commit c79254c

Please sign in to comment.