Corrected bone names in krobject file format
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40186
This commit is contained in:
@@ -66,9 +66,29 @@ tinyxml2::XMLElement *KRInstance::saveXML( tinyxml2::XMLNode *parent)
|
|||||||
|
|
||||||
void KRInstance::loadModel() {
|
void KRInstance::loadModel() {
|
||||||
if(m_models.size() == 0) {
|
if(m_models.size() == 0) {
|
||||||
m_models = m_pContext->getModelManager()->getModel(m_model_name.c_str()); // The model manager returns the LOD levels in sorted order, with the highest detail first
|
std::vector<KRModel *> models = m_pContext->getModelManager()->getModel(m_model_name.c_str()); // The model manager returns the LOD levels in sorted order, with the highest detail first
|
||||||
if(m_models.size() > 0) {
|
std::map<KRModel *, std::vector<KRBone *> > bones;
|
||||||
getScene().notify_sceneGraphModify(this);
|
if(models.size() > 0) {
|
||||||
|
bool all_bones_found = true;
|
||||||
|
for(std::vector<KRModel *>::iterator model_itr = models.begin(); model_itr != models.end(); model_itr++) {
|
||||||
|
KRModel *model = *model_itr;
|
||||||
|
std::vector<KRBone *> model_bones;
|
||||||
|
int bone_count = model->getBoneCount();
|
||||||
|
for(int bone_index=0; bone_index < bone_count; bone_index++) {
|
||||||
|
KRBone *matching_bone = dynamic_cast<KRBone *>(getScene().getRootNode()->findChild(model->getBoneName(bone_index)));
|
||||||
|
if(matching_bone) {
|
||||||
|
model_bones.push_back(matching_bone);
|
||||||
|
} else {
|
||||||
|
all_bones_found = false; // Reject when there are any missing bones or multiple matches
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bones[model] = model_bones;
|
||||||
|
}
|
||||||
|
if(all_bones_found) {
|
||||||
|
m_models = models;
|
||||||
|
m_bones = bones;
|
||||||
|
getScene().notify_sceneGraphModify(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,7 +137,7 @@ void KRInstance::render(KRCamera *pCamera, std::vector<KRLight *> &lights, const
|
|||||||
matModel = KRQuaternion(KRVector3::Forward(), KRVector3::Normalize(camera_pos - model_center)).rotationMatrix() * matModel;
|
matModel = KRQuaternion(KRVector3::Forward(), KRVector3::Normalize(camera_pos - model_center)).rotationMatrix() * matModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
pModel->render(pCamera, lights, viewport, matModel, m_pLightMap, renderPass);
|
pModel->render(pCamera, lights, viewport, matModel, m_pLightMap, renderPass, m_bones[pModel]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@
|
|||||||
#import "KRContext.h"
|
#import "KRContext.h"
|
||||||
#import "KRModel.h"
|
#import "KRModel.h"
|
||||||
#import "KRTexture.h"
|
#import "KRTexture.h"
|
||||||
|
#import "KRBone.h"
|
||||||
|
|
||||||
class KRInstance : public KRNode {
|
class KRInstance : public KRNode {
|
||||||
|
|
||||||
@@ -68,6 +69,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<KRModel *> m_models;
|
std::vector<KRModel *> m_models;
|
||||||
|
std::map<KRModel *, std::vector<KRBone *> > m_bones; // Outer std::map connects model to set of bones
|
||||||
KRTexture *m_pLightMap;
|
KRTexture *m_pLightMap;
|
||||||
std::string m_lightMap;
|
std::string m_lightMap;
|
||||||
std::string m_model_name;
|
std::string m_model_name;
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ void KRModel::loadPack(KRDataBlock *data) {
|
|||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
|
|
||||||
void KRModel::render(KRCamera *pCamera, std::vector<KRLight *> &lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass) {
|
void KRModel::render(KRCamera *pCamera, std::vector<KRLight *> &lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector<KRBone *> &bones) {
|
||||||
|
|
||||||
//fprintf(stderr, "Rendering model: %s\n", m_name.c_str());
|
//fprintf(stderr, "Rendering model: %s\n", m_name.c_str());
|
||||||
if(renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) {
|
if(renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) {
|
||||||
@@ -480,7 +480,7 @@ KRModel::pack_header *KRModel::getHeader() const
|
|||||||
KRModel::pack_bone *KRModel::getBone(int index)
|
KRModel::pack_bone *KRModel::getBone(int index)
|
||||||
{
|
{
|
||||||
pack_header *header = getHeader();
|
pack_header *header = getHeader();
|
||||||
return (pack_bone *)((unsigned char *)m_pData->getStart()) + sizeof(pack_header) + sizeof(pack_material) * header->submesh_count;
|
return (pack_bone *)((unsigned char *)m_pData->getStart() + sizeof(pack_header) + sizeof(pack_material) * header->submesh_count + sizeof(pack_bone) * index);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *KRModel::getVertexData() const {
|
unsigned char *KRModel::getVertexData() const {
|
||||||
@@ -669,3 +669,14 @@ size_t KRModel::AttributeOffset(__int32_t vertex_attrib, __int32_t vertex_attrib
|
|||||||
}
|
}
|
||||||
return VertexSizeForAttributes(mask);
|
return VertexSizeForAttributes(mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int KRModel::getBoneCount()
|
||||||
|
{
|
||||||
|
pack_header *header = getHeader();
|
||||||
|
return header->bone_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *KRModel::getBoneName(int bone_index)
|
||||||
|
{
|
||||||
|
return getBone(bone_index)->szName;
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
#import <string>
|
#import <string>
|
||||||
#import "KRVector2.h"
|
#import "KRVector2.h"
|
||||||
#import "KRContext.h"
|
#import "KRContext.h"
|
||||||
|
#import "KRBone.h"
|
||||||
|
|
||||||
#import "KREngine-common.h"
|
#import "KREngine-common.h"
|
||||||
|
|
||||||
@@ -71,7 +72,7 @@ public:
|
|||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
|
|
||||||
void render(KRCamera *pCamera, std::vector<KRLight *> &lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass);
|
void render(KRCamera *pCamera, std::vector<KRLight *> &lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector<KRBone *> &bones);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -171,6 +172,9 @@ public:
|
|||||||
|
|
||||||
static size_t VertexSizeForAttributes(__int32_t vertex_attrib_flags);
|
static size_t VertexSizeForAttributes(__int32_t vertex_attrib_flags);
|
||||||
static size_t AttributeOffset(__int32_t vertex_attrib, __int32_t vertex_attrib_flags);
|
static size_t AttributeOffset(__int32_t vertex_attrib, __int32_t vertex_attrib_flags);
|
||||||
|
|
||||||
|
int getBoneCount();
|
||||||
|
char *getBoneName(int bone_index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_lodCoverage; // This LOD level is activated when the bounding box of the model will cover less than this percent of the screen (100 = highest detail model)
|
int m_lodCoverage; // This LOD level is activated when the bounding box of the model will cover less than this percent of the screen (100 = highest detail model)
|
||||||
|
|||||||
Reference in New Issue
Block a user