Forum

Using distance from camera to scale an object?

01 November 2015 05:49
Hello,

Here's one I've been scratching my head on.

Can I get the distance from camera to object (in the running web app) and use that value to scale an object. For example, if the camera is 100 feet from the object, the scale of the object is 100, but if the camera is zoomed in to 10 feet from the object the object scale dynamically decreases to 10 also.

An simple example file would very helpful from anyone out here. I find I can learn best with the source coding to pick apart. And I am definitely a beginner so seeing simple full code helps.

Thanks in advance!

02 November 2015 10:27
Hi,

Distance from the camera to an object can obtained as follows:
var obj_pos = m_trans.get_object_center(obj);
var cam_eye = m_cam.get_eye(camobj);
var dist = m_vec3.dist(obj_pos, cam_eye);

Objects can be scaled with the following method:
m_trans.set_scale(obj, factor);

Hope this helps!
The Founder | Twitter | Facebook | Linkedin
19 May 2016 03:03
is there a way to do this same thing using logic nodes?
19 May 2016 10:44

is there a way to do this same thing using logic nodes?
Hello!
For now there is no functionality to get the distance from camera to object using only logic nodes without coding. But you can do it with "JS Callback" node, which can use functions prepared in javascript part of your application (in this case function will be similiar to the one in Yuri's answer).

Scale can be changed via "Transform Object" node.
Blend4Web Team - developer
Twitter
LinkedIn
 
Please register or log in to leave a reply.