提交 27dc056a 编写于 作者: M Mr.doob

Minor refactoring and clean up.

上级 49c7eeaf
因为 它太大了无法显示 source diff 。你可以改为 查看blob
此差异已折叠。
此差异已折叠。
......@@ -7,9 +7,9 @@ fogs:{}};g=function(){I-=1;h()};for(q in A.cameras){w=A.cameras[q];if(w.type=="p
z[1],z[2]);light.position.normalize()}else if(q.type=="point"){z=q.position;light=new THREE.PointLight;light.position.set(z[0],z[1],z[2])}w=q.color;i=q.intensity||1;light.color.setRGB(w[0]*i,w[1]*i,w[2]*i);F.scene.addLight(light);F.lights[v]=light}for(n in A.fogs){v=A.fogs[n];if(v.type=="linear")E=new THREE.Fog(0,v.near,v.far);else v.type=="exp2"&&(E=new THREE.FogExp2(0,v.density));w=v.color;E.color.setRGB(w[0],w[1],w[2]);F.fogs[n]=E}if(F.cameras&&A.defaults.camera)F.currentCamera=F.cameras[A.defaults.camera];
if(F.fogs&&A.defaults.fog)F.scene.fog=F.fogs[A.defaults.fog];w=A.defaults.bgcolor;F.bgColor=new THREE.Color;F.bgColor.setRGB(w[0],w[1],w[2]);F.bgColorAlpha=A.defaults.bgalpha;for(j in A.geometries){n=A.geometries[j];if(n.type=="bin_mesh"||n.type=="ascii_mesh")H+=1}K=H;for(j in A.geometries){n=A.geometries[j];if(n.type=="cube"){k=new Cube(n.width,n.height,n.depth,n.segments_width,n.segments_height,null,n.flipped,n.sides);F.geometries[j]=k}else if(n.type=="plane"){k=new Plane(n.width,n.height,n.segments_width,
n.segments_height);F.geometries[j]=k}else if(n.type=="sphere"){k=new Sphere(n.radius,n.segments_width,n.segments_height);F.geometries[j]=k}else if(n.type=="cylinder"){k=new Cylinder(n.numSegs,n.topRad,n.botRad,n.height,n.topOffset,n.botOffset);F.geometries[j]=k}else if(n.type=="torus"){k=new Torus(n.radius,n.tube,n.segmentsR,n.segmentsT);F.geometries[j]=k}else if(n.type=="icosahedron"){k=new Icosahedron(n.subdivisions);F.geometries[j]=k}else if(n.type=="bin_mesh")C.loadBinary({model:n.url,callback:e(j)});
else n.type=="ascii_mesh"&&C.loadAscii({model:n.url,callback:e(j)})}for(p in A.textures){j=A.textures[p];I+=j.url instanceof Array?j.url.length:1}M=I;for(p in A.textures){j=A.textures[p];if(j.mapping!=undefined&&THREE[j.mapping]!=undefined)j.mapping=new THREE[j.mapping];if(j.url instanceof Array){n=ImageUtils.loadArray(j.url,g);n=new THREE.Texture(n,j.mapping)}else{n=ImageUtils.loadTexture(j.url,j.mapping,g);if(THREE[j.min_filter]!=undefined)n.min_filter=THREE[j.min_filter];if(THREE[j.mag_filter]!=
undefined)n.mag_filter=THREE[j.mag_filter]}F.textures[p]=n}for(l in A.materials){p=A.materials[l];for(x in p.parameters)if(x=="env_map"||x=="map"||x=="light_map")p.parameters[x]=F.textures[p.parameters[x]];else if(x=="shading")p.parameters[x]=p.parameters[x]=="flat"?THREE.FlatShading:THREE.SmoothShading;else if(x=="blending")p.parameters[x]=THREE[p.parameters[x]]?THREE[p.parameters[x]]:THREE.NormalBlending;else x=="combine"&&(p.parameters[x]=p.parameters[x]=="MixOperation"?THREE.MixOperation:THREE.MultiplyOperation);
p=new THREE[p.type](p.parameters);F.materials[l]=p}c();d(F)}},addMesh:function(a,d,b,f,g,c,e,h,j,l){d=new THREE.Mesh(d,l);d.scale.x=d.scale.y=d.scale.z=b;d.position.x=f;d.position.y=g;d.position.z=c;d.rotation.x=e;d.rotation.y=h;d.rotation.z=j;a.addObject(d);return d},addPanoramaCubeWebGL:function(a,d,b){var f=ShaderUtils.lib.cube;f.uniforms.tCube.texture=b;b=new THREE.MeshShaderMaterial({fragment_shader:f.fragment_shader,vertex_shader:f.vertex_shader,uniforms:f.uniforms});d=new THREE.Mesh(new Cube(d,
else n.type=="ascii_mesh"&&C.loadAscii({model:n.url,callback:e(j)})}for(p in A.textures){j=A.textures[p];I+=j.url instanceof Array?j.url.length:1}M=I;for(p in A.textures){j=A.textures[p];if(j.mapping!=undefined&&THREE[j.mapping]!=undefined)j.mapping=new THREE[j.mapping];if(j.url instanceof Array)n=ImageUtils.loadTextureCube(j.url,j.mapping,g);else{n=ImageUtils.loadTexture(j.url,j.mapping,g);if(THREE[j.min_filter]!=undefined)n.min_filter=THREE[j.min_filter];if(THREE[j.mag_filter]!=undefined)n.mag_filter=
THREE[j.mag_filter]}F.textures[p]=n}for(l in A.materials){p=A.materials[l];for(x in p.parameters)if(x=="env_map"||x=="map"||x=="light_map")p.parameters[x]=F.textures[p.parameters[x]];else if(x=="shading")p.parameters[x]=p.parameters[x]=="flat"?THREE.FlatShading:THREE.SmoothShading;else if(x=="blending")p.parameters[x]=THREE[p.parameters[x]]?THREE[p.parameters[x]]:THREE.NormalBlending;else x=="combine"&&(p.parameters[x]=p.parameters[x]=="MixOperation"?THREE.MixOperation:THREE.MultiplyOperation);p=
new THREE[p.type](p.parameters);F.materials[l]=p}c();d(F)}},addMesh:function(a,d,b,f,g,c,e,h,j,l){d=new THREE.Mesh(d,l);d.scale.x=d.scale.y=d.scale.z=b;d.position.x=f;d.position.y=g;d.position.z=c;d.rotation.x=e;d.rotation.y=h;d.rotation.z=j;a.addObject(d);return d},addPanoramaCubeWebGL:function(a,d,b){var f=ShaderUtils.lib.cube;f.uniforms.tCube.texture=b;b=new THREE.MeshShaderMaterial({fragment_shader:f.fragment_shader,vertex_shader:f.vertex_shader,uniforms:f.uniforms});d=new THREE.Mesh(new Cube(d,
d,d,1,1,null,!0),b);a.addObject(d);return d},addPanoramaCube:function(a,d,b){var f=[];f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(b[0])}));f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(b[1])}));f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(b[2])}));f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(b[3])}));f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(b[4])}));f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(b[5])}));d=new THREE.Mesh(new Cube(d,
d,d,1,1,f,!0),new THREE.MeshFaceMaterial);a.addObject(d);return d},addPanoramaCubePlanes:function(a,d,b){var f=d/2;d=new Plane(d,d);var g=Math.PI,c=Math.PI/2;SceneUtils.addMesh(a,d,1,0,0,-f,0,0,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(b[5])}));SceneUtils.addMesh(a,d,1,-f,0,0,0,c,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(b[0])}));SceneUtils.addMesh(a,d,1,f,0,0,0,-c,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(b[1])}));SceneUtils.addMesh(a,d,1,0,f,0,c,0,g,new THREE.MeshBasicMaterial({map:new THREE.Texture(b[2])}));
SceneUtils.addMesh(a,d,1,0,-f,0,-c,0,g,new THREE.MeshBasicMaterial({map:new THREE.Texture(b[3])}))}},ShaderUtils={lib:{fresnel:{uniforms:{mRefractionRatio:{type:"f",value:1.02},mFresnelBias:{type:"f",value:0.1},mFresnelPower:{type:"f",value:2},mFresnelScale:{type:"f",value:1},tCube:{type:"t",value:1,texture:null}},fragment_shader:"uniform samplerCube tCube;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\nvec4 refractedColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nrefractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;\nrefractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;\nrefractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;\nrefractedColor.a = 1.0;\ngl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );\n}",
......
此差异已折叠。
此差异已折叠。
......@@ -29,38 +29,37 @@
</style>
</head>
<body>
<div id="info">
<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - webgl 3d sounds example -
music by <a href="http://www.newgrounds.com/audio/listen/358232" target="_blank">larrylarrybb</a> and
<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - webgl 3d sounds example -
music by <a href="http://www.newgrounds.com/audio/listen/358232" target="_blank">larrylarrybb</a> and
<a href="http://www.newgrounds.com/audio/listen/376737" target="_blank">skullbeatz</a> <br/><br/>
navigate with WASD / arrows / mouse
</div>
<div id="container"></div>
<div id="container"></div>
<script type="text/javascript" src="../build/Three.js"></script>
<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
<script type="text/javascript" src="js/Detector.js"></script>
<script type="text/javascript" src="js/Stats.js"></script>
<script type="text/javascript">
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
var container, stats;
var container;
var camera, scene, renderer, soundRenderer;
var light, pointLight;
var cameraControl;
var mesh;
var material_sphere1, material_sphere2;
var postprocessing = { enabled: true };
init();
animate();
......@@ -73,7 +72,7 @@
camera = new THREE.QuakeCamera( { fov: 50, aspect: window.innerWidth / window.innerHeight, near: 1, far: 10000,
movement_speed: 1, look_speed: 0.002, nofly: true, look_vertical: false } );
camera.position.set( 0, 25, 0 );
light = new THREE.DirectionalLight( 0xffffff );
......@@ -82,22 +81,22 @@
scene.addLight( light );
var sphere = new Sphere( 20, 32, 16 );
material_sphere1 = new THREE.MeshLambertMaterial( { color: 0xffaa00, shading: THREE.FlatShading } );
material_sphere2 = new THREE.MeshLambertMaterial( { color: 0xff2200, shading: THREE.FlatShading } );
var cube = new Cube( 5, 40, 5 );
var material_cube = new THREE.MeshLambertMaterial( { color: 0xffff00, shading: THREE.FlatShading } );
material_cube.color.setHSV( 0.1, 0.7, 1 );
// sound spheres
var s = 1;
var mesh1 = new THREE.Mesh( sphere, material_sphere1 );
mesh1.position.set( -250, 30, 0 );
mesh1.scale.set( s, s, s );
var sound1 = new THREE.Sound3D( [ "sounds/358232_j_s_song.mp3", "sounds/358232_j_s_song.ogg" ] , 275, 20, true );
//var sound1 = new THREE.Sound3D( "sounds/358232_j_s_song.ogg", 275, 20, true );
sound1.play();
......@@ -105,17 +104,17 @@
var dbg = new THREE.Mesh( cube, material_cube );
dbg.position.set( 0, -10 ,0 );
mesh1.addChild( dbg );
mesh1.addChild( sound1 );
scene.addObject( mesh1 );
var mesh2 = new THREE.Mesh( sphere, material_sphere2 );
mesh2.position.set( 250, 30, 0 );
mesh2.scale.set( s, s, s );
var sound2 = new THREE.Sound3D( [ "sounds/376737_Skullbeatz___Bad_Cat_Maste.mp3", "sounds/376737_Skullbeatz___Bad_Cat_Maste.ogg" ], 275, 20, true );
//var sound2 = new THREE.Sound3D( "sounds/376737_Skullbeatz___Bad_Cat_Maste.ogg", 275, 20, true );
var sound2 = new THREE.Sound3D( [ "sounds/376737_Skullbeatz___Bad_Cat_Maste.mp3", "sounds/376737_Skullbeatz___Bad_Cat_Maste.ogg" ], 275, 20, true );
//var sound2 = new THREE.Sound3D( "sounds/376737_Skullbeatz___Bad_Cat_Maste.ogg", 275, 20, true );
sound2.play();
var dbg = new THREE.Mesh( cube, material_cube );
......@@ -126,11 +125,11 @@
scene.addObject( mesh2 );
// ground
var material_wireframe = new THREE.MeshLambertMaterial( { color: 0xffaa00, wireframe: true, wireframe_linewidth: 1 } );
material_wireframe.color.setHSV( 0.1, 0.2, 0.25 );
var plane = new Plane( 1000, 1000, 100, 100 );
mesh = new THREE.Mesh( plane, material_wireframe );
mesh.position.y = 0.1;
......@@ -142,19 +141,14 @@
renderer.setSize( window.innerWidth, window.innerHeight );
soundRenderer = new THREE.SoundRenderer();
container.innerHTML = "";
container.appendChild( renderer.domElement );
container.appendChild( soundRenderer.domElement );
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
//container.appendChild( stats.domElement );
initPostprocessing();
renderer.autoClear = false;
}
......@@ -215,18 +209,17 @@
requestAnimationFrame( animate );
render();
stats.update();
}
function render() {
var time = new Date().getTime() * 0.005;
material_sphere1.color.setHSV( 0.0, 0.3 + 0.7 * ( 1 + Math.cos(time) ) / 2, 1 );
material_sphere2.color.setHSV( 0.1, 0.3 + 0.7 * ( 1 + Math.sin(time) ) / 2, 1 );
material_sphere2.color.setHSV( 0.1, 0.3 + 0.7 * ( 1 + Math.sin(time) ) / 2, 1 );
if ( postprocessing.enabled ) {
renderer.clear();
......
......@@ -8,13 +8,13 @@
THREE.Geometry = function () {
this.id = "Geometry" + THREE.GeometryIdCounter++;
this.vertices = [];
this.faces = [];
this.uvs = [];
this.uvs2 = [];
this.colors = [];
this.skinWeights = [];
this.skinIndices = [];
//this.skinVerticesA = [];
......@@ -127,18 +127,18 @@ THREE.Geometry.prototype = {
// create internal buffers for reuse when calling this method repeatedly
// (otherwise memory allocation / deallocation every frame is big resource hog)
if ( this.__tmpVertices == undefined ) {
this.__tmpVertices = new Array( this.vertices.length );
vertices = this.__tmpVertices;
for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
vertices[ v ] = new THREE.Vector3();
}
for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
face = this.faces[ f ];
......@@ -154,19 +154,18 @@ THREE.Geometry.prototype = {
}
}
} else {
vertices = this.__tmpVertices;
for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
vertices[ v ].set( 0, 0, 0 );
}
}
for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
......
......@@ -10,10 +10,14 @@
THREE.Matrix4 = function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
this.n11 = n11 || 1; this.n12 = n12 || 0; this.n13 = n13 || 0; this.n14 = n14 || 0;
this.n21 = n21 || 0; this.n22 = n22 || 1; this.n23 = n23 || 0; this.n24 = n24 || 0;
this.n31 = n31 || 0; this.n32 = n32 || 0; this.n33 = n33 || 1; this.n34 = n34 || 0;
this.n41 = n41 || 0; this.n42 = n42 || 0; this.n43 = n43 || 0; this.n44 = n44 || 1;
this.set(
n11 || 1, n12 || 0, n13 || 0, n14 || 0,
n21 || 0, n22 || 1, n23 || 0, n24 || 0,
n31 || 0, n32 || 0, n33 || 1, n34 || 0,
n41 || 0, n42 || 0, n43 || 0, n44 || 1
);
this.flat = new Array( 16 );
this.m33 = new THREE.Matrix3();
......@@ -22,23 +26,27 @@ THREE.Matrix4 = function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33
THREE.Matrix4.prototype = {
identity: function () {
set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
this.n11 = 1; this.n12 = 0; this.n13 = 0; this.n14 = 0;
this.n21 = 0; this.n22 = 1; this.n23 = 0; this.n24 = 0;
this.n31 = 0; this.n32 = 0; this.n33 = 1; this.n34 = 0;
this.n41 = 0; this.n42 = 0; this.n43 = 0; this.n44 = 1;
this.n11 = n11; this.n12 = n12; this.n13 = n13; this.n14 = n14;
this.n21 = n21; this.n22 = n22; this.n23 = n23; this.n24 = n24;
this.n31 = n31; this.n32 = n32; this.n33 = n33; this.n34 = n34;
this.n41 = n41; this.n42 = n42; this.n43 = n43; this.n44 = n44;
return this;
},
set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
identity: function () {
this.n11 = n11; this.n12 = n12; this.n13 = n13; this.n14 = n14;
this.n21 = n21; this.n22 = n22; this.n23 = n23; this.n24 = n24;
this.n31 = n31; this.n32 = n32; this.n33 = n33; this.n34 = n34;
this.n41 = n41; this.n42 = n42; this.n43 = n43; this.n44 = n44;
this.set(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
);
return this;
......@@ -46,10 +54,14 @@ THREE.Matrix4.prototype = {
copy: function ( m ) {
this.n11 = m.n11; this.n12 = m.n12; this.n13 = m.n13; this.n14 = m.n14;
this.n21 = m.n21; this.n22 = m.n22; this.n23 = m.n23; this.n24 = m.n24;
this.n31 = m.n31; this.n32 = m.n32; this.n33 = m.n33; this.n34 = m.n34;
this.n41 = m.n41; this.n42 = m.n42; this.n43 = m.n43; this.n44 = m.n44;
this.set(
m.n11, m.n12, m.n13, m.n14,
m.n21, m.n22, m.n23, m.n24,
m.n31, m.n32, m.n33, m.n34,
m.n41, m.n42, m.n43, m.n44
);
return this;
......@@ -133,6 +145,7 @@ THREE.Matrix4.prototype = {
b31 = b.n31, b32 = b.n32, b33 = b.n33, b34 = b.n34,
b41 = b.n41, b42 = b.n42, b43 = b.n43, b44 = b.n44;
/*
this.n11 = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
this.n12 = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
this.n13 = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
......@@ -152,6 +165,27 @@ THREE.Matrix4.prototype = {
this.n42 = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
this.n43 = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
this.n44 = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
*/
this.n11 = a11 * b11 + a12 * b21 + a13 * b31;
this.n12 = a11 * b12 + a12 * b22 + a13 * b32;
this.n13 = a11 * b13 + a12 * b23 + a13 * b33;
this.n14 = a11 * b14 + a12 * b24 + a13 * b34 + a14;
this.n21 = a21 * b11 + a22 * b21 + a23 * b31;
this.n22 = a21 * b12 + a22 * b22 + a23 * b32;
this.n23 = a21 * b13 + a22 * b23 + a23 * b33;
this.n24 = a21 * b14 + a22 * b24 + a23 * b34 + a24;
this.n31 = a31 * b11 + a32 * b21 + a33 * b31;
this.n32 = a31 * b12 + a32 * b22 + a33 * b32;
this.n33 = a31 * b13 + a32 * b23 + a33 * b33;
this.n34 = a31 * b14 + a32 * b24 + a33 * b34 + a34;
this.n41 = a41 * b11 + a42 * b21 + a43 * b31;
this.n42 = a41 * b12 + a42 * b22 + a43 * b32;
this.n43 = a41 * b13 + a42 * b23 + a43 * b33;
this.n44 = a41 * b14 + a42 * b24 + a43 * b34 + a44;
return this;
......@@ -189,25 +223,10 @@ THREE.Matrix4.prototype = {
this.n43 = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
this.n44 = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
r[ 0 ] = this.n11;
r[ 1 ] = this.n21;
r[ 2 ] = this.n31;
r[ 3 ] = this.n41;
r[ 4 ] = this.n12;
r[ 5 ] = this.n22;
r[ 6 ] = this.n32;
r[ 7 ] = this.n42;
r[ 8 ] = this.n13;
r[ 9 ] = this.n23;
r[ 10 ] = this.n33;
r[ 11 ] = this.n43;
r[ 12 ] = this.n14;
r[ 13 ] = this.n24;
r[ 14 ] = this.n34;
r[ 15 ] = this.n44;
r[ 0 ] = this.n11; r[ 1 ] = this.n21; r[ 2 ] = this.n31; r[ 3 ] = this.n41;
r[ 4 ] = this.n12; r[ 5 ] = this.n22; r[ 6 ] = this.n32; r[ 7 ] = this.n42;
r[ 8 ] = this.n13; r[ 9 ] = this.n23; r[ 10 ] = this.n33; r[ 11 ] = this.n43;
r[ 12 ] = this.n14; r[ 13 ] = this.n24; r[ 14 ] = this.n34; r[ 15 ] = this.n44;
return this;
......@@ -224,6 +243,7 @@ THREE.Matrix4.prototype = {
mn13 = m.n13, mn23 = m.n23, mn33 = m.n33, mn43 = m.n43,
mn14 = m.n14, mn24 = m.n24, mn34 = m.n34, mn44 = m.n44;
/*
this.n11 = n11 * mn11 + n12 * mn21 + n13 * mn31 + n14 * mn41;
this.n12 = n11 * mn12 + n12 * mn22 + n13 * mn32 + n14 * mn42;
this.n13 = n11 * mn13 + n12 * mn23 + n13 * mn33 + n14 * mn43;
......@@ -243,6 +263,27 @@ THREE.Matrix4.prototype = {
this.n42 = n41 * mn12 + n42 * mn22 + n43 * mn32 + n44 * mn42;
this.n43 = n41 * mn13 + n42 * mn23 + n43 * mn33 + n44 * mn43;
this.n44 = n41 * mn14 + n42 * mn24 + n43 * mn34 + n44 * mn44;
*/
this.n11 = n11 * mn11 + n12 * mn21 + n13 * mn31;
this.n12 = n11 * mn12 + n12 * mn22 + n13 * mn32;
this.n13 = n11 * mn13 + n12 * mn23 + n13 * mn33;
this.n14 = n11 * mn14 + n12 * mn24 + n13 * mn34 + n14;
this.n21 = n21 * mn11 + n22 * mn21 + n23 * mn31;
this.n22 = n21 * mn12 + n22 * mn22 + n23 * mn32;
this.n23 = n21 * mn13 + n22 * mn23 + n23 * mn33;
this.n24 = n21 * mn14 + n22 * mn24 + n23 * mn34 + n24;
this.n31 = n31 * mn11 + n32 * mn21 + n33 * mn31;
this.n32 = n31 * mn12 + n32 * mn22 + n33 * mn32;
this.n33 = n31 * mn13 + n32 * mn23 + n33 * mn33;
this.n34 = n31 * mn14 + n32 * mn24 + n33 * mn34 + n34;
this.n41 = n41 * mn11 + n42 * mn21 + n43 * mn31;
this.n42 = n41 * mn12 + n42 * mn22 + n43 * mn32;
this.n43 = n41 * mn13 + n42 * mn23 + n43 * mn33;
this.n44 = n41 * mn14 + n42 * mn24 + n43 * mn34 + n44;
return this;
......@@ -297,7 +338,8 @@ THREE.Matrix4.prototype = {
n13 * n21 * n32 * n44-
n11 * n23 * n32 * n44-
n12 * n21 * n33 * n44+
n11 * n22 * n33 * n44 );
n11 * n22 * n33 * n44
);
},
......@@ -335,55 +377,19 @@ THREE.Matrix4.prototype = {
},
flatten: function() {
var flat = this.flat;
flat[ 0 ] = this.n11;
flat[ 1 ] = this.n21;
flat[ 2 ] = this.n31;
flat[ 3 ] = this.n41;
flat[ 4 ] = this.n12;
flat[ 5 ] = this.n22;
flat[ 6 ] = this.n32;
flat[ 7 ] = this.n42;
flat[ 8 ] = this.n13;
flat[ 9 ] = this.n23;
flat[ 10 ] = this.n33;
flat[ 11 ] = this.n43;
flat[ 12 ] = this.n14;
flat[ 13 ] = this.n24;
flat[ 14 ] = this.n34;
flat[ 15 ] = this.n44;
flatten: function () {
this.flattenToArray( this.flat );
return flat;
},
flattenToArray: function( flat ) {
flat[ 0 ] = this.n11;
flat[ 1 ] = this.n21;
flat[ 2 ] = this.n31;
flat[ 3 ] = this.n41;
flat[ 4 ] = this.n12;
flat[ 5 ] = this.n22;
flat[ 6 ] = this.n32;
flat[ 7 ] = this.n42;
flat[ 8 ] = this.n13;
flat[ 9 ] = this.n23;
flat[ 10 ] = this.n33;
flat[ 11 ] = this.n43;
flattenToArray: function ( flat ) {
flat[ 12 ] = this.n14;
flat[ 13 ] = this.n24;
flat[ 14 ] = this.n34;
flat[ 15 ] = this.n44;
flat[ 0 ] = this.n11; flat[ 1 ] = this.n21; flat[ 2 ] = this.n31; flat[ 3 ] = this.n41;
flat[ 4 ] = this.n12; flat[ 5 ] = this.n22; flat[ 6 ] = this.n32; flat[ 7 ] = this.n42;
flat[ 8 ] = this.n13; flat[ 9 ] = this.n23; flat[ 10 ] = this.n33; flat[ 11 ] = this.n43;
flat[ 12 ] = this.n14; flat[ 13 ] = this.n24; flat[ 14 ] = this.n34; flat[ 15 ] = this.n44;
return flat;
......@@ -391,7 +397,7 @@ THREE.Matrix4.prototype = {
flattenToArrayOffset: function( flat, offset ) {
flat[ offset ] = this.n11;
flat[ offset ] = this.n11;
flat[ offset + 1 ] = this.n21;
flat[ offset + 2 ] = this.n31;
flat[ offset + 3 ] = this.n41;
......@@ -417,34 +423,46 @@ THREE.Matrix4.prototype = {
setTranslation: function( x, y, z ) {
this.set( 1, 0, 0, x,
0, 1, 0, y,
0, 0, 1, z,
0, 0, 0, 1 );
this.set(
1, 0, 0, x,
0, 1, 0, y,
0, 0, 1, z,
0, 0, 0, 1
);
return this;
},
setScale: function( x, y, z ) {
setScale: function ( x, y, z ) {
this.set(
x, 0, 0, 0,
0, y, 0, 0,
0, 0, z, 0,
0, 0, 0, 1
this.set( x, 0, 0, 0,
0, y, 0, 0,
0, 0, z, 0,
0, 0, 0, 1 );
);
return this;
},
setRotX: function( theta ) {
setRotX: function ( theta ) {
var c = Math.cos( theta ), s = Math.sin( theta );
this.set( 1, 0, 0, 0,
0, c, -s, 0,
0, s, c, 0,
0, 0, 0, 1 );
this.set(
1, 0, 0, 0,
0, c, -s, 0,
0, s, c, 0,
0, 0, 0, 1
);
return this;
......@@ -454,10 +472,14 @@ THREE.Matrix4.prototype = {
var c = Math.cos( theta ), s = Math.sin( theta );
this.set( c, 0, s, 0,
0, 1, 0, 0,
-s, 0, c, 0,
0, 0, 0, 1 );
this.set(
c, 0, s, 0,
0, 1, 0, 0,
-s, 0, c, 0,
0, 0, 0, 1
);
return this;
......@@ -467,10 +489,14 @@ THREE.Matrix4.prototype = {
var c = Math.cos( theta ), s = Math.sin( theta );
this.set( c, -s, 0, 0,
s, c, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 );
this.set(
c, -s, 0, 0,
s, c, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
);
return this;
......@@ -478,18 +504,22 @@ THREE.Matrix4.prototype = {
setRotAxis: function( axis, angle ) {
//Based on http://www.gamedev.net/reference/articles/article1199.asp
// Based on http://www.gamedev.net/reference/articles/article1199.asp
var c = Math.cos( angle ),
s = Math.sin( angle ),
t = 1 - c,
x = axis.x, y = axis.y, z = axis.z,
tx = t * x, ty = t * y;
s = Math.sin( angle ),
t = 1 - c,
x = axis.x, y = axis.y, z = axis.z,
tx = t * x, ty = t * y;
this.set(
tx * x + c, tx * y - s * z, tx * z + s * y, 0,
tx * y + s * z, ty * y + c, ty * z - s * x, 0,
tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
0, 0, 0, 1
this.set( tx * x + c, tx * y - s * z, tx * z + s * y, 0,
tx * y + s * z, ty * y + c, ty * z - s * x, 0,
tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
0, 0, 0, 1 );
);
return this;
......@@ -530,22 +560,10 @@ THREE.Matrix4.prototype = {
setRotationFromQuaternion: function( quat ) {
var x = quat.x, y = quat.y, z = quat.z, w = quat.w,
x2 = x + x,
y2 = y + y,
z2 = z + z,
xx = x * x2,
xy = x * y2,
xz = x * z2,
yy = y * y2,
yz = y * z2,
zz = z * z2,
wx = w * x2,
wy = w * y2,
wz = w * z2;
x2 = x + x, y2 = y + y, z2 = z + z,
xx = x * x2, xy = x * y2, xz = x * z2,
yy = y * y2, yz = y * z2, zz = z * z2,
wx = w * x2, wy = w * y2, wz = w * z2;
this.n11 = 1 - ( yy + zz );
this.n12 = xy - wz;
......@@ -561,7 +579,7 @@ THREE.Matrix4.prototype = {
},
scale: function( vec3 ) {
scale : function ( vec3 ) {
var x = vec3.x, y = vec3.y, z = vec3.z;
......@@ -574,24 +592,7 @@ THREE.Matrix4.prototype = {
},
extractRotationMatrix: function( m ) {
m.n11 = this.n11; m.n12 = this.n12; m.n13 = this.n13; m.n14 = 0;
m.n21 = this.n21; m.n22 = this.n22; m.n23 = this.n23; m.n24 = 0;
m.n31 = this.n31; m.n32 = this.n32; m.n33 = this.n33; m.n34 = 0;
m.n41 = 0; m.n42 = 0; m.n43 = 0; m.n44 = 1;
},
extractPositionVector: function( v ) {
v.x = this.n14;
v.y = this.n24;
v.z = this.n34;
},
toString: function() {
toString : function() {
return "| " + this.n11 + " " + this.n12 + " " + this.n13 + " " + this.n14 + " |\n" +
"| " + this.n21 + " " + this.n22 + " " + this.n23 + " " + this.n24 + " |\n" +
......@@ -667,9 +668,9 @@ THREE.Matrix4.makeInvert = function ( m1, m2 ) {
// based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
var n11 = m1.n11, n12 = m1.n12, n13 = m1.n13, n14 = m1.n14,
n21 = m1.n21, n22 = m1.n22, n23 = m1.n23, n24 = m1.n24,
n31 = m1.n31, n32 = m1.n32, n33 = m1.n33, n34 = m1.n34,
n41 = m1.n41, n42 = m1.n42, n43 = m1.n43, n44 = m1.n44;
n21 = m1.n21, n22 = m1.n22, n23 = m1.n23, n24 = m1.n24,
n31 = m1.n31, n32 = m1.n32, n33 = m1.n33, n34 = m1.n34,
n41 = m1.n41, n42 = m1.n42, n43 = m1.n43, n44 = m1.n44;
if( m2 === undefined ) m2 = new THREE.Matrix4();
......@@ -699,7 +700,7 @@ THREE.Matrix4.makeInvert = function ( m1, m2 ) {
THREE.Matrix4.makeInvert = function ( m1 ) {
var m2 = new THREE.Matrix4();
return THREE.Matrix4.makeInvertTo( m1, m2 );
};
......
......@@ -54,7 +54,6 @@ THREE.Ray.prototype = {
direction = this.direction.clone();
objMatrix = object.globalMatrix;
objMatrix.extractRotationMatrix( object.matrixRotation );
a = objMatrix.multiplyVector3( vertices[ face.a ].position.clone() );
b = objMatrix.multiplyVector3( vertices[ face.b ].position.clone() );
......
......@@ -7,10 +7,14 @@
THREE.Vector3 = function ( x, y, z ) {
this.x = x || 0;
this.y = y || 0;
this.z = z || 0;
this.set(
x || 0,
y || 0,
z || 0
);
};
......@@ -26,224 +30,276 @@ THREE.Vector3.prototype = {
},
copy: function ( v ) {
copy : function ( v ) {
this.set(
v.x,
v.y,
v.z
);
this.x = v.x;
this.y = v.y;
this.z = v.z;
return this;
},
add: function ( a, b ) {
add : function ( a, b ) {
this.x = a.x + b.x;
this.y = a.y + b.y;
this.z = a.z + b.z;
this.set(
a.x + b.x,
a.y + b.y,
a.z + b.z
);
return this;
},
addSelf: function ( v ) {
addSelf : function ( v ) {
this.set(
this.x += v.x;
this.y += v.y;
this.z += v.z;
this.x + v.x,
this.y + v.y,
this.z + v.z
);
return this;
},
addScalar: function ( s ) {
addScalar : function ( s ) {
this.set(
this.x + s,
this.y + s,
this.z + s
this.x += s;
this.y += s;
this.z += s;
);
return this;
},
sub: function( a, b ) {
sub : function ( a, b ) {
this.x = a.x - b.x;
this.y = a.y - b.y;
this.z = a.z - b.z;
this.set(
a.x - b.x,
a.y - b.y,
a.z - b.z
);
return this;
},
subSelf: function ( v ) {
subSelf : function ( v ) {
this.set(
this.x -= v.x;
this.y -= v.y;
this.z -= v.z;
this.x - v.x,
this.y - v.y,
this.z - v.z
);
return this;
},
cross: function ( a, b ) {
cross : function ( a, b ) {
this.set(
a.y * b.z - a.z * b.y,
a.z * b.x - a.x * b.z,
a.x * b.y - a.y * b.x
this.x = a.y * b.z - a.z * b.y;
this.y = a.z * b.x - a.x * b.z;
this.z = a.x * b.y - a.y * b.x;
);
return this;
},
crossSelf: function ( v ) {
crossSelf : function ( v ) {
var tx = this.x, ty = this.y, tz = this.z;
this.x = ty * v.z - tz * v.y;
this.y = tz * v.x - tx * v.z;
this.z = tx * v.y - ty * v.x;
this.set(
ty * v.z - tz * v.y,
tz * v.x - tx * v.z,
tx * v.y - ty * v.x
);
return this;
},
multiply : function ( a, b ) {
this.set(
a.x * b.x,
a.y * b.y,
a.z * b.z
);
return this;
},
multiply: function ( a, b ) {
multiplySelf : function ( v ) {
this.set(
this.x = a.x * b.x;
this.y = a.y * b.y;
this.z = a.z * b.z;
this.x * v.x,
this.y * v.y,
this.z * v.z
);
return this;
},
multiplySelf: function ( v ) {
multiplyScalar : function ( s ) {
this.set(
this.x * s,
this.y * s,
this.z * s
this.x *= v.x;
this.y *= v.y;
this.z *= v.z;
);
return this;
},
multiplyScalar: function ( s ) {
divideSelf : function ( v ) {
this.x *= s;
this.y *= s;
this.z *= s;
this.set(
this.x / v.x,
this.y / v.y,
this.z / v.z
);
return this;
},
divideSelf: function ( v ) {
divideScalar : function ( s ) {
this.set(
this.x /= v.x;
this.y /= v.y;
this.z /= v.z;
this.x / s,
this.y / s,
this.z / s
);
return this;
},
divideScalar: function ( s ) {
negate : function () {
this.set(
- this.x,
- this.y,
- this.z
this.x /= s;
this.y /= s;
this.z /= s;
);
return this;
},
dot: function ( v ) {
dot : function ( v ) {
return this.x * v.x + this.y * v.y + this.z * v.z;
},
distanceTo: function ( v ) {
distanceTo : function ( v ) {
var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
return Math.sqrt( dx * dx + dy * dy + dz * dz );
return Math.sqrt( this.distanceToSquared( v ) );
},
distanceToSquared: function ( v ) {
distanceToSquared : function ( v ) {
var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
return dx * dx + dy * dy + dz * dz;
},
length: function () {
length : function () {
return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
return Math.sqrt( this.lengthSq() );
},
lengthSq: function () {
lengthSq : function () {
return this.x * this.x + this.y * this.y + this.z * this.z;
},
lengthManhattan: function () {
lengthManhattan : function () {
return this.x + this.y + this.z;
},
normalize : function () {
negate: function () {
this.x = - this.x;
this.y = - this.y;
this.z = - this.z;
return this;
},
normalize: function () {
var length = Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
var l = this.length();
length > 0 ? this.multiplyScalar( 1 / length ) : this.set( 0, 0, 0 );
l > 0 ? this.multiplyScalar( 1 / l ) : this.set( 0, 0, 0 );
return this;
},
setLength: function( len ) {
setLength : function( len ) {
return this.normalize().multiplyScalar( len );
},
isZero: function () {
isZero : function () {
var almostZero = 0.0001;
return ( Math.abs( this.x ) < almostZero ) && ( Math.abs( this.y ) < almostZero ) && ( Math.abs( this.z ) < almostZero );
},
clone: function () {
clone : function () {
return new THREE.Vector3( this.x, this.y, this.z );
},
toString: function () {
toString : function () {
return 'THREE.Vector3 ( ' + this.x + ', ' + this.y + ', ' + this.z + ' )';
......
......@@ -7,31 +7,31 @@
THREE.Mesh = function( geometry, materials ) {
THREE.Object3D.call( this );
this.geometry = geometry;
this.materials = materials && materials.length ? materials : [ materials ];
this.geometry = geometry;
this.materials = materials && materials.length ? materials : [ materials ];
this.flipSided = false;
this.doubleSided = false;
this.overdraw = false; // TODO: Move to material?
// calc bound radius
if( this.geometry ) {
if( !this.geometry.boundingSphere )
if ( this.geometry ) {
if( !this.geometry.boundingSphere ) {
this.geometry.computeBoundingSphere();
}
this.boundRadius = geometry.boundingSphere.radius;
}
}
THREE.Mesh.prototype = new THREE.Object3D();
THREE.Mesh.prototype = new THREE.Object3D();
THREE.Mesh.prototype.constructor = THREE.Mesh;
THREE.Mesh.prototype.supr = THREE.Object3D.prototype;
THREE.Mesh.prototype.supr = THREE.Object3D.prototype;
......@@ -2,49 +2,52 @@
* @author mikael emtinger / http://gomo.se/
*/
THREE.Sound3D = function( sources, radius, volume, loop ) {
THREE.Sound3D = function ( sources, radius, volume, loop ) {
THREE.Object3D.call( this );
// flags
this.isLoaded = false;
this.isAddedToDOM = false;
this.isPlaying = false;
this.duration = -1;
this.radius = radius !== undefined ? Math.abs( radius ) : 100;
this.volume = Math.min( 1, Math.max( 0, volume !== undefined ? volume : 1 ) );
// dom
this.isLoaded = false;
this.isAddedToDOM = false;
this.isPlaying = false;
this.duration = -1;
this.radius = radius !== undefined ? Math.abs( radius ) : 100;
this.volume = Math.min( 1, Math.max( 0, volume !== undefined ? volume : 1 ) );
this.domElement = document.createElement( "audio" );
this.domElement = document.createElement( 'audio' );
this.domElement.volume = 0;
this.domElement.pan = 0;
this.domElement.loop = loop !== undefined ? loop : true;
this.domElement.pan = 0;
this.domElement.loop = loop !== undefined ? loop : true;
// init sources
this.sources = sources instanceof Array ? sources : [ sources ];
var element, source, type,
s, sl = this.sources.length;
for( s = 0; s < sl; s++ ) {
var element, source, type, s, sl = this.sources.length;
for ( s = 0; s < sl; s++ ) {
source = this.sources[ s ];
source.toLowerCase();
if( source.indexOf( ".mp3" ) !== -1 ) type = "audio/mpeg";
else if( source.indexOf( ".ogg" ) !== -1 ) type = "audio/ogg";
else if( source.indexOf( ".wav" ) !== -1 ) type = "audio/wav";
if( this.domElement.canPlayType( type ) ) {
element = document.createElement( "source" );
if ( source.indexOf( ".mp3" ) !== -1 ) {
type = "audio/mpeg";
} else if( source.indexOf( ".ogg" ) !== -1 ) {
type = "audio/ogg";
} else if( source.indexOf( ".wav" ) !== -1 ) {
type = "audio/wav";
}
if ( this.domElement.canPlayType( type ) ) {
element = document.createElement( "source" );
element.src = this.sources[ s ];
this.domElement.THREESound3D = this;
this.domElement.appendChild( element );
this.domElement.addEventListener( "canplay", this.onLoad, true );
......@@ -59,81 +62,67 @@ THREE.Sound3D = function( sources, radius, volume, loop ) {
};
THREE.Sound3D.prototype = new THREE.Object3D();
THREE.Sound3D.prototype = new THREE.Object3D();
THREE.Sound3D.prototype.constructor = THREE.Sound3D;
THREE.Sound3D.prototype.supr = THREE.Object3D.prototype;
THREE.Sound3D.prototype.supr = THREE.Object3D.prototype;
/*
* OnLoad
*/
THREE.Sound3D.prototype.onLoad = function () {
THREE.Sound3D.prototype.onLoad = function( ) {
var sound3D = this.THREESound3D;
if( sound3D.isLoaded )
if ( sound3D.isLoaded ) {
return;
}
this.removeEventListener( "canplay", this.onLoad, true );
sound3D.isLoaded = true;
sound3D.duration = this.duration;
if( sound3D.isPlaying )
if ( sound3D.isPlaying ) {
sound3D.play();
}
};
/*
* Add To DOM
*/
THREE.Sound3D.prototype.addToDOM = function ( parent ) {
THREE.Sound3D.prototype.addToDOM = function( parent ) {
this.isAddedToDOM = true;
parent.appendChild( this.domElement );
};
THREE.Sound3D.prototype.play = function ( startTime ) {
/*
* Play
*/
THREE.Sound3D.prototype.play = function( startTime ) {
this.isPlaying = true;
if( this.isLoaded ) {
if ( this.isLoaded ) {
this.domElement.play();
if( startTime )
if ( startTime ) {
this.domElement.currentTime = startTime % this.duration;
}
}
};
THREE.Sound3D.prototype.pause = function () {
/*
* Pause
*/
THREE.Sound3D.prototype.pause = function() {
this.isPlaying = false;
this.domElement.pause();
};
/*
* Stop
*/
THREE.Sound3D.prototype.stop = function(){
THREE.Sound3D.prototype.stop = function (){
this.isPlaying = false;
this.domElement.pause();
......@@ -141,32 +130,28 @@ THREE.Sound3D.prototype.stop = function(){
};
/*
* Calculate Volume and Pan
*/
THREE.Sound3D.prototype.calculateVolumeAndPan = function ( cameraRelativePosition ) {
var distance = cameraRelativePosition.length();
if( distance <= this.radius ) {
THREE.Sound3D.prototype.calculateVolumeAndPan = function( cameraRelativePosition ) {
var distance = cameraRelativePosition.length();
if( distance <= this.radius )
this.domElement.volume = this.volume * ( 1 - distance / this.radius );
else
this.domElement.volume = 0;
};
} else {
this.domElement.volume = 0;
}
/*
* Update
*/
};
THREE.Sound3D.prototype.update = function( parentGlobalMatrix, forceUpdate, camera ) {
THREE.Sound3D.prototype.update = function ( parentGlobalMatrix, forceUpdate, camera ) {
// update local (rotation/scale is not used)
if( this.matrixAutoUpdate ) {
if ( this.matrixAutoUpdate ) {
this.localMatrix.setPosition( this.position );
forceUpdate = true;
......@@ -175,15 +160,20 @@ THREE.Sound3D.prototype.update = function( parentGlobalMatrix, forceUpdate, came
// update global
if( forceUpdate || this.matrixNeedsUpdate ) {
if ( forceUpdate || this.matrixNeedsUpdate ) {
if ( parentGlobalMatrix ) {
if( parentGlobalMatrix )
this.globalMatrix.multiply( parentGlobalMatrix, this.localMatrix );
else
} else {
this.globalMatrix.copy( this.localMatrix );
}
this.matrixNeedsUpdate = false;
forceUpdate = true;
forceUpdate = true;
}
......@@ -192,10 +182,10 @@ THREE.Sound3D.prototype.update = function( parentGlobalMatrix, forceUpdate, came
var i, l = this.children.length;
for( i = 0; i < l; i++ )
this.children[ i ].update( this.globalMatrix, forceUpdate, camera );
};
for ( i = 0; i < l; i++ ) {
this.children[ i ].update( this.globalMatrix, forceUpdate, camera );
}
};
......@@ -2,46 +2,51 @@
* @author mikael emtinger / http://gomo.se/
*/
THREE.SoundRenderer = function() {
this.volume = 1;
this.domElement = document.createElement( "div" );
this.volume = 1;
this.domElement = document.createElement( "div" );
this.domElement.id = "THREESound";
this.cameraPosition = new THREE.Vector3();
this.soundPosition = new THREE.Vector3();
/*
* Render
*/
this.render = function( scene, camera, callSceneUpdate ) {
if( callSceneUpdate )
this.soundPosition = new THREE.Vector3();
this.render = function ( scene, camera, callSceneUpdate ) {
if ( callSceneUpdate ) {
scene.update( undefined, false, camera );
// loop through all sounds
}
var sound;
var sounds = scene.sounds;
var s, l = sounds.length;
//camera.globalMatrix.extractPositionVector( this.cameraPosition );
for( s = 0; s < l; s++ ) {
for ( s = 0; s < l; s++ ) {
sound = sounds[ s ];
sound.globalMatrix.extractPositionVector( this.soundPosition );
this.soundPosition.set(
sound.globalMatrix.n14,
sound.globalMatrix.n24,
sound.globalMatrix.n34
);
this.soundPosition.subSelf( camera.position );
if( sound.isPlaying && sound.isLoaded ) {
if( !sound.isAddedToDOM )
if ( !sound.isAddedToDOM ) {
sound.addToDOM( this.domElement );
}
sound.calculateVolumeAndPan( this.soundPosition );
}
......
......@@ -4,27 +4,20 @@
*/
THREE.Scene = function() {
// call super
THREE.Object3D.call( this );
// vars
THREE.Object3D.call( this );
this.objects = [];
this.lights = [];
this.sounds = [];
this.fog = null;
this.lights = [];
this.sounds = [];
this.fog = null;
};
THREE.Scene.prototype = new THREE.Object3D();
THREE.Scene.prototype = new THREE.Object3D();
THREE.Scene.prototype.constructor = THREE.Scene;
THREE.Scene.prototype.supr = THREE.Object3D.prototype;
/*
* Add Child
*/
THREE.Scene.prototype.supr = THREE.Object3D.prototype;
THREE.Scene.prototype.addChild = function( child ) {
......@@ -34,34 +27,42 @@ THREE.Scene.prototype.addChild = function( child ) {
}
THREE.Scene.prototype.addChildRecurse = function( child ) {
if( child instanceof THREE.Light ) {
if( this.lights.indexOf( child ) === -1 )
this.lights.push( child );
} else if( child instanceof THREE.Sound3D ) {
if( this.sounds.indexOf( child ) === -1 )
if ( child instanceof THREE.Light ) {
if ( this.lights.indexOf( child ) === -1 ) {
this.lights.push( child );
}
} else if ( child instanceof THREE.Sound3D ) {
if ( this.sounds.indexOf( child ) === -1 ) {
this.sounds.push( child );
} else if( !( child instanceof THREE.Camera || child instanceof THREE.Bone ) ) {
if( this.objects.indexOf( child ) === -1 )
}
} else if ( !( child instanceof THREE.Camera || child instanceof THREE.Bone ) ) {
if ( this.objects.indexOf( child ) === -1 ) {
this.objects.push( child );
}
}
for( var c = 0; c < child.children.length; c++ )
for ( var c = 0; c < child.children.length; c++ ) {
this.addChildRecurse( child.children[ c ] );
}
}
/*
* Remove Child
*/
THREE.Scene.prototype.removeChild = function( child ) {
this.supr.removeChild.call( this, child );
......@@ -70,43 +71,48 @@ THREE.Scene.prototype.removeChild = function( child ) {
}
THREE.Scene.prototype.removeChildRecurse = function( child ) {
if( child instanceof THREE.Light ) {
if ( child instanceof THREE.Light ) {
var i = this.lights.indexOf( child );
if( i !== -1 )
if ( i !== -1 ) {
this.lights.splice( i, 1 );
} else if( child instanceof THREE.Sound3D ) {
}
} else if ( child instanceof THREE.Sound3D ) {
var i = this.sounds.indexOf( child );
if( i !== -1 )
if( i !== -1 ) {
this.sounds.splice( i, 1 );
} else if( !( child instanceof THREE.Camera ) ) {
}
} else if ( !( child instanceof THREE.Camera ) ) {
var i = this.objects.indexOf( child );
if( i !== -1 )
if( i !== -1 ) {
this.objects.splice( i, 1 );
}
}
for( var c = 0; c < child.children.length; c++ )
this.removeChildRecurse( child.children[ c ] );
}
for ( var c = 0; c < child.children.length; c++ ) {
this.removeChildRecurse( child.children[ c ] );
}
/*
* Backward Compatibility
*/
}
THREE.Scene.prototype.addObject = THREE.Scene.prototype.addChild;
THREE.Scene.prototype.removeObject = THREE.Scene.prototype.removeChild;
THREE.Scene.prototype.addLight = THREE.Scene.prototype.addChild;
THREE.Scene.prototype.removeLight = THREE.Scene.prototype.removeChild;
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册