instanced bones.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. var createScene = function () {
  2. var scene = new BABYLON.Scene(engine);
  3. var light = new BABYLON.DirectionalLight("dir01", new BABYLON.Vector3(0, -0.5, -1.0), scene);
  4. var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, new BABYLON.Vector3(0, 30, 0), scene);
  5. camera.attachControl(canvas, false);
  6. camera.setPosition(new BABYLON.Vector3(20, 70, 120));
  7. light.position = new BABYLON.Vector3(50, 250, 200);
  8. light.shadowOrthoScale = 2.0;
  9. camera.minZ = 1.0;
  10. scene.ambientColor = new BABYLON.Color3(0.3, 0.3, 0.3);
  11. // Ground
  12. var ground = BABYLON.Mesh.CreateGround("ground", 1000, 1000, 1, scene, false);
  13. var groundMaterial = new BABYLON.StandardMaterial("ground", scene);
  14. groundMaterial.diffuseColor = new BABYLON.Color3(0.2, 0.2, 0.2);
  15. groundMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
  16. ground.material = groundMaterial;
  17. ground.receiveShadows = true;
  18. // Shadows
  19. var shadowGenerator = new BABYLON.ShadowGenerator(1024, light);
  20. shadowGenerator.useBlurExponentialShadowMap = true;
  21. // Dude
  22. BABYLON.SceneLoader.ImportMesh("him", "scenes/Dude/", "Dude.babylon", scene, function (newMeshes2, particleSystems2, skeletons2) {
  23. var dude = newMeshes2[0];
  24. for (var index = 1; index < newMeshes2.length; index++) {
  25. shadowGenerator.getShadowMap().renderList.push(newMeshes2[index]);
  26. }
  27. for (var count = 0; count < 50; count++) {
  28. var offsetX = 200 * Math.random() - 100;
  29. var offsetZ = 200 * Math.random() - 100;
  30. for (index = 1; index < newMeshes2.length; index++) {
  31. var instance = newMeshes2[index].createInstance("instance" + count);
  32. shadowGenerator.getShadowMap().renderList.push(instance);
  33. instance.parent = newMeshes2[index].parent;
  34. instance.position = newMeshes2[index].position.clone();
  35. if (!instance.parent.subMeshes) {
  36. instance.position.x += offsetX;
  37. instance.position.z -= offsetZ;
  38. }
  39. }
  40. }
  41. dude.rotation.y = Math.PI;
  42. dude.position = new BABYLON.Vector3(0, 0, -80);
  43. scene.beginAnimation(skeletons2[0], 0, 100, true, 1.0);
  44. });
  45. return scene;
  46. };