var scene;
var engine;
var meshesForAnimation;
var box;
var jet;
var dinoRed;
var dinoBlue;
var jet1;
// event listner for pick event
window.addEventListener("click", function () {
// We try to pick an object
var pickResult = scene.pick(scene.pointerX, scene.pointerY);
if (pickResult.hit) {
if( pickResult.pickedMesh.parent.name == 'dinoBlue' ) {
//alert('blueClicked');
dinoBlue.play(true)};
if( pickResult.pickedMesh.parent.name == 'jet' ) {
//alert('blueClicked');
jet1.play(true)};
// impact.position.x = pickResult.pickedPoint.x;
// impact.position.y = pickResult.pickedPoint.y;
//alert(pickResult.pickedMesh.parent.name);
console.log(pickResult.pickedPoint.x + ' picked ' + pickResult.pickedMesh.parent.name) ;
// console.log(pickResult.pickedPoint.x + ' picked ' + pickResult.pickedMesh['parent']);
}
})
doSomeInitWork=function(){
// get the canvas DOM element
var canvas = document.getElementById('renderCanvas');
// load the 3D engine
engine = new BABYLON.Engine(canvas, true);
// createScene function that creates and return the scene
var createScene = function(){
// create a basic BJS Scene object
scene = new BABYLON.Scene(engine);
// create a FreeCamera, and set its position to (x:0, y:5, z:-10)
//var camera = new BABYLON.FreeCamera('camera1', new BABYLON.Vector3(0, 5,-10), scene);
// var box = BABYLON.Mesh.CreateBox('Box',1,0,scene);
// glb or gltf exports the animation. Can we trigger this
// jet = BABYLON.SceneLoader.Append("", "models/jet1.gltf", scene, function (scene) {
// do something with the scene
//});
box = BABYLON.SceneLoader.Append("", "models/kidHouse1.gltf", scene, function (scene) {
// do something with the scene
// get the list of animations
dinoRed = scene.animationGroups[0];
dinoBlue = scene.animationGroups[1];
jet1 = scene.animationGroups[2];
});
// var camera = new BABYLON.UniversalCamera("UniversalCamera", new BABYLON.Vector3(0, 0, box.position), scene);
var camera = new BABYLON.ArcRotateCamera('arcCamera1', BABYLON.Tools.ToRadians(135),BABYLON.Tools.ToRadians(45),10.0,box.position, scene);
// target the camera to scene origin
camera.setTarget(BABYLON.Vector3.Zero());
//camera.lowerRadiusLimit =2; // how close to zoom in
//camera.upperRadiusLimit = 50; // how far away we can zoom out
camera.wheelPrecision = 100;
//camera.collisionRadius = new BABYLON.Vector3(0.5, 0.5, 0.5)
//scene.collisionsEnabled = true;
// camera.checkCollisions = true;
// box.checkCollisions = true;
// attach the camera to the canvas
camera.attachControl(canvas, false);
// create a basic light, aiming 0,1,0 - meaning, to the sky
var light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(0,1,0), scene);
// create a built-in "sphere" shape; its constructor takes 6 params: name, segment, diameter, scene, updatable, sideOrientation
// var sphere = BABYLON.Mesh.CreateSphere('sphere1', 16, 2, scene);
// move the sphere upward 1/2 of its height
//sphere.position.y = 1;
// create a built-in "ground" shape;
var ground = BABYLON.Mesh.CreateGround('ground1', 6, 6, 2, scene);
// create an action or pick
pickResult = scene.pick(scene.pointerX, scene.pointerY);
// return the created scene
return scene;
}
// call the createScene function
scene = createScene();
// run the render loop
engine.runRenderLoop(function(){
scene.render();
});
// the canvas/window resize event handler
window.addEventListener('resize', function(){
engine.resize();
});
}
btnGetBabylonJS.onclick=function(){
$.getScript("https://preview.babylonjs.com/babylon.js", function( data, textStatus, jqxhr) {
console.log( data ); // Data returned
console.log( textStatus ); // Success
console.log( jqxhr.status ); // 200
console.log( "Load was performed." );
});
}
btngetBabylonLoader.onclick=function(){
$.getScript( "https://preview.babylonjs.com/loaders/babylonjs.loaders.min.js", function( data, textStatus, jqxhr ) {
console.log( data ); // Data returned
console.log( textStatus ); // Success
console.log( jqxhr.status ); // 200
console.log( "Load was performed." );
});
}
btnGetPepJS.onclick=function(){
$.getScript( "https://code.jquery.com/pep/0.4.1/pep.js", function( data, textStatus, jqxhr ) {
console.log( data ); // Data returned
console.log( textStatus ); // Success
console.log( jqxhr.status ); // 200
console.log( "Load was performed." );
});
}
btnRunCode.onclick=function(){
doSomeInitWork();
}
Form1.onshow=function(){
doSomeInitWork();
}
//"animations":[{"name":"Take1","channels":[{"sampler":0,"target":{"path":"translation","node":62}},{"sampler":1,"target":{"path":"scale","node":62}},{"sampler":2,"target":{"path":"rotation","node":62}}],"samplers":[{"input":248,"interpolation":"LINEAR","output":249},{"input":248,"interpolation":"LINEAR","output":250},{"input":248,"interpolation":"LINEAR","output":251}]},{"name":"Take2","channels":[{"sampler":0,"target":{"path":"translation","node":61}},{"sampler":1,"target":{"path":"scale","node":61}},{"sampler":2,"target":{"path":"rotation","node":61}}]
btnCreateAnim.onclick=function(){
scene.stopAllAnimations();
}
btnPlayAnim.onclick=function(){
console.log(scene.animationGroups);
// alert('button clicked');
dinoRed.play(true);
dinoBlue.play(true);
jet1.play(true);
}