Preserving a blender camera's up vector.
2 posters
Preserving a blender camera's up vector.
Hi Everyone,
I noticed that the up vector for cameras is hard coded to z-up (as of version 1.3.1). If you roll your Blender camera or point it straight down, you're likely to have issues. So I decided to hack the exporter and loading code. It seems to be working perfectly for me so I thought I'd share:
On line 554 in the exporter, right before the "CLOSE CAMERA" block insert this:
Then load the up vector using this modified function from sio2_camera.cc; note case 6 and the added "up" token.
-Greg
I noticed that the up vector for cameras is hard coded to z-up (as of version 1.3.1). If you roll your Blender camera or point it straight down, you're likely to have issues. So I decided to hack the exporter and loading code. It seems to be working perfectly for me so I thought I'd share:
On line 554 in the exporter, right before the "CLOSE CAMERA" block insert this:
- Code:
#================================
# UP POSITION
#================================
up = ( Blender.Mathutils.Vector( 0.0, 1.0, 0.0, 0.0 ) * obj.matrixWorld )
buffer = "\tup( %s %s %s )\n" % ( optimize_float( up[0] ),
optimize_float( up[1] ),
optimize_float( up[2] ) )
f.write( buffer )
Then load the up vector using this modified function from sio2_camera.cc; note case 6 and the added "up" token.
- Code:
unsigned char sio2CameraLoad( char *_root,
char *_tok,
char *_val )
{
unsigned int i = 0;
static const unsigned int n_token = 7;
static char *token[ n_token ] = { "pos", "tar", "fov", "cstart", "cend", "iponame", "up" };
if( !*_tok )
{
char name[ SIO2_MAX_CHAR ] = {""};
sio2StringScanf( _val, "%s", name );
sio2->_SIO2camera = sio2CameraInit( name );
return 1;
}
while( i != n_token )
{
if( !sio2StringCmp( _tok, token[ i ] ) )
{ break; }
++i;
}
switch( i )
{
case 0:
{
sio2StringScanf( _val, "%f%f%f", &sio2->_SIO2camera->pos->x,
&sio2->_SIO2camera->pos->y,
&sio2->_SIO2camera->pos->z );
return 1;
}
case 1:
{
sio2StringScanf( _val, "%f%f%f", &sio2->_SIO2camera->tar->x,
&sio2->_SIO2camera->tar->y,
&sio2->_SIO2camera->tar->z );
return 1;
}
case 2:
{
sio2StringScanf( _val, "%f", &sio2->_SIO2camera->fov );
return 1;
}
case 3:
{
sio2StringScanf( _val, "%f", &sio2->_SIO2camera->cstart );
return 1;
}
case 4:
{
sio2StringScanf( _val, "%f", &sio2->_SIO2camera->cend );
return 1;
}
case 5:
{
sio2StringScanf( _val, "%s", sio2->_SIO2camera->iponame );
return 1;
}
case 6:
{
sio2StringScanf( _val, "%f%f%f", &sio2->_SIO2camera->up->x,
&sio2->_SIO2camera->up->y,
&sio2->_SIO2camera->up->z );
return 1;
}
}
return 0;
}
-Greg
gtmacdonald- Posts : 9
Join date : 2008-12-11
Re: Preserving a blender camera's up vector.
Looking good to me I will add it in 1.3.2... Tks for you contribution!
Cheers,
Cheers,
Re: Preserving a blender camera's up vector.
Hummmm actually testing your thing I found that its basically wrong... the vector is not normalized and when looking straight down the Y axis the up vector should be 0.0f, 0.0f, 1.0f, and if the camera Y rotation is 90 the up vector should be 0.0f, 1.0f, 0.0f etc...
Cheers,
Cheers,
Re: Preserving a blender camera's up vector.
Oh, damn. I thought I had tested it enough. If I figure out a fix I'll repost. Sorry about that...
-Greg
-Greg
gtmacdonald- Posts : 9
Join date : 2008-12-11
Re: Preserving a blender camera's up vector.
I think I needed to normalize and divide by w before. Hopefully this one will work better.
-Greg
- Code:
#================================
# UP POSITION
#================================
m = obj.matrixWorld.rotationPart()
m = m.invert()
m.transpose()
up = ( Blender.Mathutils.Vector( 0.0, 1.0, 0.0 ) * m )
up = up.normalize()
buffer = "\tup( %s %s %s )\n" % ( optimize_float( up[0] ),
optimize_float( up[1] ),
optimize_float( up[2] ) )
f.write( buffer )
-Greg
gtmacdonald- Posts : 9
Join date : 2008-12-11
Similar topics
» Blender Cameras
» a problem with blender, when i run the blender on leopard prompt "not enough VRAM"
» Blender Exporter v1.2 and up
» calculate an angle rotation from a direction vector
» Particle system - vel/dir vector attached to particle
» a problem with blender, when i run the blender on leopard prompt "not enough VRAM"
» Blender Exporter v1.2 and up
» calculate an angle rotation from a direction vector
» Particle system - vel/dir vector attached to particle
Permissions in this forum:
You cannot reply to topics in this forum