|
frukc, Newbie
Posted: 08 March 2012 10:38 PM Total Posts: 8
would it be difficult to implement this in Loader module? like - if I load ‘file_name.obj.zip’ loader would unzip file first and then pass it to correstponding parser. as3 compression libraries are available for long time now, ‘text’ format 3d files are perfect for compression and grow huge, without it.
or maybe there allready is feature like this?
ty!
|
loth, Sr. Member
Posted: 09 March 2012 12:06 AM Total Posts: 236
[ # 1 ]
yosh
i use fzip and ByteArray something like this
File Attachments
|
jtopaz, Member
Posted: 09 March 2012 10:05 AM Total Posts: 53
[ # 2 ]
For .obj format, if we only zip the .obj file, how it handle the .mtl file and it’s texture image file?
|
loth, Sr. Member
Posted: 09 March 2012 10:15 AM Total Posts: 236
[ # 3 ]
simply i don’t use .mtl i creat new texture for all
and in fact .obj is biger than .3ds
but .obj have better support of smoothing group
|
frukc, Newbie
Posted: 09 March 2012 10:42 AM Total Posts: 8
[ # 4 ]
.mtl and texture files are handled as before. i had no problems with them.
my solution was to modify “SingleFileLoader.as” in loaders/misc/
by adding zip libraries…
import nochump.util.zip.ZipFile; import nochump.util.zip.ZipEntry;
and a little bit of code…
private function handleUrlLoaderComplete(event : Event) : void { var urlLoader : URLLoader = URLLoader(event.currentTarget); removeListeners(urlLoader); ///////////////////// added if (_req.url.toLowerCase().indexOf("zip") > -1) { var myZipFile:ZipFile = new ZipFile(urlLoader.data); _data = myZipFile.getInput(myZipFile.getEntry(myZipFile.entries[0])); } else { _data = urlLoader.data; } ///////////////////// end added //_data = urlLoader.data; .......
in project code i changed:
Loader3D.enableParser(OBJParserN); ... myLoader.load(new URLRequest('../lib/MODEL.obj'));
to
Loader3D.enableParser(OBJParserN); ... myLoader.load(new URLRequest('../lib/MODEL.zip'));
(zip file contains single file - same ‘MODEL.obj’)
and all worked fine from that point! including .mtl and texture file loading (zipped is just .obj file)
|
frukc, Newbie
Posted: 09 March 2012 10:50 AM Total Posts: 8
[ # 5 ]
p.s. reduction in size of OBJ file by zipping was 81% from 1.8Mb to 0.37Mb
|
loth, Sr. Member
Posted: 09 March 2012 11:47 AM Total Posts: 236
[ # 6 ]
|
loth, Sr. Member
Posted: 09 March 2012 04:50 PM Total Posts: 236
[ # 7 ]
i make basic tutorial about that
i add texture after
File Attachments
|
frukc, Newbie
Posted: 09 March 2012 11:39 PM Total Posts: 8
[ # 8 ]
good! can’t take a look at it now, but i guess, some as3 folks will appreciate your effort.
|
C., Newbie
Posted: 03 April 2012 06:48 PM Total Posts: 9
[ # 9 ]
Hey guys,
Thats a really interesting topic. Exactly what I was looking for! Has anyone tried already to load the images from the zip file as well? So that you only have to upload a single file, including all assets.
Somehow I couldnt manage to get the JPG in the loader again. I assume it should work with assetLoaderContext. But I dont know how to do that exactly.
My approach was something like this:
else if (product.substring(product.length - 4, product.length).toLowerCase() == ".zip") { var urlstream:URLStream = new URLStream(); urlstream.addEventListener(Event.COMPLETE, zipCompleteHandler); urlstream.load(new URLRequest(product)); }
...
private function zipCompleteHandler(event:Event):void { var datastream:URLStream = URLStream(event.target); var zipFile:ZipFile = new ZipFile(datastream); var assetcontext:AssetLoaderContext = new AssetLoaderContext(true); zipImages = new Array(); var data3ds:ByteArray = new ByteArray(); for (var i:int = 0; i < zipFile.entries.length; i++) { var entry:ZipEntry = zipFile.entries[i]; if (entry.name.substring(entry.name.length - 4, entry.name.length).toLowerCase() == ".3ds") { //if 3ds data3ds = zipFile.getInput(entry); trace("3ds-Url: " + entry.name); } else if (entry.name.substring(entry.name.length - 1, entry.name.length).toLowerCase() == "/" || entry.name.substring(entry.name.length - 1, entry.name.length).toLowerCase() == "\\") { //if folder-> do nothing trace("Folder Url: "+entry.name); } else { // images
zipImages[entry.name] = tempLoader.loadBytes(zipFile.getInput(entry)); assetcontext.mapUrlToData(entry.name, zipFile.getInput(entry)); trace("Image Url: "+entry.name); } } loader.loadData(data3ds, assetcontext, null, new Max3DSParser()); }
Do I have to convert the Image from Bytearray back to jpg before putting it in assetloadercontext? If so, how do I do that?
Thanks a lot!
Best regards
C.
|
loth, Sr. Member
Posted: 03 April 2012 11:47 PM Total Posts: 236
[ # 10 ]
jpg are already compress
compress them is a nonsense
i think
|
C., Newbie
Posted: 04 April 2012 07:19 AM Total Posts: 9
[ # 11 ]
Of course you are right and I have to admit that using JPG was a stupid example. But for BMP and PNG it would make sense.
Also I like the idea of having all assets in just one zip-file to load from instead of several folders.
|
loth, Sr. Member
Posted: 04 April 2012 09:40 AM Total Posts: 236
[ # 12 ]
for png is the same no compression and bmp not in flash
look at fzip codazure website they are a simple exemple
with 1000 icons
|
|