Rendered STL Camera Position

52 views
Skip to first unread message

TeamTeamUSA

unread,
Feb 13, 2010, 6:17:16 PM2/13/10
to thingiverse
I've uploaded a STL file created in OpenSCAD but when rendered on
Thingiverse the camera is too close to the object. How is the camera
position derived from the STL file?

I tried zooming out in OpenSCAD and uploading the STL; same camera
position. I'm using OpenSCAD 2010.02.06 (www.openscad.org).

Maybe the object is too small? It's 75 x 16 x 9 mm. You can see the
image here:
http://thingiverse-production.s3.amazonaws.com/renders/f0/b6/8d/d5/c9/DragKnife_Holder_YingYang_6mm_CameraTest_preview_large.jpg
Almost half the object is missing.

Any ideas?

Go!

=ml=

Marius Kintel

unread,
Feb 13, 2010, 7:11:14 PM2/13/10
to thing...@googlegroups.com
On Feb 14, 2010, at 00:17 , TeamTeamUSA wrote:

> I've uploaded a STL file created in OpenSCAD but when rendered on
> Thingiverse the camera is too close to the object. How is the camera
> position derived from the STL file?
>

The camera position is not (and can not be) stored in the STL file,
just the object itself.
Thingiverse positions the camera automatically, but it look like you
hit a weak point there.
Try scaling, rotating or moving the object around a bit - maybe you
find a the sweet spot, and hopefully this will be fixed in thingiverse
down the road.

~/= Marius

--
We are Elektropeople for a better living.


Zach 'Hoeken' Smith

unread,
Feb 17, 2010, 5:25:07 PM2/17/10
to thing...@googlegroups.com
Yeah, this is something that we attempt to automatically determine through code.  Unfortunately I don't have much of a 3D background, so I have no idea the proper way of doing it.  Here's the relevant code from Thingiverse.  If anyone has a better idea of how to automatically aim the camera and place the lights, please let me know.

PHP code from the renderer controller:

             //were does the camera go?
            $cam_x = $max_x * 2;
            $cam_y = $max_y * 2;
            $cam_z = $max_z * 2;

          //where are we looking?
            $look_x = ($max_x - $min_x)/2;
            $look_y = ($max_y - $min_y)/2;
            $look_z = ($max_z - $min_z)/2;#include "<?=$inc_path?>"
#include "<?=HOME_DIR?>/tools/povray/axes_macro.inc"

background {color rgb <0.9, 0.9, 0.9>}

light_source {
  <<?=$light1_x?>, <?=$light1_y?>, <?=$light1_z?>>
  color rgb <1,1,1>
  jitter
}
light_source {
  <<?=$light2_x?>, <?=$light2_y?>, <?=$light2_z?>>
  color rgb <1.0, 1.0, 1.0>
  jitter
}

camera
{
    perspective
    location <<?=$cam_x?>, <?=$cam_y?>, <?=$cam_z?>>
    look_at <<?=$look_x?>, <?=$look_y?>, <?=$look_z?>>
}

//the coordinate grid and axes
Axes_Macro
(
    100,    // Axes_axesSize,    The distance from the origin to one of the grid's edges.    (float)
    50,        // Axes_majUnit,    The size of each large-unit square.    (float)
    10,        // Axes_minUnit,    The number of small-unit squares that make up a large-unit square.    (integer)
    0.005,    // Axes_thickRatio,    The thickness of the grid lines (as a factor of axesSize).    (float)
    on,        // Axes_aBool,        Turns the axes on/off. (boolean)
    on,        // Axes_mBool,        Turns the minor units on/off. (boolean)
    off,    // Axes_xBool,        Turns the plane perpendicular to the x-axis on/off.    (boolean)
    on,        // Axes_yBool,        Turns the plane perpendicular to the y-axis on/off.    (boolean)
    off        // Axes_zBool,        Turns the plane perpendicular to the z-axis on/off.    (boolean)
)

object
{
    Axes_Object
}

