Forráskód Böngészése

Editor: added fog to scene export.

alteredq 12 éve
szülő
commit
ff27cf7fcc

+ 5 - 2
build/three.js

@@ -9573,7 +9573,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 	// fogs
 
-	for( df in data.fogs ) {
+	for ( df in data.fogs ) {
 
 		f = data.fogs[ df ];
 
@@ -9600,7 +9600,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 	// count how many geometries will be loaded asynchronously
 
-	for( dg in data.geometries ) {
+	for ( dg in data.geometries ) {
 
 		g = data.geometries[ dg ];
 
@@ -12083,6 +12083,8 @@ THREE.Scene.prototype.__removeObject = function ( object ) {
 
 THREE.Fog = function ( hex, near, far ) {
 
+	this.name = '';
+
 	this.color = new THREE.Color( hex );
 
 	this.near = ( near !== undefined ) ? near : 1;
@@ -12102,6 +12104,7 @@ THREE.Fog.prototype.clone = function () {
 
 THREE.FogExp2 = function ( hex, density ) {
 
+	this.name = '';
 	this.color = new THREE.Color( hex );
 	this.density = ( density !== undefined ) ? density : 0.00025;
 

+ 1 - 1
build/three.min.js

@@ -271,7 +271,7 @@ a);return a};THREE.SpriteAlignment={};THREE.SpriteAlignment.topLeft=new THREE.Ve
 THREE.SpriteAlignment.bottomRight=new THREE.Vector2(-1,1);THREE.Scene=function(){THREE.Object3D.call(this);this.overrideMaterial=this.fog=null;this.matrixAutoUpdate=!1;this.__objects=[];this.__lights=[];this.__objectsAdded=[];this.__objectsRemoved=[]};THREE.Scene.prototype=Object.create(THREE.Object3D.prototype);
 THREE.Scene.prototype.__addObject=function(a){if(a instanceof THREE.Light)-1===this.__lights.indexOf(a)&&this.__lights.push(a),a.target&&void 0===a.target.parent&&this.add(a.target);else if(!(a instanceof THREE.Camera||a instanceof THREE.Bone)&&-1===this.__objects.indexOf(a)){this.__objects.push(a);this.__objectsAdded.push(a);var b=this.__objectsRemoved.indexOf(a);-1!==b&&this.__objectsRemoved.splice(b,1)}for(b=0;b<a.children.length;b++)this.__addObject(a.children[b])};
 THREE.Scene.prototype.__removeObject=function(a){if(a instanceof THREE.Light){var b=this.__lights.indexOf(a);-1!==b&&this.__lights.splice(b,1)}else a instanceof THREE.Camera||(b=this.__objects.indexOf(a),-1!==b&&(this.__objects.splice(b,1),this.__objectsRemoved.push(a),b=this.__objectsAdded.indexOf(a),-1!==b&&this.__objectsAdded.splice(b,1)));for(b=0;b<a.children.length;b++)this.__removeObject(a.children[b])};
-THREE.Fog=function(a,b,c){this.color=new THREE.Color(a);this.near=void 0!==b?b:1;this.far=void 0!==c?c:1E3};THREE.Fog.prototype.clone=function(){return new THREE.Fog(this.color.getHex(),this.near,this.far)};THREE.FogExp2=function(a,b){this.color=new THREE.Color(a);this.density=void 0!==b?b:2.5E-4};THREE.FogExp2.prototype.clone=function(){return new THREE.FogExp2(this.color.getHex(),this.density)};
+THREE.Fog=function(a,b,c){this.name="";this.color=new THREE.Color(a);this.near=void 0!==b?b:1;this.far=void 0!==c?c:1E3};THREE.Fog.prototype.clone=function(){return new THREE.Fog(this.color.getHex(),this.near,this.far)};THREE.FogExp2=function(a,b){this.name="";this.color=new THREE.Color(a);this.density=void 0!==b?b:2.5E-4};THREE.FogExp2.prototype.clone=function(){return new THREE.FogExp2(this.color.getHex(),this.density)};
 THREE.CanvasRenderer=function(a){function b(a){z!==a&&(z=q.globalAlpha=a)}function c(a){u!==a&&(a===THREE.NormalBlending?q.globalCompositeOperation="source-over":a===THREE.AdditiveBlending?q.globalCompositeOperation="lighter":a===THREE.SubtractiveBlending&&(q.globalCompositeOperation="darker"),u=a)}function d(a){t!==a&&(t=q.strokeStyle=a)}function e(a){E!==a&&(E=q.fillStyle=a)}console.log("THREE.CanvasRenderer",THREE.REVISION);var a=a||{},f=this,g,h,i,j=new THREE.Projector,m=void 0!==a.canvas?a.canvas:
 document.createElement("canvas"),n,l,p,o,q=m.getContext("2d"),r=new THREE.Color(0),s=0,z=1,u=0,t=null,E=null,A=null,v=null,x=null,B,F,H,J,I=new THREE.RenderableVertex,L=new THREE.RenderableVertex,C,G,R,P,Q,Y,oa,N,M,da,S,K,O=new THREE.Color,ha=new THREE.Color,Z=new THREE.Color,aa=new THREE.Color,ia=new THREE.Color,U=new THREE.Color,ea=new THREE.Color,eb={},Aa={},Ja,Ta,ra,Ma,qb,nb,fb,Wa,zb,Ab,ob=new THREE.Rectangle,Na=new THREE.Rectangle,ka=new THREE.Rectangle,kb=!1,Ha=new THREE.Color,cb=new THREE.Color,
 lb=new THREE.Color,ua=new THREE.Vector3,gb,Xa,rb,va,Ya,Za,a=16;gb=document.createElement("canvas");gb.width=gb.height=2;Xa=gb.getContext("2d");Xa.fillStyle="rgba(0,0,0,1)";Xa.fillRect(0,0,2,2);rb=Xa.getImageData(0,0,2,2);va=rb.data;Ya=document.createElement("canvas");Ya.width=Ya.height=a;Za=Ya.getContext("2d");Za.translate(-a/2,-a/2);Za.scale(a,a);a--;this.domElement=m;this.sortElements=this.sortObjects=this.autoClear=!0;this.info={render:{vertices:0,faces:0}};this.setSize=function(a,b){n=a;l=b;p=

+ 71 - 2
examples/js/exporters/SceneExporter.js

@@ -23,11 +23,14 @@ THREE.SceneExporter.prototype = {
 		var geometriesArray = [];
 		var materialsArray = [];
 		var texturesArray = [];
+		var fogsArray = [];
 
 		var geometriesMap = {};
 		var materialsMap = {};
 		var texturesMap = {};
 
+		// extract objects, geometries, materials, textures
+
 		var checkTexture = function ( map ) {
 
 			if ( ! map ) return;
@@ -119,15 +122,29 @@ THREE.SceneExporter.prototype = {
 
 		var objects = linesArray.join( "\n" );
 
+		// extract fog
+
+		if ( scene.fog ) {
+
+			fogsArray.push( FogString( scene.fog ) );
+
+		}
+
+		// generate sections
+
 		var geometries = generateMultiLineString( geometriesArray, ",\n\n\t" );
 		var materials = generateMultiLineString( materialsArray, ",\n\n\t" );
 		var textures = generateMultiLineString( texturesArray, ",\n\n\t" );
+		var fogs = generateMultiLineString( fogsArray, ",\n\n\t" );
+
+		// generate defaults
 
 		var bgcolor = ColorString( clearColor );
 		var bgalpha = clearAlpha;
 		var defcamera = LabelString( getObjectName( activeCamera ) );
+		var deffog = LabelString( scene.fog ? getFogName( scene.fog ) : "" );
 
-		//
+		// templates
 
 		function Vector2String( v ) {
 
@@ -566,6 +583,45 @@ THREE.SceneExporter.prototype = {
 
 		//
 
+		function FogString( f ) {
+
+			if ( f instanceof THREE.Fog ) {
+
+				var output = [
+
+				'\t' + LabelString( getFogName( f ) ) + ': {',
+				'	"type"  : "linear",',
+				'	"color" : ' + ColorString( f.color ) + ',',
+				'	"near"  : '  + f.near + ',',
+				'	"far"   : '    + f.far,
+				'}'
+
+				];
+
+			} else if ( f instanceof THREE.FogExp2 ) {
+
+				var output = [
+
+				'\t' + LabelString( getFogName( f ) ) + ': {',
+				'	"type"    : "exp2",',
+				'	"color"   : '  + ColorString( f.color ) + ',',
+				'	"density" : ' + f.density,
+				'}'
+
+				];
+
+			} else {
+
+				var output = [];
+
+			}
+
+			return generateMultiLineString( output, '\n\t\t' );
+
+		}
+
+		//
+
 		function generateMultiLineString( lines, separator, padding ) {
 
 			var cleanLines = [];
@@ -611,6 +667,12 @@ THREE.SceneExporter.prototype = {
 
 		}
 
+		function getFogName( f ) {
+
+			return f.name ? f.name : "Default fog";
+
+		}
+
 		//
 
 		var output = [
@@ -652,6 +714,12 @@ THREE.SceneExporter.prototype = {
 			'	},',
 			'',
 
+			'	"fogs" :',
+			'	{',
+			'\t' + 	fogs,
+			'	},',
+			'',
+
 			'	"transform" :',
 			'	{',
 			'		"position"  : ' + position + ',',
@@ -663,7 +731,8 @@ THREE.SceneExporter.prototype = {
 			'	{',
 			'		"bgcolor" : ' + bgcolor + ',',
 			'		"bgalpha" : ' + bgalpha + ',',
-			'		"camera"  : ' + defcamera,
+			'		"camera"  : ' + defcamera + ',',
+			'		"fog"  	  : ' + deffog,
 			'	}',
 			'}'
 		].join( '\n' );

+ 2 - 2
src/loaders/SceneLoader.js

@@ -636,7 +636,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 	// fogs
 
-	for( df in data.fogs ) {
+	for ( df in data.fogs ) {
 
 		f = data.fogs[ df ];
 
@@ -663,7 +663,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 	// count how many geometries will be loaded asynchronously
 
-	for( dg in data.geometries ) {
+	for ( dg in data.geometries ) {
 
 		g = data.geometries[ dg ];
 

+ 2 - 0
src/scenes/Fog.js

@@ -5,6 +5,8 @@
 
 THREE.Fog = function ( hex, near, far ) {
 
+	this.name = '';
+
 	this.color = new THREE.Color( hex );
 
 	this.near = ( near !== undefined ) ? near : 1;

+ 1 - 0
src/scenes/FogExp2.js

@@ -5,6 +5,7 @@
 
 THREE.FogExp2 = function ( hex, density ) {
 
+	this.name = '';
 	this.color = new THREE.Color( hex );
 	this.density = ( density !== undefined ) ? density : 0.00025;