Scaling a mounted ShapeBaseImage
by Konrad Kiss · 07/02/2009 (10:40 pm) · 24 comments
To be able to set your weapon's scale without having to re-export it, do the following:
First, in shapeBase.h find (in the ShapeBaseImageData struct)
and after that insert:
Next, in shapeImage.cpp, add to the ShapeBaseImageData constructor:
Still in the same file, find ShapeBaseImageData::initPersistFields() and add at the end of the method:
In the ShapeBaseImageData::packData method, add at the end:
In the ShapeBaseImageData::unpackData method, add at the end:
In shapeBase.cpp's ShapeBase::prepBatchRender find the following:
and replace with this:
Finally, some scripting: in your weapon's (or any other mounted image's) ShapeBaseImageData datablock, add a scale property (defaults to Point3F(1,1,1) if not set, which means no further scaling) and set it's value to the desired scale.
You're done, now you can scale any of your mounted objects. Tested only in Torque3D.
Update (07/30/2009): Updated the resource to make it networked.
Update (09/25/2009): Updated code to reflect changes to a getRenderImageTransform call from Beta 5.
First, in shapeBase.h find (in the ShapeBaseImageData struct)
/// Maximum number of sounds this image can play at a time. /// Any value <= 0 indicates that it can play an infinite number of sounds. S32 maxConcurrentSounds;
and after that insert:
// >>> // custom mounted image scaling Point3F scale; // <<<
Next, in shapeImage.cpp, add to the ShapeBaseImageData constructor:
// >>> scale = Point3F(1,1,1); // <<<
Still in the same file, find ShapeBaseImageData::initPersistFields() and add at the end of the method:
// >>>
addField("scale", TypePoint3F, Offset(scale, ShapeBaseImageData));
// <<<In the ShapeBaseImageData::packData method, add at the end:
// >>> mathWrite( *stream, scale ); // <<<
In the ShapeBaseImageData::unpackData method, add at the end:
// >>> mathRead( *stream, &scale ); // <<<
In shapeBase.cpp's ShapeBase::prepBatchRender find the following:
MatrixF mat;
getRenderImageTransform(mountedImageIndex, &mat, state->isShadowPass());
GFX->setWorldMatrix( mat );
image.shapeInstance->animate();
image.shapeInstance->render( rdata );and replace with this:
MatrixF mat;
getRenderImageTransform(mountedImageIndex, &mat, state->isShadowPass());
GFX->setWorldMatrix( mat );
image.shapeInstance->animate();
// >>>
MatrixF s(true);
s.scale( image.dataBlock->scale );
GFX->multWorld( s );
// <<<
image.shapeInstance->render( rdata );Finally, some scripting: in your weapon's (or any other mounted image's) ShapeBaseImageData datablock, add a scale property (defaults to Point3F(1,1,1) if not set, which means no further scaling) and set it's value to the desired scale.
You're done, now you can scale any of your mounted objects. Tested only in Torque3D.
Update (07/30/2009): Updated the resource to make it networked.
Update (09/25/2009): Updated code to reflect changes to a getRenderImageTransform call from Beta 5.
About the author
See www.bitgap.com.
#22
I had to make the change inside Player::renderMountedImage() to get it to work and left the changes in ShapeBase::renderMountedImage() for good measure (not sure if that was required).
ShapeBase::renderMountedImage (in shapeBase.cpp) looks like this:
...and the last few lines of Player::renderMountedImage() (in player.cpp) look like this:
10/20/2009 (1:47 am)
Works in T3D v1.0.1 with no problems at all - it even updates in realtime in the datablock editor (when the stock offset and rotation do not!).I had to make the change inside Player::renderMountedImage() to get it to work and left the changes in ShapeBase::renderMountedImage() for good measure (not sure if that was required).
ShapeBase::renderMountedImage (in shapeBase.cpp) looks like this:
void ShapeBase::renderMountedImage( U32 imageSlot, TSRenderState &rstate )
{
GFX->pushWorldMatrix();
MatrixF mat;
getRenderImageTransform(imageSlot, &mat, rstate.getSceneState()->isShadowPass());
GFX->setWorldMatrix(mat);
MountedImage& image = mMountedImageList[imageSlot];
image.shapeInstance->animate();
MatrixF s(true);
s.scale(image.dataBlock->scale);
GFX->multWorld(s);
image.shapeInstance->render(rstate);
GFX->popWorldMatrix();
}...and the last few lines of Player::renderMountedImage() (in player.cpp) look like this:
else
{
getRenderMountTransform(data.mountPoint,&nmat);
world.mul(nmat,data.mountTransform);
}
GFX->setWorldMatrix( world );
image.shapeInstance->animate();
MatrixF s(true);
s.scale(image.dataBlock->scale);
GFX->multWorld(s);
image.shapeInstance->render( rstate );
GFX->popWorldMatrix();
}
#24
I copied and pasted all codes and examined several times.
But still doesn't work.
11/10/2009 (3:59 am)
Anyone has run the code in the T3D v1.0.1?I copied and pasted all codes and examined several times.
But still doesn't work.
Torque 3D Owner Michael Chew
Pray tell how would one modify the Player::renderMountedImage()?
Im not too bright when it comes to modifying the source.