kaspar, Newbie Posted: 08 October 2012 01:57 PM Total Posts: 11
Hey,
I’m trying to load or “initialize” many embedded models but it seems that the AssetLibrary somehow replaces the textures of previous models with the latest loaded one. Here’s the code I’m using:
[Embed(source="../assets/Models/OBJ/model1.obj", mimeType="application/octet-stream")] public static var Model1:Class;
[Embed(source="../assets/Models/OBJ/model1.mtl", mimeType="application/octet-stream")] public static var Model1Mtl:Class;
[Embed(source="../assets/textures/model1.jpg")] public static var Model1Texture:Class;
[Embed(source="../assets/Models/OBJ/model2.obj", mimeType="application/octet-stream")] public static var Model2:Class;
[Embed(source="../assets/Models/OBJ/model2.mtl", mimeType="application/octet-stream")] public static var Model2Mtl:Class;
[Embed(source="../assets/textures/model2.jpg")] public static var Model2Texture:Class;
public static function init():void { Parsers.enableAllBundled();
var context : AssetLoaderContext = new AssetLoaderContext(); context.mapUrlToData("model1.mtl", Model1Mtl); context.mapUrlToData("model1.jpg", Model1Texture);
AssetLibrary.loadData(new Model1(), context);
var context2:AssetLoaderContext = new AssetLoaderContext(); context2.mapUrlToData("model2.mtl", Model2Mtl); context2.mapUrlToData("model2.jpg", Model2Texture);
AssetLibrary.loadData(new Model2(), context2); }
When model2 is loaded, model1’s texture is replaced with model2’s texture, even when model2 is not placed on stage…
Is this a bug or should I be using another approach?
80prozent, Sr. Member Posted: 08 October 2012 02:08 PM Total Posts: 430
[ # 1 ]
hi
you create 2 AssetLoaderContext, but use the first for both loadData calls.
try this:
var context : AssetLoaderContext = new AssetLoaderContext(); context.mapUrlToData("model1.mtl", Model1Mtl); context.mapUrlToData("model1.jpg", Model1Texture);
AssetLibrary.loadData(new Model1(), context);
var context2:AssetLoaderContext = new AssetLoaderContext(); context2.mapUrlToData("model2.mtl", Model2Mtl); context2.mapUrlToData("model2.jpg", Model2Texture);
AssetLibrary.loadData(new Model2(), context2);
hope that helps
kaspar, Newbie Posted: 08 October 2012 02:31 PM Total Posts: 11
[ # 2 ]
actually I DO use the context2, it was just a typo in the post(fixed now)
80prozent, Sr. Member Posted: 08 October 2012 02:36 PM Total Posts: 430
[ # 3 ]
normaly the ConflictStrategy.as should take care of that.
maybe you should wait till the first loadData call is done, and than change your contex and do the next loadData, instead of using 2 contex.
kaspar, Newbie Posted: 09 October 2012 07:12 AM Total Posts: 11
[ # 4 ]
I tried also using queue - from the trace it was showing that the BitmapTexture was the last thing it loaded for one model
private static function onAssetComplete(event:AssetEvent):void { if(event.asset as BitmapTexture) { initQueue.shift(); if(initQueue.length) AssetLibrary.loadData(initQueue[0].object, initQueue[0].context); } }
but the result is the same, latest BitmapTexture will replace textures on all models…
kaspar, Newbie Posted: 09 October 2012 07:47 AM Total Posts: 11
[ # 5 ]
Is there any other way to use embedded OBJ files that have dependecies with .mtl and .jpg than using AssetLibrary?
kaspar, Newbie Posted: 09 October 2012 10:45 AM Total Posts: 11
[ # 6 ]
Ok I tried loading models one by one using separate AssetLoaders and the result is same: the all the models will have texture of the last model???
Fabrice Closier, Administrator Posted: 09 October 2012 12:30 PM Total Posts: 1265
[ # 7 ]
use the objParser from dev branch. This issue has been fixed.
kaspar, Newbie Posted: 09 October 2012 12:54 PM Total Posts: 11
[ # 8 ]
Awesome! Thanks a million!
jscamposcr, Newbie Posted: 15 October 2012 11:45 PM Total Posts: 20
[ # 9 ]
Hi Guys,
I’m having some issues when loading multiple models, if I load each one individually it works perfect but if I load 2 or more the texture on all but the last one will get messed up, check attachement and code:
Embeds:
[Embed(source="../assets/bulb.obj", mimeType="application/octet-stream")] private var BulbModel:Class; [Embed(source="../assets/bulb.mtl", mimeType="application/octet-stream")] private var BulbMTL:Class; [Embed(source="../assets/maps/bulb-texture.jpg", mimeType="image/jpg")] private var BulbTexture:Class;
[Embed(source="../assets/heart.obj", mimeType="application/octet-stream")] private var HeartModel:Class; [Embed(source="../assets/heart.mtl", mimeType="application/octet-stream")] private var HeartMTL:Class; [Embed(source="../assets/maps/heart-texture.jpg", mimeType="image/jpg")] private var HeartTexture:Class;
Inside my main function:
var heartLoaderContent:AssetLoaderContext = new AssetLoaderContext(); heartLoaderContent.mapUrlToData("heart.mtl", new HeartMTL()); heartLoaderContent.mapUrlToData("maps/heart-texture.jpg", new HeartTexture());
var _heartLoader:Loader3D = new Loader3D(); _heartLoader.addEventListener(LoaderEvent.LOAD_ERROR, onLoadError); _heartLoader.name = "Heart"; _heartLoader.loadData(new HeartModel(), heartLoaderContent, null, new OBJParser(6));
var bulbLoaderContent:AssetLoaderContext = new AssetLoaderContext(); bulbLoaderContent.mapUrlToData("bulb.mtl", new BulbMTL()); bulbLoaderContent.mapUrlToData("maps/bulb-texture.jpg", new BulbTexture());
var _bulbLoader:Loader3D = new Loader3D(); _bulbLoader.addEventListener(LoaderEvent.LOAD_ERROR, onLoadError); _bulbLoader.name = "Bulb"; _bulbLoader.loadData(new BulbModel(), bulbLoaderContent, null, new OBJParser(1)); _bulbLoader.y = 200;
//setup the scene _view.scene.addChild(_heartLoader); _view.scene.addChild(_bulbLoader);
kaspar, Newbie Posted: 26 October 2012 12:16 PM Total Posts: 11
[ # 10 ]
As Fabrice said - download the away3d.loaders.parsers.OBJParser.as from the dev branch and replace the one in your away3d source - that should fix it.