function Scene3D() { this.canvas; this.engine; this.scene; this.camera; this.light; }; Scene3D.prototype.setLights = function (){ var DLight1 = new BABYLON.DirectionalLight("dl", new BABYLON.Vector3(1,-1,1), this.scene); //DLight1.specular=new BABYLON.Color3(2, 2, 2); var DLight2 = new BABYLON.DirectionalLight("dl", new BABYLON.Vector3(-1,-1,1), this.scene); //DLight2.specular=new BABYLON.Color3(2, 2, 2); var SpotLight = new BABYLON.SpotLight("sl", new BABYLON.Vector3(-10,10,0), new BABYLON.Vector3(10,-10,0), Math.PI*1.5, 1, this.scene) /* var light0 = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(1.9,3.2,4.5), this.scene); //light0.diffuse = new BABYLON.Color3(1, 0, 0); //light0.specular = new BABYLON.Color3(1, 1, 1); light0.intensity = 3.3; */ /* var light1 = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(600, 600, 0), this.scene); light1.diffuse = new BABYLON.Color3(1, 1, 1); light1.specular = new BABYLON.Color3(0.3, 0.3, 0.3); light1.position = new BABYLON.Vector3(250, 400, 0); light1.intensity = 2; */ /* var light1 = new BABYLON.PointLight("Omni1", new BABYLON.Vector3(8.6,13.4,-0.9), this.scene); //light1.diffuse = new BABYLON.Color3(1, 0, 0); //light1.specular = new BABYLON.Color3(1, 1, 1); light1.intensity = 8.4; var light2 = new BABYLON.PointLight("Omni2", new BABYLON.Vector3(-3.5,-6.9,7.2), this.scene); //light2.diffuse = new BABYLON.Color3(1, 0, 0); //light2.specular = new BABYLON.Color3(1, 1, 1); light2.intensity = 7.3; */ } Scene3D.prototype.setCamera = function () { // Create a rotating camera this.camera = new BABYLON.ArcRotateCamera("Camera", -Math.PI/2, 0, 1000, BABYLON.Vector3.Zero(), this.scene); this.camera.attachControl(this.canvas, true); this.camera.lowerBetaLimit = 0.1; this.camera.upperBetaLimit = (Math.PI / 2) * 0.99; this.camera.lowerRadiusLimit = 125; this.camera.checkCollisions = true; }; Scene3D.prototype.setFreeCamera=function() { var followCam = new BABYLON.FollowCamera("fcam", this.camera.position, this.scene); followCam.radius = 200; followCam.maxCameraSpeed = 10; return followCam; }; Scene3D.prototype.setProductCamera = function (position) { this.camera.setTarget=position; }; Scene3D.prototype.createScene = function () { // Attach it to handle user inputs (keyboard, mouse, touch) this.canvas=document.getElementById('canvas3d'); this.engine = new BABYLON.Engine(this.canvas, true); this.scene = new BABYLON.Scene(this.engine); this.setCamera(); this.setLights(); //this.scene.debugLayer.show(); }; //实时渲染 Scene3D.prototype.render= function () { this.scene.collisionsEnabled = true; var scene=this.scene; this.engine.runRenderLoop( function () { scene.render(); } ); };