<!DOCTYPE html> <html> <head> <title>BabylonJS</title> <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=no"> <script src="lib/babylon.2.3.js"></script> <style> html, body { overflow: hidden; width : 100%; height : 100%; margin : 0; padding : 0; } #gameCanvas { width : 100%; height : 100%; touch-action: none; } </style> </head> <body> <canvas id="gameCanvas"></canvas> </body> </html>
var canvas = document.getElementById('gameCanvas'); var engine = new BABYLON.Engine(canvas, true);
var scene = new BABYLON.Scene(engine);
var camera = new BABYLON.FreeCamera('camera1', new BABYLON.Vector3(0, 5,-10), scene); camera.setTarget(BABYLON.Vector3.Zero());
var light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(0,1,0), scene);
var box = new BABYLON.Mesh.CreateBox('box1', 2.0, scene);
var texture = new BABYLON.StandardMaterial("texture1", scene); texture.bumpTexture = new BABYLON.Texture("asset/babylonjs.png", scene); box.material = texture;
var animationX = new BABYLON.Animation.CreateAndStartAnimation('boxrotate', box, 'rotation.x', 60, 360, 1, 10); var animationY = new BABYLON.Animation.CreateAndStartAnimation('boxrotate', box, 'rotation.y', 60, 360, 1, 10);
engine.runRenderLoop(function(){ scene.render(); });
<!DOCTYPE html> <html> <head> <title>BabylonJS</title> <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=no"> <script src="lib/babylon.2.3.js"></script> <style> html, body { overflow: hidden; width : 100%; height : 100%; margin : 0; padding : 0; } #gameCanvas { width : 100%; height : 100%; touch-action: none; } </style> </head> <body> <canvas id="gameCanvas"></canvas> <script> window.addEventListener('DOMContentLoaded', function(){ // DOM- canvas var canvas = document.getElementById('gameCanvas'); // 3D- var engine = new BABYLON.Engine(canvas, true); // createScene – , var createScene = function(){ // Scene var scene = new BABYLON.Scene(engine); // FreeCamera, (x:0, y:5, z:-10) var camera = new BABYLON.FreeCamera('camera1', new BABYLON.Vector3(0, 5,-10), scene); // camera.setTarget(BABYLON.Vector3.Zero()); // , 0,1,0 – – , «» var light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(0,1,0), scene); // — var box = new BABYLON.Mesh.CreateBox('box1', 2.0, scene); // , var texture = new BABYLON.StandardMaterial("texture1", scene); texture.bumpTexture = new BABYLON.Texture("asset/babylonjs.png", scene); box.material = texture; // . . var animationX = new BABYLON.Animation.CreateAndStartAnimation('boxrotate', box, 'rotation.x', 60, 360, 1, 10); var animationY = new BABYLON.Animation.CreateAndStartAnimation('boxrotate', box, 'rotation.y', 60, 360, 1, 10); // return scene; } // createScene var scene = createScene(); // engine.runRenderLoop(function(){ scene.render(); }); // canvas window.addEventListener('resize', function(){ engine.resize(); }); }); </script> </body> </html>
Source: https://habr.com/ru/post/282089/
All Articles