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

Ray pick don't work in different directions #1494

Closed
g-rodigy opened this issue May 18, 2024 · 3 comments
Closed

Ray pick don't work in different directions #1494

g-rodigy opened this issue May 18, 2024 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@g-rodigy
Copy link
Contributor

Describe the bug
Based on example pick_ray_surface, test some case, code below. Ray pick does not work in same conditions.

To Reproduce

const viewer = new Viewer({
    canvasId: "myCanvas"
});

viewer.camera.eye = [-9.54, 13.47, 29.97];
viewer.camera.look = [4.40, 3.72, 8.89];
viewer.camera.up = [0.21, 0.91, -0.31];
    
const xktLoader = new XKTLoaderPlugin(viewer);

const sceneModel = xktLoader.load({
    id: "myModel",
    src: "../../assets/models/xkt/v10/glTF-Embedded/Duplex_A_20110505.glTFEmbedded.xkt",
   edges: true
});

function rayPick(origin, direction) {
    var hitInternal = viewer.scene.pick({
        pickSurface: true,
        // pickSurfacePrecision: true,
        origin,
        direction,
    }, new PickResult())

    new Mesh(viewer.scene, {
            geometry: new ReadableGeometry(viewer.scene, {
                primitive: "lines",
                positions: [...origin, ...direction],
                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
    });

    return hitInternal
}

sceneModel.on("loaded", function () {
    var start = [-16, 5, 8]
    var end = [30, 0, 0]
    console.log(rayPick(start, end ));
    console.log(rayPick(end, start)); // return null
})

Expected behavior
Will return pickResult on both variants.

Desktop (please complete the following information):

  • OS: Windows
  • Browser Chrome
  • Version 124

Additional context
Xeokit-sdk version v2.6.9

@paireks
Copy link
Member

paireks commented May 22, 2024

Hey,

just to make sure: isn't it null, because you switched origin point with direction vector?

It should work if there will be start and end point, but it looks to me, that there is a starting point and direction vector instead.

@paireks paireks added the question Further information is requested label May 22, 2024
@g-rodigy
Copy link
Contributor Author

It should work if there will be start and end point, but it looks to me, that there is a starting point and direction vector instead.

So, looks like I misunderstood. But if I have 2 points need get direction from one to other. Could you provide some small example?

@paireks
Copy link
Member

paireks commented May 22, 2024

Direction vector from point A to B is a B - A, meaning:
directionVectorX = B.X - A.X
directionVectorY = B.Y - A.Y
directionVectorZ = B.Z - A.Z

from this you should be able to create directionVector = [directionVectorX, directionVectorY, directionVectorZ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants