Jump to content

Unable to "hit" an object using pickResult in a loaded scene


3556
 Share

Recommended Posts

I am loading a scene where I'm trying to click on an object using pickResult.pickedMesh. I however get "null" when I check it on console.log. i.e. it is not hitting anything in the scene. 

Here is the code snippet. Have attached the index.html file as well. I was unable to upload the complete project to the playground, as I'm not sure how to upload the .babylon scene file and the .jpg files.

     //When pointer down event is raised

            newScene.onPointerDown = function (evt, pickResult) 
            {
                  // Check if pickResult(); did hit anything by printing it on console.log
                 console.log(pickResult.pickedMesh) 

                 // print the info of the clicked object

                 if (pickResult.hit) {console.log(pickResult.pickedMesh)}
            };

Would appreciate if anyone could help out on what could be possible wrong? Thanks.

index.html

Link to comment
Share on other sites

Thanks. That seems to be a member of a mesh?

I am however loading a complete scene via BABYLON.SceneLoader.Load(" ", "Retail.babylon", engine, function (newScene).  Do I have to loop through all the meshes in the scene and set each of them to isPickable = true; ?
 

Link to comment
Share on other sites

I had taken the scene from the babylon.js samples, so am not sure if the meshes in it are set to false (or true). I loaded the scene in the BJS editor and sandbox, but couldn't see that info in there. Any idea how that info can be viewed/edited? 

Link to comment
Share on other sites

Was able to resolve this using BABYLON.SceneLoader.ImportMesh and then setting individual meshes to isPickable

Thanks for all your help.

 

		// Import the scene as individual meshes
		BABYLON.SceneLoader.ImportMesh("", "./", "Retail.babylon", scene, function (newMeshes)
		{		
		  // set isPickable to true, so that mouse clicks can hit objects
		  for (var i = 0; i < newMeshes.length; i++) {newMeshes[i].isPickable = true;}
		}
		)		

		//When pointer down event is raised
		scene.onPointerDown = function (evt, pickResult) 
		{
                  // print the info of the clicked object 
                  if (pickResult.hit){console.log(pickResult.pickedMesh.name)} 
		}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...