提交 477b0095 编写于 作者: A alteredq

Added dumping of scale to Blender exporter / handling of scale to JSONLoader.

This is backwards compatible: for existing models that don't have scale nothing should change.
上级 e6fd2d05
......@@ -399,11 +399,11 @@ Math.LN2));k.image.width=o;k.image.height=t;k.image.getContext("2d").drawImage(t
THREE.SubtractiveBlending;else if(b.blending=="Multiply")h.blending=THREE.MultiplyBlending;if(b.transparent!==undefined)h.transparent=b.transparent;if(b.depthTest!==undefined)h.depthTest=b.depthTest;if(b.mapDiffuse&&d){j=document.createElement("canvas");h.map=new THREE.Texture(j);h.map.sourceFile=b.mapDiffuse;f(h.map,d+"/"+b.mapDiffuse)}else if(b.colorDiffuse){j=(b.colorDiffuse[0]*255<<16)+(b.colorDiffuse[1]*255<<8)+b.colorDiffuse[2]*255;h.color=j;h.opacity=b.transparency}else if(b.DbgColor)h.color=
b.DbgColor;if(b.mapLightmap&&d){j=document.createElement("canvas");h.lightMap=new THREE.Texture(j);h.lightMap.sourceFile=b.mapLightmap;f(h.lightMap,d+"/"+b.mapLightmap)}return new THREE[g](h)}};THREE.JSONLoader=function(b){THREE.Loader.call(this,b)};THREE.JSONLoader.prototype=new THREE.Loader;THREE.JSONLoader.prototype.constructor=THREE.JSONLoader;THREE.JSONLoader.prototype.supr=THREE.Loader.prototype;
THREE.JSONLoader.prototype.load=function(b){var d=this,c=b.model,f=b.callback,g=b.texture_path?b.texture_path:this.extractUrlbase(c);b=new Worker(c);b.onmessage=function(h){d.createModel(h.data,f,g);d.onLoadComplete()};this.onLoadStart();b.postMessage((new Date).getTime())};
THREE.JSONLoader.prototype.createModel=function(b,d,c){var f=new THREE.Geometry;this.init_materials(f,b.materials,c);(function(){if(b.version===undefined||b.version!=2)console.error("Deprecated file format.");else{var g,h,j,k,n,p,o,t,x,v,z,C,E,J,U,y=b.faces;p=b.vertices;var L=b.normals,N=b.colors,P=0;for(g=0;g<b.uvs.length;g++)b.uvs[g].length&&P++;for(g=0;g<P;g++){f.faceUvs[g]=[];f.faceVertexUvs[g]=[]}k=0;for(n=p.length;k<n;){o=new THREE.Vertex;o.position.x=p[k++];o.position.y=p[k++];o.position.z=
p[k++];f.vertices.push(o)}k=0;for(n=y.length;k<n;){v=y[k++];p=v&1;j=v&2;g=v&4;h=v&8;t=v&16;o=v&32;z=v&64;v&=128;if(p){C=new THREE.Face4;C.a=y[k++];C.b=y[k++];C.c=y[k++];C.d=y[k++];p=4}else{C=new THREE.Face3;C.a=y[k++];C.b=y[k++];C.c=y[k++];p=3}if(j){j=y[k++];C.materials=f.materials[j]}j=f.faces.length;if(g)for(g=0;g<P;g++){E=b.uvs[g];x=y[k++];U=E[x*2];x=E[x*2+1];f.faceUvs[g][j]=new THREE.UV(U,x)}if(h)for(g=0;g<P;g++){E=b.uvs[g];J=[];for(h=0;h<p;h++){x=y[k++];U=E[x*2];x=E[x*2+1];J[h]=new THREE.UV(U,
x)}f.faceVertexUvs[g][j]=J}if(t){t=y[k++]*3;h=new THREE.Vector3;h.x=L[t++];h.y=L[t++];h.z=L[t];C.normal=h}if(o)for(g=0;g<p;g++){t=y[k++]*3;h=new THREE.Vector3;h.x=L[t++];h.y=L[t++];h.z=L[t];C.vertexNormals.push(h)}if(z){o=new THREE.Color(y[k++]);C.color=o}if(v)for(g=0;g<p;g++){o=y[k++];o=new THREE.Color(N[o]);C.vertexColors.push(o)}f.faces.push(C)}}})();(function(){var g,h,j,k;if(b.skinWeights){g=0;for(h=b.skinWeights.length;g<h;g+=2){j=b.skinWeights[g];k=b.skinWeights[g+1];f.skinWeights.push(new THREE.Vector4(j,
k,0,0))}}if(b.skinIndices){g=0;for(h=b.skinIndices.length;g<h;g+=2){j=b.skinIndices[g];k=b.skinIndices[g+1];f.skinIndices.push(new THREE.Vector4(j,k,0,0))}}f.bones=b.bones;f.animation=b.animation})();(function(){if(b.morphTargets!==undefined){var g,h,j,k;g=0;for(h=b.morphTargets.length;g<h;g++){f.morphTargets[g]={};f.morphTargets[g].name=b.morphTargets[g].name;f.morphTargets[g].vertices=[];dstVertices=f.morphTargets[g].vertices;srcVertices=b.morphTargets[g].vertices;j=0;for(k=srcVertices.length;j<
k;j+=3)dstVertices.push(new THREE.Vertex(new THREE.Vector3(srcVertices[j],srcVertices[j+1],srcVertices[j+2])))}}})();f.computeCentroids();f.computeFaceNormals();d(f)};THREE.BinaryLoader=function(b){THREE.Loader.call(this,b)};THREE.BinaryLoader.prototype=new THREE.Loader;THREE.BinaryLoader.prototype.constructor=THREE.BinaryLoader;THREE.BinaryLoader.prototype.supr=THREE.Loader.prototype;
THREE.JSONLoader.prototype.createModel=function(b,d,c){var f=new THREE.Geometry;this.init_materials(f,b.materials,c);(function(){if(b.version===undefined||b.version!=2)console.error("Deprecated file format.");else{var g,h,j,k,n,p,o,t,x,v,z,C,E,J,U,y=b.faces;p=b.vertices;var L=b.normals,N=b.colors;o=b.scale!==undefined?b.scale:1;var P=0;for(g=0;g<b.uvs.length;g++)b.uvs[g].length&&P++;for(g=0;g<P;g++){f.faceUvs[g]=[];f.faceVertexUvs[g]=[]}k=0;for(n=p.length;k<n;){z=new THREE.Vertex;z.position.x=p[k++]/
o;z.position.y=p[k++]/o;z.position.z=p[k++]/o;f.vertices.push(z)}k=0;for(n=y.length;k<n;){v=y[k++];p=v&1;j=v&2;g=v&4;h=v&8;t=v&16;o=v&32;z=v&64;v&=128;if(p){C=new THREE.Face4;C.a=y[k++];C.b=y[k++];C.c=y[k++];C.d=y[k++];p=4}else{C=new THREE.Face3;C.a=y[k++];C.b=y[k++];C.c=y[k++];p=3}if(j){j=y[k++];C.materials=f.materials[j]}j=f.faces.length;if(g)for(g=0;g<P;g++){E=b.uvs[g];x=y[k++];U=E[x*2];x=E[x*2+1];f.faceUvs[g][j]=new THREE.UV(U,x)}if(h)for(g=0;g<P;g++){E=b.uvs[g];J=[];for(h=0;h<p;h++){x=y[k++];
U=E[x*2];x=E[x*2+1];J[h]=new THREE.UV(U,x)}f.faceVertexUvs[g][j]=J}if(t){t=y[k++]*3;h=new THREE.Vector3;h.x=L[t++];h.y=L[t++];h.z=L[t];C.normal=h}if(o)for(g=0;g<p;g++){t=y[k++]*3;h=new THREE.Vector3;h.x=L[t++];h.y=L[t++];h.z=L[t];C.vertexNormals.push(h)}if(z){o=new THREE.Color(y[k++]);C.color=o}if(v)for(g=0;g<p;g++){o=y[k++];o=new THREE.Color(N[o]);C.vertexColors.push(o)}f.faces.push(C)}}})();(function(){var g,h,j,k;if(b.skinWeights){g=0;for(h=b.skinWeights.length;g<h;g+=2){j=b.skinWeights[g];k=b.skinWeights[g+
1];f.skinWeights.push(new THREE.Vector4(j,k,0,0))}}if(b.skinIndices){g=0;for(h=b.skinIndices.length;g<h;g+=2){j=b.skinIndices[g];k=b.skinIndices[g+1];f.skinIndices.push(new THREE.Vector4(j,k,0,0))}}f.bones=b.bones;f.animation=b.animation})();(function(){if(b.morphTargets!==undefined){var g,h,j,k;g=0;for(h=b.morphTargets.length;g<h;g++){f.morphTargets[g]={};f.morphTargets[g].name=b.morphTargets[g].name;f.morphTargets[g].vertices=[];dstVertices=f.morphTargets[g].vertices;srcVertices=b.morphTargets[g].vertices;
j=0;for(k=srcVertices.length;j<k;j+=3)dstVertices.push(new THREE.Vertex(new THREE.Vector3(srcVertices[j],srcVertices[j+1],srcVertices[j+2])))}}})();f.computeCentroids();f.computeFaceNormals();d(f)};THREE.BinaryLoader=function(b){THREE.Loader.call(this,b)};THREE.BinaryLoader.prototype=new THREE.Loader;THREE.BinaryLoader.prototype.constructor=THREE.BinaryLoader;THREE.BinaryLoader.prototype.supr=THREE.Loader.prototype;
THREE.BinaryLoader.prototype={load:function(b){var d=b.model,c=b.callback,f=b.texture_path?b.texture_path:THREE.Loader.prototype.extractUrlbase(d),g=b.bin_path?b.bin_path:THREE.Loader.prototype.extractUrlbase(d);b=(new Date).getTime();d=new Worker(d);var h=this.showProgress?THREE.Loader.prototype.updateProgress:null;d.onmessage=function(j){THREE.BinaryLoader.prototype.loadAjaxBuffers(j.data.buffers,j.data.materials,c,g,f,h)};d.onerror=function(j){alert("worker.onerror: "+j.message+"\n"+j.data);j.preventDefault()};
d.postMessage(b)},loadAjaxBuffers:function(b,d,c,f,g,h){var j=new XMLHttpRequest,k=f+"/"+b,n=0;j.onreadystatechange=function(){if(j.readyState==4)j.status==200||j.status==0?THREE.BinaryLoader.prototype.createBinModel(j.responseText,c,g,d):alert("Couldn't load ["+k+"] ["+j.status+"]");else if(j.readyState==3){if(h){n==0&&(n=j.getResponseHeader("Content-Length"));h({total:n,loaded:j.responseText.length})}}else j.readyState==2&&(n=j.getResponseHeader("Content-Length"))};j.open("GET",k,!0);j.overrideMimeType("text/plain; charset=x-user-defined");
j.setRequestHeader("Content-Type","text/plain");j.send(null)},createBinModel:function(b,d,c,f){var g=function(h){function j(O,aa){var qa=o(O,aa),Da=o(O,aa+1),ha=o(O,aa+2),la=o(O,aa+3),m=(la<<1&255|ha>>7)-127;qa|=(ha&127)<<16|Da<<8;if(qa==0&&m==-127)return 0;return(1-2*(la>>7))*(1+qa*Math.pow(2,-23))*Math.pow(2,m)}function k(O,aa){var qa=o(O,aa),Da=o(O,aa+1),ha=o(O,aa+2);return(o(O,aa+3)<<24)+(ha<<16)+(Da<<8)+qa}function n(O,aa){var qa=o(O,aa);return(o(O,aa+1)<<8)+qa}function p(O,aa){var qa=o(O,aa);
......
此差异已折叠。
......@@ -94,6 +94,8 @@ THREE.JSONLoader.prototype.createModel = function ( json, callback, texture_path
normals = json.normals,
colors = json.colors,
scale = ( json.scale !== undefined ) ? json.scale : 1.0,
nUvLayers = 0;
// disregard empty arrays
......@@ -118,9 +120,9 @@ THREE.JSONLoader.prototype.createModel = function ( json, callback, texture_path
vertex = new THREE.Vertex();
vertex.position.x = vertices[ offset ++ ];
vertex.position.y = vertices[ offset ++ ];
vertex.position.z = vertices[ offset ++ ];
vertex.position.x = vertices[ offset ++ ] / scale;
vertex.position.y = vertices[ offset ++ ] / scale;
vertex.position.z = vertices[ offset ++ ] / scale;
geometry.vertices.push( vertex );
......
......@@ -208,6 +208,8 @@ var model = {
"version" : 2,
"scale" : %(scale)f,
"materials": [%(materials)s],
"vertices": [%(vertices)s],
......@@ -741,7 +743,7 @@ def generate_materials_string(mesh, scene, use_colors, draw_type):
# ASCII model generator
# #####################################################
def generate_ascii_model(mesh, scene, use_normals, use_colors, use_uv_coords, use_materials, align_model, flipyz, option_truncate, draw_type):
def generate_ascii_model(mesh, scene, use_normals, use_colors, use_uv_coords, use_materials, align_model, flipyz, option_truncate, option_scale, draw_type):
vertices = mesh.vertices[:]
......@@ -769,6 +771,8 @@ def generate_ascii_model(mesh, scene, use_normals, use_colors, use_uv_coords, us
"nnormal" : nnormal,
"ncolor" : ncolor,
"nmaterial" : nmaterial,
"scale" : option_scale,
"uvs" : generate_uvs(uvs, use_uv_coords),
"normals" : generate_normals(normals, use_normals),
......@@ -834,7 +838,7 @@ def export_mesh(obj, scene, filepath, use_normals, use_colors, use_uv_coords, us
if not active_col_layer:
use_colors = False
text = generate_ascii_model(mesh, scene, use_normals, use_colors, use_uv_coords, use_materials, align_model, flipyz, option_truncate, obj.draw_type)
text = generate_ascii_model(mesh, scene, use_normals, use_colors, use_uv_coords, use_materials, align_model, flipyz, option_truncate, option_scale, obj.draw_type)
write_file(filepath, text)
# remove temp mesh
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册