object
{
    m_<?=$object_name?>
    rotate -90*x
    texture
    {
        pigment {color rgb <0.1, 0.6, 0.1>}
        finish
        {
            ambient 0.15
            diffuse 0.85
            specular 0.3
        }
    }
}
           
            //try to make it a bit more generalized and robust.
            $max = max($max_x, $max_y, $max_z);
            $min = min($min_x, $min_y, $min_z);
            $cam = $max*2;
            $look = ($max - $min)/2;
           
            //what are our ranges
            $range_x = $max_x - $min_x;
            $range_y = $max_y - $min_y;
            $range_z = $max_z - $min_z;
           
            //what is our zero move?
            $move_x = $max_x - ($range_x/2);
            $move_y = $max_y - ($range_y/2);
            $move_z = -$min_z;

            //not sure what this does to light.
            //$light_x = ($max_x+1) / 2;
            //$light_y = ($max_y+1) / 2;
            //$light_z = $max_z * 2;

            // interesting - makes object appear to glow.
            //$light_x = $look_x;
            //$light_y = $look_y;
            //$light_z = $look_z;

            //rotate light 20 * z
            $i3d = new Image_3D();
            $rotation = $i3d->createMatrix('rotation', array(0, 20, 0));
            $light1 = new Image_3D_Point($cam, $cam, $cam);
            $light1->transform($rotation);

            $light1_x = $light1->getX();
            $light1_y = $light1->getY();
            $light1_z = $light1->getZ();

            //rotate light -20 * z
            $i3d = new Image_3D();
            $rotation = $i3d->createMatrix('rotation', array(0, -20, 0));
            $light2 = new Image_3D_Point($cam, $cam, $cam);
            $light2->transform($rotation);

            $light2_x = $light2->getX();
            $light2_y = $light2->getY();
            $light2_z = $light2->getZ();

php code from the renderer view (which generates a povray file)

#include "<?=$inc_path?>"
#include "<?=HOME_DIR?>/tools/povray/axes_macro.inc"

background {color rgb <0.9, 0.9, 0.9>}

light_source {
  <<?=$light1_x?>, <?=$light1_y?>, <?=$light1_z?>>
  color rgb <1,1,1>
  jitter
}
light_source {
  <<?=$light2_x?>, <?=$light2_y?>, <?=$light2_z?>>
  color rgb <1.0, 1.0, 1.0>
  jitter
}

camera
{
    perspective
    location <<?=$cam_x?>, <?=$cam_y?>, <?=$cam_z?>>
    look_at <<?=$look_x?>, <?=$look_y?>, <?=$look_z?>>
}

//the coordinate grid and axes
Axes_Macro
(
    100,    // Axes_axesSize,    The distance from the origin to one of the grid's edges.    (float)
    50,        // Axes_majUnit,    The size of each large-unit square.    (float)
    10,        // Axes_minUnit,    The number of small-unit squares that make up a large-unit square.    (integer)
    0.005,    // Axes_thickRatio,    The thickness of the grid lines (as a factor of axesSize).    (float)
    on,        // Axes_aBool,        Turns the axes on/off. (boolean)
    on,        // Axes_mBool,        Turns the minor units on/off. (boolean)
    off,    // Axes_xBool,        Turns the plane perpendicular to the x-axis on/off.    (boolean)
    on,        // Axes_yBool,        Turns the plane perpendicular to the y-axis on/off.    (boolean)
    off        // Axes_zBool,        Turns the plane perpendicular to the z-axis on/off.    (boolean)
)

object
{
    Axes_Object
}

object
{
    m_<?=$object_name?>
    rotate -90*x
    texture
    {
        pigment {color rgb <0.1, 0.6, 0.1>}
        finish
        {
            ambient 0.15
            diffuse 0.85
            specular 0.3
        }
    }
}


Zach






--
Go visit thingiverse at http://thingiverse.com and stay tuned to the blog at http://blog.thingiverse.com.

You received this message because you are subscribed to the Google
Groups "thingiverse" group.
To post to this group, send email to thing...@googlegroups.com
To unsubscribe from this group, send email to
thingiverse...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/thingiverse?hl=en

Marius Kintel

unread,
Feb 18, 2010, 8:52:02 AM2/18/10
to thing...@googlegroups.com
I'll try. I don't know PHP, so please expand my vector code to the
correct PHP syntax:

First of all, point the camera towards the center of the object:

> //where are we looking?
> $look_x = ($max_x - $min_x)/2;
> $look_y = ($max_y - $min_y)/2;
> $look_z = ($max_z - $min_z)/2;

then becomes

$cx = ($max_x + $min_x)/2;
$cy = ($max_y + $min_y)/2;
$cz = ($max_z + $min_z)/2;

(in vector form c = (max + min) / 2)

Second, we want to ensure that we see the entire object. One simple
way to estimate this is to encase the object in a sphere and make sure
we see the sphere. I assume that the image rendered is square and that
the default viewing angle in PovRay is 90 degrees. This assumtion
implies that the distance from the center of the object to the camera
equals the radius of this sphere. If we overestimate the sphere, we
should be ok.
vector code follows:

dim = (max - min) / 2; // dimension of our object
radius = sqrt(dimx^2 + dimy^2 + dimz^2); // Radius of our sphere,
overestimated
camdir = c - d; // viewing direction
camdir *= radius / sqrt(camdirx^2 + camdiry^2 + camdirz^2); // makes
the length of camdir equal the radius
campos = c - camdir; // New camera position
look = c // camera points towards this point

If objects still stick out of the view frustum (might happen in freak
cases I fear), multiply the radius with some small factor (e.g. 1.2).
Warning: Untested, but hope it helps

Reply all
Reply to author
Forward
0 new messages