3Dlove Posted August 5, 2015 Share Posted August 5, 2015 Hello guys, I try to check mesh visibility by camera, if the mesh is hidden or not by other meshes. Here is my code : I need to put on a mouseMove event The problem is that the text message 'Je te vois !!!' is showed even if the sphere is behind the plane :var canvas = document.getElementById("renderCanvas");var engine = new BABYLON.Engine(canvas, true);var createScene = function () { // This creates a basic Babylon Scene object (non-mesh) var scene = new BABYLON.Scene(engine); // This creates and positions a free camera (non-mesh) var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 2, -10), scene); camera.attachControl(canvas, true); camera.applyGravity = true; camera.checkCollisions = true; camera.minZ = 0.1; camera.keysUp.push('Z'.charCodeAt(0)); camera.keysDown.push('S'.charCodeAt(0)); camera.keysLeft.push('Q'.charCodeAt(0)); camera.keysRight.push('D'.charCodeAt(0)); // This creates a light, aiming 0,1,0 - to the sky (non-mesh) var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene); light.intensity = 0.7; // Our built-in 'ground' shape. Params: name, width, depth, subdivs, scene var ground = BABYLON.Mesh.CreateGround("ground1", 200, 200, 2, scene); ground.checkCollisions = true; // Our built-in 'sphere' shape. Params: name, subdivs, size, scene var sphere = BABYLON.Mesh.CreateSphere("sphere1", 16, 2, scene); sphere.position.y = 1; // Plane var plane = BABYLON.Mesh.CreatePlane('plane', 8, scene); plane.material = new BABYLON.StandardMaterial('mat', scene); plane.material.backFaceCulling = false; plane.material.emissiveColor = BABYLON.Color3.Red(); plane.material.alpha = 0.5; plane.material.hasAlpha = true; plane.checkCollisions = true; plane.position = new BABYLON.Vector3(0, 4, -2); return scene; }; var scene = createScene(); engine.runRenderLoop(function () { scene.render(); }); // Resize window.addEventListener("resize", function () { engine.resize(); }); document.getElementById('renderCanvas').addEventListener('mousemove', function (evt) { var pickResult = scene.pick(evt.clientX, evt.clientY, function (mesh) { if ( scene.isActiveMesh(mesh) && (mesh.name === 'sphere1') ) return true; return false; }); if (pickResult.hit && pickResult.distance < 11) { console.warn('Je te vois !!!'); } else { console.info('Je ne te vois plus'); } }); Quote Link to comment Share on other sites More sharing options...
Temechon Posted August 5, 2015 Share Posted August 5, 2015 Fixed : http://www.babylonjs-playground.com/#1WSL9Q Your predicate should contain all mesh, otherwise you will test ONLY if the sphere1 intersect with the mouse (which is always true no matter if a plane is in front). 3Dlove 1 Quote Link to comment Share on other sites More sharing options...
3Dlove Posted August 6, 2015 Author Share Posted August 6, 2015 Thank you a lot ! =D =D =D Does exist a better solution to do that with less memory consumption ?$('#canvas').on('mousemove', function (evt) { var pickResult = scene.pick(scene.pointerX, scene.pointerY, null, false); if (pickResult.hit && pickResult.distance < 11) { var mesh = pickResult.pickedMesh; var parentName = (mesh.parent !== undefined)?mesh.parent.name:false; var isValidMesh = (scene.isActiveMesh(mesh) && (mesh.name.substring(0, 3) === 'tot' || mesh.name === 'titi' || parentName === 'tata')); if (isValidMesh === true) { console.info('Valid !'); } else { console.warn('Not valid !'); } } else { console.warn('Not valid !'); } }); Quote Link to comment Share on other sites More sharing options...
Temechon Posted August 6, 2015 Share Posted August 6, 2015 I'm not sure, but I don't think so. Quote Link to comment Share on other sites More sharing options...
RaananW Posted August 6, 2015 Share Posted August 6, 2015 If the meshes are static, you could optimize the process using octree - http://doc.babylonjs.com/tutorials/Optimizing_Your_Scene_with_Octrees But I am also not too sure there is a way other than using ray-tracing for that. Maybe using a different event and not the mousemove event will be better. And, just off topic - the new doc site is AWESOME!!! Temechon 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted August 6, 2015 Share Posted August 6, 2015 And, just off topic - the new doc site is AWESOME!!! But where is it? We can see it ? Quote Link to comment Share on other sites More sharing options...
iiceman Posted August 6, 2015 Share Posted August 6, 2015 http://doc.babylonjs.com/ <-- it's already the new one, I think the older one is here: http://babylondoc.azurewebsites.net/ Dad72 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted August 6, 2015 Share Posted August 6, 2015 Thanks iiceman. very good work on this doc. I like tooI especially like the search by tag (in classes) Temechon 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 6, 2015 Share Posted August 6, 2015 We will SOOOOOOOOOOOOOOONNN (correct @Temechon? ) add a post to show you guys how to contribute Quote Link to comment Share on other sites More sharing options...
Temechon Posted August 7, 2015 Share Posted August 7, 2015 The post is being written Quote Link to comment Share on other sites More sharing options...
3Dlove Posted August 7, 2015 Author Share Posted August 7, 2015 Yes, very nice Doc, this community is very active =D -- OK for octrees, exist-it in BJS an event Listenner for MouseIn and MouseOut specific tagged meshes ? =p Have a nice day Quote Link to comment Share on other sites More sharing options...
RaananW Posted August 7, 2015 Share Posted August 7, 2015 I made an off-topic the topic. ... That's usually Wingnut's job! Temechon 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.