Closed GoogleCodeExporter closed 9 years ago
I want to make sure I understand the use case. By "instance clones of a model",
do you mean something like this:
var model1 = new hemi.model.Model();
model1.setFileName('foo/scene.json');
var model2 = model1.clone();
? If so, would that be functionally different than:
var model1 = new hemi.model.Model();
model1.setFileName('foo/scene.json');
var model2 = new hemi.model.Model();
model2.setFileName('foo/scene.json');
?
Original comment by erik.kit...@gmail.com
on 20 Jun 2011 at 3:58
like above, except the line: "var model2 = model1.clone();"
would be executed after model1 loaded successfully. like this:
var model1 = new hemi.model.Model();
var subscription = model1 .subscribe (
hemi.msg.load,
function() {
model1.unsubscribe(subscription, hemi.msg.load);
var model2 = model1.clone();
}
);
model1.setFileName('foo/scene.json');
Above, if instead of the line "var model2 = model1.clone();" you used the
"model2.setFileName('foo/scene.json')" command you end up pulling the
'scene.json' file from browser cache and re-parsing it, you then recreate all
shapes, materials and transforms. All these newly created objects are
duplicates and impact memory footprint and performance. With a working clone
command, your cloned model simply references the existing materials, shapes and
transforms.
I have been up all night looking at this and other issues. What I found is that
I can create a new transform and reference shapes from the model1. Like this:
var model1 = new hemi.model.Model();
var subscription = model1 .subscribe (
hemi.msg.load,
function() {
model1.unsubscribe(subscription, hemi.msg.load);
var core = hemi.core,
pack = core.mainPack,
//create a new o3d.Transform
var transform = pack.createObject('Transform');
transform.parent = hemi.core.client.root;
transform.shapes = transform.shapes.concat(model1.getShapes());
}
);
model1.setFileName('foo/scene.json');
Something like the above works for my immediate need. But it is not exaclty a
clone, because it does not create a new hemi.model.Model object, it creates an
O3D tramsform. I'm not really sure that clone is the right name for it, maybe
'createInstance()' is better. A 'clone()' implies some kind of deep copy, much
like you utility for cloning arrays.
Original comment by raj...@gmail.com
on 20 Jun 2011 at 5:19
Ah, so you want a new Model that shares the geometry and materials of the old
Model but with its own unique transform hierarchy. I think this is doable.
We're doing a hard push on editor work right now, but I'll look into this when
I can.
Original comment by erik.kit...@gmail.com
on 20 Jun 2011 at 5:51
I got this working. Here is the code:
function clone() {
var core = hemi.core,
pack = core.mainPack;
var newModel = new hemi.model.Model();
newModel.pack = hemi.core.client.createPack();
var transform = newMesh.pack.createObject('Transform'); //o3d.Transform
transform.parent = core.client.root;
transform.shapes = transform.shapes.concat(this.getShapes());
transform.recalculateBoundingBox();
newModel.root = transform;
var paramObject = this.pack.createObject('ParamObject');
newModel.animationTime = paramObject.createParam('animTime', 'ParamFloat');
return newModel;
}
I haven't addressed the issue of animation yet. I havent had time to write a
unit test, but this deoes work in my subclass of hemi.model.Model. I dont
really have time to commit as of now.
Original comment by raj...@gmail.com
on 27 Jun 2011 at 1:35
The example code I posted has a problem in that once you make a clone, you
cannot then clone() that clone. There is something in the hemi.model.Model
object life-cycle I am not understanding.
Original comment by raj...@gmail.com
on 30 Jun 2011 at 1:51
Lowering priority as much of this may change in a move off o3d. Once those
plans are worked out then this can be raised if needed. For the core team will
not have cycles to address. Please let me know if that is not acceptable.
Original comment by jpywt...@gmail.com
on 3 Aug 2011 at 3:29
yeah I am going to change the status on this to WontFix to take it off your
list. I think the switch to Three.js will likely resolve this.
Original comment by raj...@gmail.com
on 19 Sep 2011 at 9:46
Original issue reported on code.google.com by
raj...@gmail.com
on 19 Jun 2011 at 11:50