ecojust
November 23, 2021, 10:15am
1
i create too much point by thinInstance;
and then
scene.onPointerDown = function (evt, pickResult) {
if (pickResult.hit && ~pickResult.thinInstanceIndex) {
console.log('onPointerDown---------------')
const worldMat = instance.thinInstanceGetWorldMatrices()
const thinInstanceMatrix = worldMat[pickResult.thinInstanceIndex]
callback && callback(pickResult.thinInstanceIndex, thinInstanceMatrix)
}
}
but i found that,when i use mouse hover them,not click them;
some computation function is running , because the fps number going down really fast;
when the mouse stay away from them , fps number back to normal;
so,i wonder whether mouse movement detection can be removed for this, and onPointerDown events are not affected
thanks for your answer !
sebavan
November 23, 2021, 10:17am
2
Could you share a repro in the playground ? so it might help us find the best config ?
1 Like
ecojust
November 24, 2021, 2:07am
3
https://playground.babylonjs.com/#RC2IAH
I wrote my code according to this case,I can’t copy all the configuration for my project (it is too long and it is too hard to write on PG),but I can provide the code of create instance:
createInstance(instance: BABYLON.Mesh, matricesData: Float32Array, isPickable: boolean, callback?: Function) {
instance.thinInstanceSetBuffer('matrix', matricesData, 16, false)
instance.isPickable = isPickable
instance.thinInstanceEnablePicking = isPickable
if (isPickable) {
BabylonService.getScene().onPointerDown = function (evt, pickResult) {
if (pickResult.hit && ~pickResult.thinInstanceIndex) {
console.log('onPointerDown---------------')
const worldMat = instance.thinInstanceGetWorldMatrices()
const thinInstanceMatrix = worldMat[pickResult.thinInstanceIndex]
callback && callback(pickResult.thinInstanceIndex, thinInstanceMatrix)
}
}
}
}
em…maybe i find the reason…
ecojust
November 24, 2021, 2:10am
4
ball.actionManager.registerAction(
new BABYLON.ExecuteCodeAction(
{
trigger: BABYLON.ActionManager.OnPickTrigger,
},
(e: BABYLON.ActionEvent) => {
if (this.pickable) {
BabylonEvent.triggerEvent({
action: 'clickThePoint',
mesh: ball,
})
}
}
)
)
Maybe I wrote the if statement in the wrong place
finally,I replaced the above code,it is useful,and this problem has also been solved
public setPickable(bool: boolean) {
if (bool) {
this.ball.actionManager = new BABYLON.ActionManager(this.scene)
this.ball.actionManager.registerAction(
new BABYLON.ExecuteCodeAction(
{
trigger: BABYLON.ActionManager.OnPickTrigger,
},
(e: BABYLON.ActionEvent) => {
BabylonEvent.triggerEvent({
action: 'clickThePoint',
mesh: this.getBall,
})
}
)
)
}
}
thanks
1 Like