28 #include "glm/gtc/type_ptr.hpp" 29 #include "glm/gtc/matrix_transform.hpp" 70 shadow(false), beaming(false), inheritcolor(false), rotatetexture(false),
71 isTransparent(false), hasTransparencyHint(false), transparencyHint(false),
72 data(0), dangly(0), skin(0) {
210 return absolutePosition;
252 float curX, curY, curZ;
284 if (!environmentMap.
empty()) {
334 for (std::list<ModelNode *>::iterator c =
_children.begin(); c !=
_children.end(); ++c) {
335 (*c)->setAlpha(alpha,
true);
341 bool hasTexture =
false;
345 bool hasAlpha =
true;
350 for (
size_t t = 0; t != textures.size(); t++) {
354 if (!textures[t].empty() && (textures[t] !=
"NULL")) {
363 if (
_mesh->
data->
textures[t].getTexture().getTXI().getFeatures().alphaMean == 1.0f)
369 if (!
_mesh->
data->
textures[t].getTexture().getTXI().getFeatures().bumpyShinyTexture.empty())
370 envMap =
_mesh->
data->
textures[t].getTexture().getTXI().getFeatures().bumpyShinyTexture;
371 if (!
_mesh->
data->
textures[t].getTexture().getTXI().getFeatures().envMapTexture.empty())
372 envMap =
_mesh->
data->
textures[t].getTexture().getTXI().getFeatures().envMapTexture;
382 if (!envMap.
empty()) {
414 for (VertexDecl::const_iterator vA = vertexDecl.begin(); vA != vertexDecl.end(); ++vA) {
416 if ((vA->index !=
VPOSITION) || (vA->type != GL_FLOAT))
419 const uint32 stride = MAX<uint32>(vA->size, vA->stride /
sizeof(float));
421 const float *vertexData =
reinterpret_cast<const float *
>(vA->pointer);
423 const float *vX = vertexData + 0;
424 const float *vY = vertexData + 1;
425 const float *vZ = vertexData + 2;
428 _boundBox.
add(vX[v * stride], vY[v * stride], vZ[v * stride]);
437 float minX, minY, minZ, maxX, maxY, maxZ;
441 _center[0] = minX + ((maxX - minX) / 2.0f);
442 _center[1] = minY + ((maxY - minY) / 2.0f);
443 _center[2] = minZ + ((maxZ - minZ) / 2.0f);
485 for (std::list<ModelNode *>::iterator c =
_children.begin(); c !=
_children.end(); ++c) {
486 (*c)->createAbsoluteBound(parentPosition);
501 modelPosition = glm::rotate(modelPosition,
532 for (std::list<ModelNode *>::iterator c =
_children.begin(); c !=
_children.end(); ++c)
533 (*c)->orderChildren();
541 for (
size_t t = 0; t < mesh.
data->
textures.size(); t++) {
547 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
551 for (
size_t t = 0; t < mesh.
data->
textures.size(); t++) {
557 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
572 for (
size_t t = 0; t < mesh.
data->
textures.size(); t++) {
579 for (
size_t t = 0; t < mesh.
data->
textures.size(); t++) {
599 for (
size_t t = 0; t < mesh.
data->
textures.size(); t++) {
604 glBlendFunc(GL_ONE, GL_ZERO);
608 for (
size_t t = 0; t < mesh.
data->
textures.size(); t++) {
616 glDisable(GL_ALPHA_TEST);
617 glBlendFunc(GL_ZERO, GL_ONE);
625 glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);
631 glEnable(GL_ALPHA_TEST);
632 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
646 glRotatef(
_rotation[0], 1.0f, 0.0f, 0.0f);
647 glRotatef(
_rotation[1], 0.0f, 1.0f, 0.0f);
648 glRotatef(
_rotation[2], 0.0f, 0.0f, 1.0f);
657 mesh = rootStateNode->
_mesh;
658 doRender = rootStateNode->
_render;
673 shouldRender =
false;
685 for (std::list<ModelNode *>::iterator c =
_children.begin(); c !=
_children.end(); ++c) {
745 for (std::list<ModelNode *>::iterator c =
_children.begin(); c !=
_children.end(); ++c) {
786 for (std::list<ModelNode *>::iterator c =
_children.begin(); c !=
_children.end(); ++c) {
792 glm::mat4 mine = parent;
795 mine = glm::rotate(mine,
801 if (
_render || showInvisible) {
805 glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
807 glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
810 glVertex3f(mine[3][0], mine[3][1], mine[3][2]);
814 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
817 glVertex3f(parent[3][0], parent[3][1], parent[3][2]);
818 glVertex3f(mine[3][0], mine[3][1], mine[3][2]);
822 for (std::list<ModelNode *>::iterator c =
_children.begin(); c !=
_children.end(); ++c)
823 (*c)->drawSkeleton(mine, showInvisible);
877 int stride = vb.
getSize() /
sizeof(float);
878 float *v =
reinterpret_cast<float *
>(vb.
getData());
879 for (
int i = 0; i < vertexCount; ++i) {
892 std::vector<ModelNode *> nodeChain;
894 nodeChain.push_back(node);
899 for (std::vector<ModelNode *>::reverse_iterator n = nodeChain.rbegin();
900 n != nodeChain.rend();
911 if (ori.
x != 0 || ori.
y != 0 || ori.
z != 0)
914 glm::vec3(ori.
x, ori.
y, ori.
z));
922 std::vector<ModelNode *> nodeChain;
924 nodeChain.push_back(node);
929 for (std::vector<ModelNode *>::reverse_iterator n = nodeChain.rbegin();
930 n != nodeChain.rend();
960 if (rootStateNode && rootStateNode !=
this) {
961 return rootStateNode->
_mesh;
980 if (rootStateNode && rootStateNode !=
this) {
1000 if (rootStateNode && rootStateNode !=
this) {
1059 if (textureCount == 0) {
1071 if (phandles[0].empty()) {
1084 uint32 materialFlags = 0;
1091 if (
_name ==
"Plane237") {
1113 materialName += penvmap->
getName();
1144 if (textureCount >= 1) {
1145 if (!phandles[0].empty()) {
1146 materialName += phandles[0].
getName();
1153 if (phandles[0].getTexture().getTXI().getFeatures().blending) {
1161 if (phandles[0].getTexture().getTXI().getFeatures().decal) {
1174 if (textureCount >= 2) {
1175 if (!phandles[1].empty()) {
1176 materialName +=
".";
1177 materialName += phandles[1].
getName();
1191 if (textureCount >= 3) {
1192 if (!phandles[2].empty()) {
1193 materialName +=
".";
1194 materialName += phandles[2].
getName();
1203 if (textureCount >= 4) {
1211 materialName += penvmap->
getName();
1236 surface =
SurfaceMan.getSurface(materialName);
1242 materialFlags &= ~Shader::ShaderMaterial::MATERIAL_OPAQUE;
1246 cripter.
genName(vertexShaderName);
1247 fragmentShaderName = vertexShaderName +
".frag";
1248 vertexShaderName +=
".vert";
1255 if (!vertexObject) {
1257 bool isGL3 =
GfxMan.isGL3();
1262 cripter.
build(isGL3, vertexStringFinal, fragmentStringFinal);
1276 sampler->
handle = *penvmap;
1279 if (textureCount >= 1) {
1280 if (!phandles[0].empty()) {
1282 sampler->
handle = phandles[0];
1286 if (textureCount >= 2) {
1287 if (!phandles[1].empty()) {
1289 sampler->
handle = phandles[1];
void setBufferedPosition(float x, float y, float z)
const Common::UString & getState() const
Return the name of the current state.
Generic image decoder interface.
void lockFrameIfVisible()
void setEnvironmentMap(const Common::UString &environmentMap="")
Change the environment map on this model node.
EnvironmentMapMode
The way the environment map is applied to a model node.
void build(bool isGL3, Common::UString &v_string, Common::UString &f_string)
static void renderGeometryEnvMappedOver(Mesh &mesh)
Only render transparent parts.
Common::BoundingBox _absoluteBoundBox
The model's box after translate/rotate.
Texture & getTexture() const
Not strictly speaking an input, but generated for an output.
An element of the front GUI.
void setInvisible(bool invisible)
Should the node never be rendered at all?
A class holding an UTF-8 string.
A standard diffuse texture.
#define TextureMan
Shortcut for accessing the texture manager.
uint32 getCount() const
Get vertex count.
void setPosition(float x, float y, float z)
Set the position of the node.
bool _orientationBuffered
VertexBuffer * getVertexBuffer()
#define SurfaceMan
Shortcut for accessing the shader manager.
Shader::ShaderRenderable * _shaderRenderable
float getDepth() const
Get the depth of the bounding box.
void loadTextures(const std::vector< Common::UString > &textures)
void * getVariableData(uint32 index) const
A reflective environment map.
The Aurora texture manager.
void getRotation(float &x, float &y, float &z) const
Get the rotation of the node.
std::list< ModelNode * > & getChildren()
Get the node's children.
void setBufferedOrientation(float x, float y, float z, float angle)
glm::mat4 _invBindPose
Inverse bind pose matrix used for animations.
float _rotation[3]
Node rotation.
bool _dirtyMesh
Mesh data needs updating.
float getHeight() const
Get the height of the node's bounding box.
void queueRender(const glm::mat4 &parentTransform)
void setParent(ModelNode *parent)
Set the node's parent.
void rotate(float x, float y, float z)
Rotate the node, relative to its current rotation.
Render hint; material has no transparency.
void unlockFrameIfVisible()
void lockFrameIfVisible()
Diffuse textures first, then blend the environment map in.
bool _render
Render the node?
void scale(float x, float y, float z)
Different to default blending. Maybe this should be extended one day.
TextureHandle * getEnvironmentMap(EnvironmentMapMode &mode)
void getPosition(float &x, float &y, float &z) const
Get the position of the node.
void declareSampler(ShaderDescriptor::Sampler sampler, ShaderDescriptor::SamplerType type)
bool isCubeMap() const
Is this image a cube map?
float _alpha
Alpha of the node, used if no _mesh is present in this node.
TextureHandle * getTextures(uint32 &count)
std::vector< VertexAttrib > VertexDecl
Vertex data layout.
A bounding box around 3D points.
void computeInverseBindPose()
void connect(ShaderDescriptor::Sampler sampler, ShaderDescriptor::Input input, ShaderDescriptor::Action action)
Connect an input to a sampler and an action.
float getAlpha()
Get the alpha (transparency) of the node.
const VertexDecl & getVertexDecl() const
Access vertex declaration.
void setFlags(uint32 flags)
const glm::mat4 & getOrigin() const
Environment map first, then blend the diffuse textures in.
Model * _model
The model this node belongs to.
void exceptionDispatcherWarning(const char *s,...)
Exception dispatcher that prints the exception as a warning, and adds another reason on top...
float getHeight() const
Get the height of the bounding box.
const ImageDecoder & getImage() const
Return the image.
float _scale[3]
Scale of the node.
void setAlpha(float alpha, bool isRecursive=true)
Set the alpha (transparency) of the node.
bool _dirtyRender
Rendering information needs updating.
void getMin(float &x, float &y, float &z) const
Basic exceptions to throw.
float _position[3]
Model's position.
Not strictly speaking an input, but generated for an output.
Graphics::Aurora::TextureHandle handle
void computeAbsoluteTransform()
Utility templates and functions.
void getMax(float &x, float &y, float &z) const
void setRotation(float x, float y, float z)
Set the rotation of the node.
float getWidth() const
Get the width of the bounding box.
void unlockFrameIfVisible()
TextureHandle envMap
The environment map texture.
float getWidth() const
Get the width of the node's bounding box.
bool _vertexCoordsBuffered
glm::mat4 _renderTransform
Not really blending, but component-wise multiply.
static bool nodeComp(ModelNode *a, ModelNode *b)
virtual void buildMaterial()
static bool renderableMesh(Mesh *mesh)
glm::mat4 _absoluteTransform
Absolute transformation matrix used for animations.
void createAbsoluteBound()
A node within a 3D model.
Material definitely has transparency.
float getDepth() const
Get the depth of the node's bounding box.
uint32 getSize() const
Get vertex element size in bytes.
The global shader material manager.
bool empty() const
Is the string empty?
The global shader surface manager.
void setMaterial(Shader::ShaderMaterial *material)
Buffer containing vertex data.
#define MaterialMan
Shortcut for accessing the shader material manager.
std::vector< QuaternionKeyFrame > _orientationFrames
Keyframes for orientation animation.
bool isInFrontOf(const ModelNode &node) const
Is this node in front of that other node?
void absolutize()
Apply the origin transformations directly to the coordinates.
float _position[3]
Position of the node.
void rotate(float angle, float x, float y, float z)
static void renderGeometry(Mesh &mesh)
void render(RenderPass pass)
std::vector< TextureHandle > textures
Textures.
void renderImmediate(const glm::mat4 &parentTransform)
float _scale[3]
Model's scale.
void renderBind()
Follows the steps of renderImmediate, but broken into different functions.
Material definitely has transparency.
void render(RenderPass pass)
Render the object.
void add(float x, float y, float z)
float _orientation[4]
Model's orientation.
Shader sampler is used to bind a texture to a texture unit.
Common::BoundingBox _boundBox
void createBound()
Create the model's bounding box.
Graphics::Mesh::Mesh * rawMesh
Node raw mesh data.
void inheritPosition(ModelNode &node) const
Common::UString _name
The node's name.
std::vector< Shader::ShaderRenderable > _renderableArray
Damn you bioware.
A texture as used in the Aurora engines.
Blending not applicable to the component.
EnvironmentMapMode envMapMode
The way the environment map is applied.
#define ShaderMan
Shortcut for accessing the shader manager.
void genName(Common::UString &n_string)
Generate a name to asscoiate with the current description.
static glm::mat4 inverse(const glm::mat4 &m)
glm::mat4 getAbsolutePosition() const
Get the position of the node after translate/rotate.
void setEnvironmentMap(const Common::UString &environmentMap="")
Change the environment map on this model.
GLvoid * getData()
Access buffer data.
float _orientation[4]
Orientation of the node.
float _orientationBuffer[4]
const Common::UString & getName() const
Get the node's name.
void move(float x, float y, float z)
Move the node, relative to its current position.
void addPass(ShaderDescriptor::Action action, ShaderDescriptor::Blend blend)
glm::mat4 _absolutePosition
std::vector< float > _vertexCoordsBuffer
ModelNode * _rootStateNode
static void renderGeometryEnvMappedUnder(Mesh &mesh)
ModelType getType() const
Return the model's type.
uint16 getNodeNumber() const
std::list< ModelNode * > _children
The node's children.
const Common::UString & getName() const
Common::BoundingBox _absoluteBoundBox
std::vector< PositionKeyFrame > _positionFrames
Keyframes for position animation.
void declareInput(ShaderDescriptor::Input input)
glm::mat4 _absolutePosition
Position of the node after translate/rotate.
const Common::BoundingBox & getAbsoluteBound() const
void calcRenderTransform(const glm::mat4 &parentTransform)
Calculate the transform used for rendering.
void queueRender(const glm::mat4 &parentTransform)
Queue the object for later rendering.
ModelNode * getParent()
Get the node's parent.
ModelNode * _parent
The node's parent.
Model * _attachedModel
The model that is attached to this node.
float _center[3]
The node's center.
ModelNode * getNode(const Common::UString &node)
Get the specified node, from the current state.
void updateGL()
Update existing GL buffer object.
static float deg2rad(float deg)
void translate(float x, float y, float z)
void getOrientation(float &x, float &y, float &z, float &a) const
Get the orientation of the node.
#define GfxMan
Shortcut for accessing the graphics manager.
Only render opaque parts.
void renderImmediate(const glm::mat4 &parentTransform)
For shader based systems, don't sort anything, render this right_now.
Shader::ShaderMaterial * _material
void drawSkeleton(const glm::mat4 &parent, bool showInvisible)
static void renderGeometryNormal(Mesh &mesh)
void setOrientation(float x, float y, float z, float a)
Set the orientation of the node.
void setMaterial(Shader::ShaderMaterial *material, bool rebuildProgram=true)
void setTextures(const std::vector< Common::UString > &textures)
Set textures to the node.
#define RenderMan
Shortcut for accessing the render manager.
void inheritOrientation(ModelNode &node) const