Skip to content

Commit

Permalink
Adding skeletons to models.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlitty committed Aug 18, 2017
1 parent 512242f commit ce83106
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
8 changes: 8 additions & 0 deletions modules/engine/include/randar/Render/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace randar
protected:
Geometry* geo;
ShaderProgram* program;
Skeleton* skel;

public:
/**
Expand Down Expand Up @@ -43,6 +44,13 @@ namespace randar
void shaderProgram(ShaderProgram& newProgram);
ShaderProgram& shaderProgram();
bool hasShaderProgram() const;

/**
* Sets and retrieves the skeleton applied to the model.
*/
void skeleton(Skeleton& skeleton);
Skeleton& skeleton();
bool hasSkeleton() const;
};

/**
Expand Down
15 changes: 10 additions & 5 deletions modules/engine/src/Render/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,19 @@ void randar::Canvas::draw(randar::Model& model, randar::LightCollection& lights)
return;
}

ShaderProgram* program;
randar::DrawState state;
state.transform = &model;
state.lights = &lights;

if (model.hasSkeleton()) {
state.skeleton = &model.skeleton();
}

if (model.hasShaderProgram()) {
program = &model.shaderProgram();
} else {
program = &this->framebuffer().context().defaultShaderProgram();
state.program = &model.shaderProgram();
}

this->draw(model.geometry(), model, lights, *program);
this->draw(model.geometry(), state);
}

// Draws a world to the canvas.
Expand Down
19 changes: 19 additions & 0 deletions modules/engine/src/Render/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ bool randar::Model::hasShaderProgram() const
return this->program != nullptr;
}

// Sets and retrieves the skeleton applied to the model.
void randar::Model::skeleton(randar::Skeleton& skeleton)
{
this->skel = &skeleton;
}

randar::Skeleton& randar::Model::skeleton()
{
if (!this->hasSkeleton()) {
throw std::runtime_error("Model has no skeleton");
}
return *this->skel;
}

bool randar::Model::hasSkeleton() const
{
return this->skel != nullptr;
}

// Node.js helper for intuitive model creation.
randar::Model randar::model()
{
Expand Down

0 comments on commit ce83106

Please sign in to comment.