picking.js 1.2 KB

123456789101112131415161718192021222324252627282930
  1. var createScene = function () {
  2. var scene = new BABYLON.Scene(engine);
  3. // setup environment
  4. var light0 = new BABYLON.PointLight("Omni", new BABYLON.Vector3(0, 10, 20), scene);
  5. var freeCamera = new BABYLON.FreeCamera("FreeCamera", new BABYLON.Vector3(0, 0, -30), scene);
  6. // Impact impostor
  7. var impact = BABYLON.Mesh.CreatePlane("impact", 1, scene);
  8. impact.material = new BABYLON.StandardMaterial("impactMat", scene);
  9. impact.material.diffuseTexture = new BABYLON.Texture("textures/impact.png", scene);
  10. impact.material.diffuseTexture.hasAlpha = true;
  11. impact.position = new BABYLON.Vector3(0, 0, -0.1);
  12. //Wall
  13. var wall = BABYLON.Mesh.CreatePlane("wall", 20.0, scene);
  14. wall.material = new BABYLON.StandardMaterial("wallMat", scene);
  15. wall.material.emissiveColor = new BABYLON.Color3(0.5, 1, 0.5);
  16. //When pointer down event is raised
  17. scene.onPointerDown = function (evt, pickResult) {
  18. // if the click hits the ground object, we change the impact position
  19. if (pickResult.hit) {
  20. impact.position.x = pickResult.pickedPoint.x;
  21. impact.position.y = pickResult.pickedPoint.y;
  22. }
  23. };
  24. return scene;
  25. }