Forum

Dynamic scene loading and relative object positioning

25 July 2016 10:30 #10717
Hi,

I'm dynamically loading a scene with several objects which i want to subsequently position in an arbitrary location in the main scene. Nonetheless, I want the relative position of the individual objects (from the dynamically loaded scene) to be maintained.

The API call I am using to position the objects from the dynamically loaded scene is:

m_trans.set_translation(obj, spawn_position[0], spawn_position[1], spawn_position[2]);

I've tried with "m_trans.set_translation_rel" as well.

(The full function to position the objects from the dynamically loaded scene in the main scene is provided below).

What obviously happens (in hindsight) is that all of the individual objects in the dynamically loaded scene are placed in the exact same position (in the main scene) causing the objects to "overlap".

So, how can I load a scene and position the objects in the main scene ***while maintaining their relative position to one another***?

By the way, it's not possible to "join" all of the objects in the dynamically loaded scene… I need them to be individual objects in the main scene.

Hope this all makes sense. Hope somebody can help me :)

Brett

function entity_loaded_cb(data_id) {
    var objs = m_scenes.get_all_objects("ALL", data_id);
    for (var i = 0; i < objs.length; i++) {
        var obj = objs[i];
            
        // Enable physics on the object.
        if (m_phy.has_physics(obj)) {
            m_phy.enable_simulation(obj);
        }

        // Set the object's location.
        console.log(spawn_position);
        if (spawn_position != null) {
            // TODO: Fix!
            //trans.set_translation(obj, spawn_position[0], spawn_position[1], spawn_position[2]); // x, y, z
            m_trans.set_translation_rel(obj, obj, spawn_position[0], spawn_position[1], spawn_position[2]); // x, y, z
        }
        // Show appended object.
        if (m_obj.is_mesh(obj)) {
            m_scenes.show_object(obj);
        }
    }
}
25 July 2016 12:16 #10723
For what it's worth, this is how I fixed this issue:

function entity_loaded_cb(data_id) {
    var objs = m_scenes.get_all_objects("ALL", data_id);
    for (var i = 0; i < objs.length; i++) {
        var obj = objs[i];
            
        // Enable physics on the object.
        if (m_phy.has_physics(obj)) {
            m_phy.enable_simulation(obj);
        }

        // Set the object's location.
        if (spawn_position != null) {
            var obj_translation_rel = m_trans.get_translation_rel(obj);
            var x_pos = spawn_position[X_INDEX] + obj_translation_rel[X_INDEX];
            var y_pos = spawn_position[Y_INDEX] + obj_translation_rel[Y_INDEX];
            var z_pos = spawn_position[Z_INDEX] + obj_translation_rel[Z_INDEX];
            m_trans.set_translation(obj, x_pos, y_pos, z_pos); // x, y, z
        }

        // Show appended object.
        if (m_obj.is_mesh(obj)) {
            m_scenes.show_object(obj);
        }
    }
}
25 July 2016 18:50 #10754
For what it's worth, this is how I fixed this issue:
Sorry for late response. We are glad you have already found a solution!
Development Lead | Twitter
 
Please register or log in to leave a reply.