Advertisement
Guest User

ModelAnimation

a guest
Oct 15th, 2015
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var canvas = document.getElementById("renderCanvas");
  2. var engine = new BABYLON.Engine(canvas, true);
  3.  
  4. var createScene = function () {
  5.  
  6.     // This creates a basic Babylon Scene object (non-mesh)
  7.     var scene = new BABYLON.Scene(engine);
  8.  
  9.     // This creates and positions a free camera (non-mesh)
  10.     var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 7, 17), scene);
  11.  
  12.     // This targets the camera to scene origin
  13.     camera.setTarget(BABYLON.Vector3.Zero());
  14.  
  15.     // This attaches the camera to the canvas
  16.     camera.attachControl(canvas, true);
  17.  
  18.     // This creates a light, aiming 0,1,0 - to the sky (non-mesh)
  19.     var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
  20.    
  21.     // Default intensity is 1. Let's dim the light a small amount
  22.     light.intensity = 0.7;
  23.  
  24.     return scene;
  25. };
  26.  
  27. var scene = createScene();
  28.  
  29. //Import human mesh
  30. BABYLON.SceneLoader.ImportMesh("him", "models/Dude/", "dude.babylon", scene, function(newMeshes, particleSystems, skeletons){      
  31.         scene.cameras[0].setTarget(newMeshes[0].position);
  32.        
  33.         scene.getMeshByName("him").scaling = new BABYLON.Vector3(0.07, 0.07, 0.07);
  34.     });
  35.  
  36. engine.runRenderLoop(function () {
  37.     if(scene.getMeshByName("him") != null){
  38.        
  39.         //my attempt
  40.         var bone = scene.getSkeletonByName("Skeleton0").bones[20];
  41.         var boneMat = bone.getWorldMatrix();
  42.         BABYLON.Matrix.RotationZToRef(0.1, boneMat);
  43.        
  44.         bone.updateMatrix(boneMat);
  45.        
  46.         scene.render();
  47.     }
  48. });
  49.    
  50. // Resize
  51. window.addEventListener("resize", function () {
  52.     engine.resize();
  53. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement