Skip to content

Commit

Permalink
Model Renderer|Definitions: Added "autoscale" to model metadata
Browse files Browse the repository at this point in the history
By default, models are autoscaled to their Thing height.
  • Loading branch information
skyjake committed Jul 20, 2015
1 parent a110e1d commit c48cf8e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions doomsday/apps/client/include/render/modelrenderer.h
Expand Up @@ -53,6 +53,7 @@ class ModelRenderer
{
StateAnims animations;
de::Matrix4f transformation;
bool autoscaleToThingHeight = true;
};

public:
Expand Down
5 changes: 5 additions & 0 deletions doomsday/apps/client/src/render/modelrenderer.cpp
Expand Up @@ -33,6 +33,7 @@ static String const DEF_ANIMATION ("animation");
static String const DEF_MATERIAL ("material");
static String const DEF_UP_VECTOR ("up");
static String const DEF_FRONT_VECTOR("front");
static String const DEF_AUTOSCALE ("autoscale");

DENG2_PIMPL(ModelRenderer)
, DENG2_OBSERVES(filesys::AssetObserver, Availability)
Expand Down Expand Up @@ -201,6 +202,10 @@ DENG2_PIMPL(ModelRenderer)
up = Vector3f(asset.geta(DEF_UP_VECTOR));
}
aux->transformation = Matrix4f::unnormalizedFrame(front, up);
if(asset.has(DEF_AUTOSCALE))
{
aux->autoscaleToThingHeight = !ScriptedInfo::isFalse(asset.get(DEF_AUTOSCALE));
}

// Custom texture maps.
if(asset.has(DEF_MATERIAL))
Expand Down
9 changes: 6 additions & 3 deletions doomsday/apps/client/src/world/clientmobjthinkerdata.cpp
Expand Up @@ -103,13 +103,16 @@ DENG2_PIMPL(ClientMobjThinkerData)
animator.reset(new MobjAnimator(modelId(), model));

// The basic transformation of the model.
modelMatrix = loaded.second->as<ModelRenderer::AuxiliaryData>().transformation;
auto const &aux = loaded.second->as<ModelRenderer::AuxiliaryData>();
modelMatrix = aux.transformation;

Vector3f dims = modelMatrix * model.dimensions();

// Scale to thing height.
// TODO: This should be optional (but the default behavior).
modelMatrix = Matrix4f::scale(self.mobj()->height / dims.y * 1.2f /*aspect correct*/) * modelMatrix;
if(aux.autoscaleToThingHeight)
{
modelMatrix = Matrix4f::scale(self.mobj()->height / dims.y * 1.2f /*aspect correct*/) * modelMatrix;
}
}
}

Expand Down

0 comments on commit c48cf8e

Please sign in to comment.