3d - How to load *.babylon exported from blender using JavaScript/FileApi/XHR? -


i'm pretty fine working .babylon file format. exporter developed blender 3d editor works , if load exported model using next code:

// won't write full code // because fetched playground , it's standard , works babylon.sceneloader.load("", "filename.babylon", engine, function (newscene) { ... 

works , webgl renderer in browser shows model.

but, if don't want load models static files must saved in public folder of http-server ( iis, apache, lighttpd, nginx, etc.. ).

for e.g. wanna load .babylon file user's side or secure access .babylon files @ backend.

all right, let's watch situation, if provide kind of uploader (using file api browser) in web-application, user able load 3d-models pc or other devices.

i'm trying load models way:

file uploading ( change event of input-file ) works well:

    function handlefiles( event ) {         var uploader = event.srcelement || event.currenttarget;         var files = uploader.files;          var reader = new filereader();         reader.onload = function( event ) {             var data = json.parse( event.target.result );             loadcustommesh( data );         };          // passing single mesh because of testing purpose         reader.readastext( files[ 0 ] );     } 

handling geometry , adding scene:

function loadcustommesh( data ) {     var mesh = new babylon.mesh( math.random().tostring(), scene );     mesh.setverticesdata( babylon.vertexbuffer.positionkind, data.meshes[ 0 ].positions, true );     mesh.setverticesdata( babylon.vertexbuffer.normalkind, data.meshes[ 0 ].normals, true );     mesh.setindices( data.meshes[ 0 ].indices );      mesh.position = new babylon.vector3( 0, 0, 0 );     ... 

it works fine! but!!! without materials...

i've found multimaterial here uploaded data:

enter image description here

but if use next code:

mesh.material = data.multimaterials[ 0 ]; 

which valid sample, throws next error:

uncaught typeerror: t.needalphablending not function 

and don't know next, ideas?

the problem solved here:

http://www.html5gamedevs.com/topic/16846-how-to-load-babylon-exported-from-blender-using-javascriptfileapixhr/

function handlefiles( event ) {     var uploader = event.srcelement || event.currenttarget;     var files = uploader.files;     var reader = new filereader();      reader.onload = function( event ) {         var result = event.target.result;          babylon.sceneloader.importmesh(             null,             event.target.result,             '',             scene,             function( newmeshes, particlesystems, skeletons ) {                 var mesh = newmeshes[ 0 ];                 mesh.position = new babylon.vector3( 0, 0, 0 );             }         );     };      reader.readasdataurl( files[ 0 ] ); } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -