Forum

User posts amiarun
17 March 2016 08:48
I have another query with regard to moving objects along the wall. This is the code I have:

 var point_w = m_util.line_plane_intersect(FRONT_WALL_PLANE_NORMAL, 3,
                        cam_trans, camera_ray, _vec3_tmp3);
                    var point_wl = m_util.line_plane_intersect(LEFT_WALL_PLANE_NORMAL, -2.45,
                        cam_trans, camera_ray, _vec3_tmp3);
                    var point_wr = m_util.line_plane_intersect(RIGHT_WALL_PLANE_NORMAL, -1.95,
                        cam_trans, camera_ray, _vec3_tmp3);
                    if (point_w && camera_ray[1] < 0) {
                        var obj_parent = m_obj.get_parent(_selected_obj);
                        if (obj_parent && m_obj.is_armature(obj_parent))
                            // translate the parent (armature) of the animated object
                            m_trans.set_translation_v(obj_parent, point_w);
                        else
                            m_trans.set_translation_v(_selected_obj, point_w);
                        limit_object_position(_selected_obj);
                    }

                    if (point_wl && camera_ray[1] < 0) {
                        m_trans.set_rotation(_selected_obj,0,0.7071,0,0.7071);
                        var obj_parent = m_obj.get_parent(_selected_obj);
                        if (obj_parent && m_obj.is_armature(obj_parent))
                            // translate the parent (armature) of the animated object
                            m_trans.set_translation_v(obj_parent, point_wl);
                        else
                            m_trans.set_translation_v(_selected_obj, point_wl);
                        limit_object_position(_selected_obj);
                    }

                    if (point_wr && camera_ray[1] < 0) {
                        m_trans.set_rotation(_selected_obj,0,0.7071,0,0.7071);
                        var obj_parent = m_obj.get_parent(_selected_obj);
                        if (obj_parent && m_obj.is_armature(obj_parent))
                            // translate the parent (armature) of the animated object
                            m_trans.set_translation_v(obj_parent, point_wr);
                        else
                            m_trans.set_translation_v(_selected_obj, point_wr);
                        limit_object_position(_selected_obj);
                    }


where:

var FRONT_WALL_PLANE_NORMAL = [1, 0, 0];
var LEFT_WALL_PLANE_NORMAL = [0, 0, 1];
var RIGHT_WALL_PLANE_NORMAL = [0, 0, -1];



When I try to move it along a single wall at a time, it works perfectly. But when I put them all together it obviously takes only only one condition because of the way I've structured my if statements.

Is there a better way of doing this movement along the wall? Is there some way I can find the object that the ray from the camera is intersecting? Sorry if this sounds more like a programming question…
10 March 2016 15:24
Yes, you're right, it worked fine. I had to change the pivot of my object for it to work correctly! Thank you!
10 March 2016 08:58
In your Furnishing the room demo, we are trying to place objects by line_plane_intersect on the floor. However, if i want to do the same for the ceiling, How would it be possible?

var point = m_util.line_plane_intersect(FLOOR_PLANE_NORMAL, 0,
                        cam_trans, camera_ray, _vec3_tmp3);


Here the FLOOR_PLANE_NORMAL has the value [0, 1, 0]. If I define another value called CEILING_PLANE_NORMAL with the value [0,-1, 0], it doesnt seem to work with the following call :

m_util.line_plane_intersect(CEILING_PLANE_NORMAL, 1.63189,
                        cam_trans, camera_ray, _vec3_tmp3);


This could be a mistake in my calculation but an explanation would be great
02 March 2016 09:05
Ok, great! I will try to implement what you suggested. Thank you
29 February 2016 12:41
To get the rotation of my camera, I've been using :

cam_rotation = m_trans.get_rotation(cam);


This is returning a quaternion. However, I need this rotation value back into blender to set the rotation of a new camera. Is there a simple way for me to do this?
25 February 2016 13:22
I see! Thanks for your explanation!! Makes sense to me now
25 February 2016 12:20

m_scenes.get_object_by_name(_objs.name, m_scenes.DATA_ID_ALL);

Yes!!! That worked, thank you so much. Could you please explain why I had to do this for it to work?
25 February 2016 11:28
Oh right, sorry.

It returns - ItaliaMateArmchairMain
Same as before.

Could it be a problem with my .blend file?
25 February 2016 08:19
It prints the following:

B4W ERROR: get object ItaliaMateArmchairMain: not found
TypeError: a is undefined
23 February 2016 11:38
I can give you a more detailed example:

var obname = "ItaliaMateArmchairMain";
    var _objs = [];
    _objs = m_scenes.get_all_objects("MESH");


    for(var i = 0 ; i < _objs.length; ++i)
    {
        if(_objs[i].name == obname) {
            console.log(_objs[i].name);
            var materials = m_mat.get_materials_names(m_scenes.get_object_by_name(_objs[i].name));
            console.log(materials);
        }
    }


Here I'm searching for an object with name - obname. And _objs is storing all the objects in the scene. I am then looking for the object in the array and printing its name out. Please check the screenshot attached. The objects is found and its name is printed. But when I use get_object_by_name() it says that its not found.

Any help would be appreciated. :)