Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Picking objects not work with param includeEntities #1526

Closed
g-rodigy opened this issue Jun 10, 2024 · 4 comments
Closed

Picking objects not work with param includeEntities #1526

g-rodigy opened this issue Jun 10, 2024 · 4 comments

Comments

@g-rodigy
Copy link
Contributor

Describe the bug
When picking objects with param includeEntities it not return PickResult wich must be.
Got console message:

[WARN] [Scene 1]: pick(): Component not found: 0jf0rYHfX3RAB3bSIRjmr1

To Reproduce

const xktLoader = new XKTLoaderPlugin(viewer);

const sceneModel = xktLoader.load({
    id: "myModel",
    src: "./xeokit-sdk/assets/models/xkt/v10/glTF-Embedded/Duplex_A_20110505.glTFEmbedded.xkt",
    edges: true,
});
	
function rayPick(origin, direction, params = {}) {
    var initOpt = {
	pickSurface: true,
	//pickSurfaceNormal: true,
	pickSurfacePrecision: true,
	origin,
	direction,
    }

    var options = Object.assign(initOpt, params)
    return viewer.scene.pick(options, new PickResult())
}

function createRay(originPos, directPos) {
        new Mesh(viewer.scene, {
            geometry: new ReadableGeometry(viewer.scene, {
		primitive: "lines",
		positions: [...originPos, ...directPos],
		indices: [0, 1]
            }),
            material: new PhongMaterial(viewer.scene, {
		emissive: [1, 0.3, 0.3],
		diffuse: [0, 0, 0],
		ambient: [0, 0, 0],
		lineWidth: 2,
            }),
            pickable: false
    });
}

sceneModel.on("loaded", function () {
    var start = [-5, 10, 8]
    var end = [-0.0001290064122168033, 6.608948152823359, 10.960792167010636]
    var direction = math.subVec3(end, start, math.vec3())

    createRay(start, end)
		
    var hit1 = rayPick(start, direction)
    var hit2 = rayPick(start, direction, {includeEntities: [hit1.entity.id]}) // [WARN] [Scene 1]: pick(): Component not found: 0jf0rYHfX3RAB3bSIRjmr1

    console.log(hit1); // PickResult
    console.log(hit2); // no hit
})

Expected behavior
Same result in both picks.

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows
  • Browser Chrome
  • Version 125
@xeolabs
Copy link
Member

xeolabs commented Jun 10, 2024

Yeah this isn't even implemented within the renderer (Renderer.js), yet it's still documented on the Scene.pick method.

To mask which objects get picked, the best way, before picking, would be for application code to

1.save which scene objects are not pickable
2. iterate over the scene objects and set pickable true on those objects that you want to pick, and false for others
3. do the pick
4. restore the state saved in (1)

The thing is, setting pickable on all scene objects could be expensive for big models, if done continuously, on each pick, if continuously picking,

Therefore I think it's best to put that in the hands of the application code, which might set those pickable flags one time before doing many of picking operations, and then restore those pickable flags after all the picking is finished.

Then I would remove the includeEntities parameter from Scene.pick() documentation.

Does that make sense?

@g-rodigy
Copy link
Contributor Author

g-rodigy commented Jun 11, 2024

1.save which scene objects are not pickable

What mean save scene? Iterate objecst and set pickable to false/true on load model, this is only one way?

@xeolabs
Copy link
Member

xeolabs commented Jun 11, 2024

1.Record the IDs of all objects for which pickable is false
2. Iterate over all objects and set pickable false on the ones you dont want to pick, and true on the ones you do want to pick
3. do the pick, or many picks
4. iterate over all objects, set pickable true, except for the ones whose IDs you recorded in (1), which you set false

Because xeokit relies on batching the objects in order to achieve performance rendering for large numbers of objects, we must enable/disable picking for the objects like this. It's a performance trade off we can't avoid.

(1-2) is setting up for masked picking, (4) is cleaning up after masked picking.

@xeolabs
Copy link
Member

xeolabs commented Jun 17, 2024

Removed includeEntities and excludeEntities from documentation - they were not supposed to be there: 535130c

@xeolabs xeolabs closed this as completed Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants