octree.js 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. var CreateOctreeTestScene = function (engine) {
  2. var scene = new BABYLON.Scene(engine);
  3. var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene);
  4. var light0 = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(0, 10, 0), scene);
  5. var material = new BABYLON.StandardMaterial("kosh", scene);
  6. var sphere = BABYLON.Mesh.CreateSphere("sphere0", 16, 1, scene);
  7. camera.setPosition(new BABYLON.Vector3(-10, 10, 0));
  8. // Sphere material
  9. material.diffuseColor = new BABYLON.Color3(0.5, 0.5, 0.5);
  10. material.specularColor = new BABYLON.Color3(1.0, 1.0, 1.0);
  11. material.specularPower = 32;
  12. material.checkReadyOnEveryCall = false;
  13. sphere.material = material;
  14. // Fog
  15. scene.fogMode = BABYLON.Scene.FOGMODE_EXP;
  16. scene.fogDensity = 0.05;
  17. // Clone spheres
  18. var playgroundSize = 50;
  19. for (var index = 0; index < 8000; index++) {
  20. var clone = sphere.clone("sphere" + (index + 1), null, true);
  21. var scale = Math.random() * 0.8 + 0.6;
  22. clone.scaling = new BABYLON.Vector3(scale, scale, scale);
  23. clone.position = new BABYLON.Vector3(Math.random() * 2 * playgroundSize - playgroundSize, Math.random() * 2 * playgroundSize - playgroundSize, Math.random() * 2 * playgroundSize - playgroundSize);
  24. }
  25. sphere.setEnabled(false);
  26. scene.createOrUpdateSelectionOctree();
  27. return scene;
  28. };