Implemented support for triangle strip format in KRModel
Implemented stock cube and sphere models Implemented visualization of bones --HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40190
This commit is contained in:
@@ -182,6 +182,14 @@
|
||||
E4BBBB9E1512A4AE00F43B5B /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4BBBB961512A46700F43B5B /* AppKit.framework */; };
|
||||
E4BBBB9F1512A4B100F43B5B /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4BBBB941512A45500F43B5B /* Cocoa.framework */; };
|
||||
E4BBBBA71512A6DC00F43B5B /* KRVector3.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017F13C99BDC0098455B /* KRVector3.cpp */; };
|
||||
E4C454AC167BB8EC003586CD /* KRModelCube.h in Headers */ = {isa = PBXBuildFile; fileRef = E4C454AB167BB8EC003586CD /* KRModelCube.h */; };
|
||||
E4C454AD167BB8EC003586CD /* KRModelCube.h in Headers */ = {isa = PBXBuildFile; fileRef = E4C454AB167BB8EC003586CD /* KRModelCube.h */; };
|
||||
E4C454AF167BB8FC003586CD /* KRModelCube.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C454AE167BB8FC003586CD /* KRModelCube.cpp */; };
|
||||
E4C454B0167BB8FC003586CD /* KRModelCube.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C454AE167BB8FC003586CD /* KRModelCube.cpp */; };
|
||||
E4C454B2167BC04C003586CD /* KRModelSphere.h in Headers */ = {isa = PBXBuildFile; fileRef = E4C454B1167BC04B003586CD /* KRModelSphere.h */; };
|
||||
E4C454B3167BC04C003586CD /* KRModelSphere.h in Headers */ = {isa = PBXBuildFile; fileRef = E4C454B1167BC04B003586CD /* KRModelSphere.h */; };
|
||||
E4C454B5167BC05C003586CD /* KRModelSphere.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C454B4167BC05C003586CD /* KRModelSphere.cpp */; };
|
||||
E4C454B6167BC05C003586CD /* KRModelSphere.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C454B4167BC05C003586CD /* KRModelSphere.cpp */; };
|
||||
E4CA10E51637BD0A005D9400 /* KRTexturePVR.h in Headers */ = {isa = PBXBuildFile; fileRef = E4CA10E41637BD0A005D9400 /* KRTexturePVR.h */; };
|
||||
E4CA10E61637BD0A005D9400 /* KRTexturePVR.h in Headers */ = {isa = PBXBuildFile; fileRef = E4CA10E41637BD0A005D9400 /* KRTexturePVR.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
E4CA10E91637BD2B005D9400 /* KRTexturePVR.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4CA10E81637BD2B005D9400 /* KRTexturePVR.cpp */; };
|
||||
@@ -377,6 +385,10 @@
|
||||
E4BBBB961512A46700F43B5B /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = ../../../../MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
|
||||
E4BBBB981512A47500F43B5B /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = ../../../../MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
|
||||
E4BBBB9A1512A48200F43B5B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = ../../../../MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
|
||||
E4C454AB167BB8EC003586CD /* KRModelCube.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRModelCube.h; path = Classes/KRModelCube.h; sourceTree = "<group>"; };
|
||||
E4C454AE167BB8FC003586CD /* KRModelCube.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRModelCube.cpp; path = Classes/KRModelCube.cpp; sourceTree = "<group>"; };
|
||||
E4C454B1167BC04B003586CD /* KRModelSphere.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRModelSphere.h; path = Classes/KRModelSphere.h; sourceTree = "<group>"; };
|
||||
E4C454B4167BC05C003586CD /* KRModelSphere.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRModelSphere.cpp; path = Classes/KRModelSphere.cpp; sourceTree = "<group>"; };
|
||||
E4CA10E41637BD0A005D9400 /* KRTexturePVR.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRTexturePVR.h; path = Classes/KRTexturePVR.h; sourceTree = "<group>"; };
|
||||
E4CA10E81637BD2B005D9400 /* KRTexturePVR.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRTexturePVR.cpp; path = Classes/KRTexturePVR.cpp; sourceTree = "<group>"; };
|
||||
E4CA10EB1637BD47005D9400 /* KRTextureTGA.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRTextureTGA.h; path = Classes/KRTextureTGA.h; sourceTree = "<group>"; };
|
||||
@@ -619,6 +631,10 @@
|
||||
E491018213C99BDC0098455B /* KRModelManager.cpp */,
|
||||
E491017A13C99BDC0098455B /* KRModel.h */,
|
||||
E491017913C99BDC0098455B /* KRModel.cpp */,
|
||||
E4C454AB167BB8EC003586CD /* KRModelCube.h */,
|
||||
E4C454AE167BB8FC003586CD /* KRModelCube.cpp */,
|
||||
E4C454B1167BC04B003586CD /* KRModelSphere.h */,
|
||||
E4C454B4167BC05C003586CD /* KRModelSphere.cpp */,
|
||||
);
|
||||
name = Model;
|
||||
sourceTree = "<group>";
|
||||
@@ -849,6 +865,8 @@
|
||||
E416AA9916713749000F6786 /* KRAnimationCurveManager.h in Headers */,
|
||||
E480BE681671C641004EC8AD /* KRBone.h in Headers */,
|
||||
104A335F1672D31C001C8BA6 /* KRCollider.h in Headers */,
|
||||
E4C454AC167BB8EC003586CD /* KRModelCube.h in Headers */,
|
||||
E4C454B2167BC04C003586CD /* KRModelSphere.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -909,6 +927,8 @@
|
||||
E461A169152E570700F2044A /* KRSpotLight.h in Headers */,
|
||||
E4324BA516444C0D0043185B /* KRParticleSystem.h in Headers */,
|
||||
E4324BAC16444DEF0043185B /* KRParticleSystemNewtonian.h in Headers */,
|
||||
E4C454AD167BB8EC003586CD /* KRModelCube.h in Headers */,
|
||||
E4C454B3167BC04C003586CD /* KRModelSphere.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -1044,6 +1064,8 @@
|
||||
E416AA9C1671375C000F6786 /* KRAnimationCurveManager.cpp in Sources */,
|
||||
E480BE6C1671C653004EC8AD /* KRBone.cpp in Sources */,
|
||||
104A335E1672D31C001C8BA6 /* KRCollider.cpp in Sources */,
|
||||
E4C454AF167BB8FC003586CD /* KRModelCube.cpp in Sources */,
|
||||
E4C454B5167BC05C003586CD /* KRModelSphere.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -1102,6 +1124,8 @@
|
||||
E428C31A1669A25D00A16EDF /* KRAnimationAttribute.cpp in Sources */,
|
||||
E416AA9D1671375C000F6786 /* KRAnimationCurveManager.cpp in Sources */,
|
||||
E480BE6D1671C653004EC8AD /* KRBone.cpp in Sources */,
|
||||
E4C454B0167BB8FC003586CD /* KRModelCube.cpp in Sources */,
|
||||
E4C454B6167BC05C003586CD /* KRModelSphere.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -7,14 +7,15 @@
|
||||
//
|
||||
|
||||
#include "KRBone.h"
|
||||
#include "KRContext.h"
|
||||
|
||||
KRBone::KRBone(KRScene &scene, std::string name) : KRNode(scene, name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
KRBone::~KRBone()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string KRBone::getElementName() {
|
||||
@@ -32,3 +33,50 @@ void KRBone::loadXML(tinyxml2::XMLElement *e)
|
||||
{
|
||||
KRNode::loadXML(e);
|
||||
}
|
||||
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
void KRBone::render(KRCamera *pCamera, std::vector<KRLight *> &lights, const KRViewport &viewport, KRNode::RenderPass renderPass)
|
||||
{
|
||||
|
||||
KRNode::render(pCamera, lights, viewport, renderPass);
|
||||
|
||||
bool bVisualize = true;
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) {
|
||||
KRMat4 sphereModelMatrix = getModelMatrix();
|
||||
|
||||
KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
|
||||
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, lights, 0, renderPass)) {
|
||||
|
||||
// Enable additive blending
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
|
||||
|
||||
|
||||
// Disable z-buffer write
|
||||
GLDEBUG(glDepthMask(GL_FALSE));
|
||||
|
||||
// Enable z-buffer test
|
||||
GLDEBUG(glEnable(GL_DEPTH_TEST));
|
||||
GLDEBUG(glDepthFunc(GL_LEQUAL));
|
||||
GLDEBUG(glDepthRangef(0.0, 1.0));
|
||||
|
||||
std::vector<KRModel *> sphereModels = getContext().getModelManager()->getModel("__sphere");
|
||||
if(sphereModels.size()) {
|
||||
for(int i=0; i < sphereModels[0]->getSubmeshCount(); i++) {
|
||||
sphereModels[0]->renderSubmesh(i);
|
||||
}
|
||||
}
|
||||
|
||||
// Enable alpha blending
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
GLDEBUG(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -20,8 +20,13 @@ public:
|
||||
virtual std::string getElementName();
|
||||
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
||||
virtual void loadXML(tinyxml2::XMLElement *e);
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
protected:
|
||||
void render(KRCamera *pCamera, std::vector<KRLight *> &lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -269,6 +269,18 @@ bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
|
||||
GLfloat *bone_mat_component = bone_mats;
|
||||
for(int bone_index=0; bone_index < bones.size(); bone_index++) {
|
||||
KRBone *bone = bones[bone_index];
|
||||
|
||||
// KRVector3 initialRotation = bone->getInitialLocalRotation();
|
||||
// KRVector3 rotation = bone->getLocalRotation();
|
||||
// KRVector3 initialTranslation = bone->getInitialLocalTranslation();
|
||||
// KRVector3 translation = bone->getLocalTranslation();
|
||||
// KRVector3 initialScale = bone->getInitialLocalScale();
|
||||
// KRVector3 scale = bone->getLocalScale();
|
||||
//
|
||||
//printf("%s - delta rotation: %.4f %.4f %.4f\n", bone->getName().c_str(), (rotation.x - initialRotation.x) * 180.0 / M_PI, (rotation.y - initialRotation.y) * 180.0 / M_PI, (rotation.z - initialRotation.z) * 180.0 / M_PI);
|
||||
//printf("%s - delta translation: %.4f %.4f %.4f\n", bone->getName().c_str(), translation.x - initialTranslation.x, translation.y - initialTranslation.y, translation.z - initialTranslation.z);
|
||||
// printf("%s - delta scale: %.4f %.4f %.4f\n", bone->getName().c_str(), scale.x - initialScale.x, scale.y - initialScale.y, scale.z - initialScale.z);
|
||||
|
||||
KRMat4 t = bone->getInverseBindPoseMatrix() * bone->getModelMatrix();
|
||||
for(int i=0; i < 16; i++) {
|
||||
*bone_mat_component++ = t[i];
|
||||
|
||||
@@ -261,7 +261,16 @@ void KRModel::renderSubmesh(int iSubmesh) {
|
||||
|
||||
if(iVertex + cVertexes >= MAX_VBO_SIZE) {
|
||||
assert(iVertex + (MAX_VBO_SIZE - iVertex) <= cBufferVertexes);
|
||||
switch (getModelFormat()) {
|
||||
case KRENGINE_MODEL_FORMAT_TRIANGLES:
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLES, iVertex, (MAX_VBO_SIZE - iVertex)));
|
||||
break;
|
||||
case KRENGINE_MODEL_FORMAT_STRIP:
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, iVertex, (MAX_VBO_SIZE - iVertex)));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
cVertexes -= (MAX_VBO_SIZE - iVertex);
|
||||
iVertex = 0;
|
||||
@@ -269,14 +278,24 @@ void KRModel::renderSubmesh(int iSubmesh) {
|
||||
} else {
|
||||
assert(iVertex + cVertexes <= cBufferVertexes);
|
||||
|
||||
switch (getModelFormat()) {
|
||||
case KRENGINE_MODEL_FORMAT_TRIANGLES:
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLES, iVertex, cVertexes));
|
||||
break;
|
||||
case KRENGINE_MODEL_FORMAT_STRIP:
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, iVertex, cVertexes));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
cVertexes = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void KRModel::LoadData(std::vector<KRVector3> vertices, std::vector<KRVector2> uva, std::vector<KRVector2> uvb, std::vector<KRVector3> normals, std::vector<KRVector3> tangents, std::vector<int> submesh_starts, std::vector<int> submesh_lengths, std::vector<std::string> material_names, std::vector<std::string> bone_names, std::vector<std::vector<int> > bone_indexes, std::vector<std::vector<float> > bone_weights) {
|
||||
void KRModel::LoadData(std::vector<KRVector3> vertices, std::vector<KRVector2> uva, std::vector<KRVector2> uvb, std::vector<KRVector3> normals, std::vector<KRVector3> tangents, std::vector<int> submesh_starts, std::vector<int> submesh_lengths, std::vector<std::string> material_names, std::vector<std::string> bone_names, std::vector<std::vector<int> > bone_indexes, std::vector<std::vector<float> > bone_weights, KRModel::model_format_t model_format) {
|
||||
|
||||
clearData();
|
||||
|
||||
@@ -317,6 +336,7 @@ void KRModel::LoadData(std::vector<KRVector3> vertices, std::vector<KRVector2> u
|
||||
pHeader->submesh_count = (__int32_t)submesh_count;
|
||||
pHeader->vertex_count = (__int32_t)vertex_count;
|
||||
pHeader->bone_count = (__int32_t)bone_count;
|
||||
pHeader->model_format = model_format;
|
||||
strcpy(pHeader->szTag, "KROBJPACK1.1 ");
|
||||
updateAttributeOffsets();
|
||||
|
||||
@@ -435,6 +455,8 @@ void KRModel::LoadData(std::vector<KRVector3> vertices, std::vector<KRVector2> u
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
optimize();
|
||||
}
|
||||
|
||||
KRVector3 KRModel::getMinPoint() const {
|
||||
@@ -680,3 +702,13 @@ char *KRModel::getBoneName(int bone_index)
|
||||
{
|
||||
return getBone(bone_index)->szName;
|
||||
}
|
||||
|
||||
void KRModel::optimize()
|
||||
{
|
||||
// TODO - Add algorithm to convert model to indexed vertices, identying vertexes with identical attributes and optimizing order of trianges for best usage post-vertex-transform cache on GPU
|
||||
}
|
||||
|
||||
KRModel::model_format_t KRModel::getModelFormat()
|
||||
{
|
||||
return (model_format_t)getHeader()->model_format;
|
||||
}
|
||||
|
||||
@@ -70,28 +70,6 @@ public:
|
||||
|
||||
bool hasTransparency();
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
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
|
||||
|
||||
std::string m_lodBaseName;
|
||||
|
||||
virtual std::string getExtension();
|
||||
virtual bool save(const std::string& path);
|
||||
|
||||
void LoadData(std::vector<KRVector3> vertices, std::vector<KRVector2> uva, std::vector<KRVector2> uvb, std::vector<KRVector3> normals, std::vector<KRVector3> tangents, std::vector<int> submesh_starts, std::vector<int> submesh_lengths, std::vector<std::string> material_names, std::vector<std::string> bone_names, std::vector<std::vector<int> > bone_indexes, std::vector<std::vector<float> > bone_weights);
|
||||
void loadPack(KRDataBlock *data);
|
||||
|
||||
|
||||
void renderSubmesh(int iSubmesh);
|
||||
|
||||
GLfloat getMaxDimension();
|
||||
|
||||
KRVector3 getMinPoint() const;
|
||||
KRVector3 getMaxPoint() const;
|
||||
|
||||
typedef enum {
|
||||
KRENGINE_ATTRIB_VERTEX = 0,
|
||||
KRENGINE_ATTRIB_NORMAL,
|
||||
@@ -104,10 +82,36 @@ public:
|
||||
} vertex_attrib_t;
|
||||
|
||||
typedef enum {
|
||||
KRENGINE_MODEL_FORMAT_TRIANGLES = 1,
|
||||
KRENGINE_MODEL_FORMAT_INDEXED
|
||||
KRENGINE_MODEL_FORMAT_TRIANGLES = 0,
|
||||
KRENGINE_MODEL_FORMAT_STRIP,
|
||||
KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES,
|
||||
KRENGINE_MODEL_FORMAT_INDEXED_STRIP
|
||||
} model_format_t;
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
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
|
||||
|
||||
std::string m_lodBaseName;
|
||||
|
||||
virtual std::string getExtension();
|
||||
virtual bool save(const std::string& path);
|
||||
|
||||
void LoadData(std::vector<KRVector3> vertices, std::vector<KRVector2> uva, std::vector<KRVector2> uvb, std::vector<KRVector3> normals, std::vector<KRVector3> tangents, std::vector<int> submesh_starts, std::vector<int> submesh_lengths, std::vector<std::string> material_names, std::vector<std::string> bone_names, std::vector<std::vector<int> > bone_indexes, std::vector<std::vector<float> > bone_weights, model_format_t model_format);
|
||||
void loadPack(KRDataBlock *data);
|
||||
|
||||
|
||||
void renderSubmesh(int iSubmesh);
|
||||
|
||||
GLfloat getMaxDimension();
|
||||
|
||||
KRVector3 getMinPoint() const;
|
||||
KRVector3 getMaxPoint() const;
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
GLint start_vertex;
|
||||
GLsizei vertex_count;
|
||||
@@ -176,7 +180,11 @@ public:
|
||||
int getBoneCount();
|
||||
char *getBoneName(int bone_index);
|
||||
|
||||
|
||||
model_format_t getModelFormat();
|
||||
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)
|
||||
vector<KRMaterial *> m_materials;
|
||||
set<KRMaterial *> m_uniqueMaterials;
|
||||
@@ -188,9 +196,11 @@ private:
|
||||
|
||||
KRDataBlock *m_pData;
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
char szTag[16];
|
||||
int32_t format_type; // 0 == Triangle list, 1 == Indexed triangle list, 2 == Indexed triangle strips, rest are reserved (model_format_t enum)
|
||||
int32_t model_format; // 0 == Triangle list, 1 == Triangle strips, 2 == Indexed triangle list, 3 == Indexed triangle strips, rest are reserved (model_format_t enum)
|
||||
int32_t vertex_attrib_flags;
|
||||
int32_t vertex_count;
|
||||
int32_t submesh_count;
|
||||
@@ -209,6 +219,7 @@ private:
|
||||
void clearBuffers();
|
||||
|
||||
void setName(const std::string name);
|
||||
void optimize();
|
||||
|
||||
|
||||
|
||||
|
||||
76
KREngine/KREngine/Classes/KRModelCube.cpp
Normal file
76
KREngine/KREngine/Classes/KRModelCube.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// KRModelCube.cpp
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2012 Kearwood Gilbert. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The views and conclusions contained in the software and documentation are those of the
|
||||
// authors and should not be interpreted as representing official policies, either expressed
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#include "KRModelCube.h"
|
||||
|
||||
|
||||
KRModelCube::KRModelCube(KRContext &context) : KRModel(context, "__cube")
|
||||
{
|
||||
std::vector<KRVector3> vertices;
|
||||
std::vector<KRVector2> uva;
|
||||
std::vector<KRVector2> uvb;
|
||||
std::vector<KRVector3> normals;
|
||||
std::vector<KRVector3> tangents;
|
||||
std::vector<int> submesh_starts;
|
||||
std::vector<int> submesh_lengths;
|
||||
std::vector<std::string> material_names;
|
||||
std::vector<std::string> bone_names;
|
||||
std::vector<std::vector<int> > bone_indexes;
|
||||
std::vector<std::vector<float> > bone_weights;
|
||||
|
||||
|
||||
vertices.push_back(KRVector3(1.0, 1.0, 1.0));
|
||||
vertices.push_back(KRVector3(-1.0, 1.0, 1.0));
|
||||
vertices.push_back(KRVector3(1.0,-1.0, 1.0));
|
||||
vertices.push_back(KRVector3(-1.0,-1.0, 1.0));
|
||||
vertices.push_back(KRVector3(-1.0,-1.0,-1.0));
|
||||
vertices.push_back(KRVector3(-1.0, 1.0, 1.0));
|
||||
vertices.push_back(KRVector3(-1.0, 1.0,-1.0));
|
||||
vertices.push_back(KRVector3(1.0, 1.0, 1.0));
|
||||
vertices.push_back(KRVector3(1.0, 1.0,-1.0));
|
||||
vertices.push_back(KRVector3(1.0,-1.0, 1.0));
|
||||
vertices.push_back(KRVector3(1.0,-1.0,-1.0));
|
||||
vertices.push_back(KRVector3(-1.0,-1.0,-1.0));
|
||||
vertices.push_back(KRVector3(1.0, 1.0,-1.0));
|
||||
vertices.push_back(KRVector3(-1.0, 1.0,-1.0));
|
||||
|
||||
|
||||
submesh_starts.push_back(0);
|
||||
submesh_lengths.push_back(vertices.size());
|
||||
material_names.push_back("");
|
||||
|
||||
LoadData(vertices, uva, uvb, normals, tangents, submesh_starts, submesh_lengths, material_names, bone_names, bone_indexes, bone_weights, KRENGINE_MODEL_FORMAT_STRIP);
|
||||
}
|
||||
|
||||
KRModelCube::~KRModelCube()
|
||||
{
|
||||
|
||||
}
|
||||
44
KREngine/KREngine/Classes/KRModelCube.h
Normal file
44
KREngine/KREngine/Classes/KRModelCube.h
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// KRModelCube.h
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2012 Kearwood Gilbert. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The views and conclusions contained in the software and documentation are those of the
|
||||
// authors and should not be interpreted as representing official policies, either expressed
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#ifndef KRMODELCUBE_H
|
||||
#define KRMODELCUBE_H
|
||||
|
||||
#include "KRModel.h"
|
||||
|
||||
class KRModelCube : public KRModel {
|
||||
public:
|
||||
KRModelCube(KRContext &context);
|
||||
virtual ~KRModelCube();
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -33,6 +33,8 @@
|
||||
#include <assert.h>
|
||||
|
||||
#import "KRModel.h"
|
||||
#import "KRModelCube.h"
|
||||
#import "KRModelSphere.h"
|
||||
|
||||
KRModelManager::KRModelManager(KRContext &context) : KRContextObject(context) {
|
||||
m_currentVBO.vbo_handle = 0;
|
||||
@@ -41,6 +43,9 @@ KRModelManager::KRModelManager(KRContext &context) : KRContextObject(context) {
|
||||
m_vboMemUsed = 0;
|
||||
m_randomParticleVertexData = NULL;
|
||||
m_volumetricLightingVertexData = NULL;
|
||||
|
||||
addModel(new KRModelCube(context));
|
||||
addModel(new KRModelSphere(context));
|
||||
}
|
||||
|
||||
KRModelManager::~KRModelManager() {
|
||||
@@ -60,11 +65,14 @@ KRModel *KRModelManager::loadModel(const char *szName, KRDataBlock *pData) {
|
||||
|
||||
|
||||
KRModel *pModel = new KRModel(*m_pContext, lowerName, pData);
|
||||
m_models.insert(std::pair<std::string, KRModel *>(pModel->getLODBaseName(), pModel));
|
||||
|
||||
addModel(pModel);
|
||||
return pModel;
|
||||
}
|
||||
|
||||
void KRModelManager::addModel(KRModel *model) {
|
||||
m_models.insert(std::pair<std::string, KRModel *>(model->getLODBaseName(), model));
|
||||
}
|
||||
|
||||
std::vector<KRModel *> KRModelManager::getModel(const char *szName) {
|
||||
std::string lowerName = szName;
|
||||
std::transform(lowerName.begin(), lowerName.end(),
|
||||
|
||||
@@ -55,6 +55,7 @@ public:
|
||||
|
||||
KRModel *loadModel(const char *szName, KRDataBlock *pData);
|
||||
std::vector<KRModel *> getModel(const char *szName);
|
||||
void addModel(KRModel *model);
|
||||
|
||||
std::vector<std::string> getModelNames();
|
||||
std::multimap<std::string, KRModel *> getModels();
|
||||
|
||||
143
KREngine/KREngine/Classes/KRModelSphere.cpp
Normal file
143
KREngine/KREngine/Classes/KRModelSphere.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
//
|
||||
// KRModelSphere.cpp
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2012 Kearwood Gilbert. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The views and conclusions contained in the software and documentation are those of the
|
||||
// authors and should not be interpreted as representing official policies, either expressed
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#include "KRModelSphere.h"
|
||||
|
||||
|
||||
KRModelSphere::KRModelSphere(KRContext &context) : KRModel(context, "__sphere")
|
||||
{
|
||||
std::vector<KRVector3> vertices;
|
||||
std::vector<KRVector2> uva;
|
||||
std::vector<KRVector2> uvb;
|
||||
std::vector<KRVector3> normals;
|
||||
std::vector<KRVector3> tangents;
|
||||
std::vector<int> submesh_starts;
|
||||
std::vector<int> submesh_lengths;
|
||||
std::vector<std::string> material_names;
|
||||
std::vector<std::string> bone_names;
|
||||
std::vector<std::vector<int> > bone_indexes;
|
||||
std::vector<std::vector<float> > bone_weights;
|
||||
|
||||
|
||||
|
||||
// Create a triangular facet approximation to a sphere
|
||||
// Based on algorithm from Paul Bourke: http://paulbourke.net/miscellaneous/sphere_cylinder/
|
||||
|
||||
int iterations = 3;
|
||||
int facet_count = pow(4, iterations) * 8;
|
||||
|
||||
class Facet3 {
|
||||
public:
|
||||
Facet3() {
|
||||
|
||||
}
|
||||
~Facet3() {
|
||||
|
||||
}
|
||||
KRVector3 p1;
|
||||
KRVector3 p2;
|
||||
KRVector3 p3;
|
||||
};
|
||||
|
||||
std::vector<Facet3> f = std::vector<Facet3>(facet_count);
|
||||
|
||||
int i,it;
|
||||
float a;
|
||||
KRVector3 p[6] = {
|
||||
KRVector3(0,0,1),
|
||||
KRVector3(0,0,-1),
|
||||
KRVector3(-1,-1,0),
|
||||
KRVector3(1,-1,0),
|
||||
KRVector3(1,1,0),
|
||||
KRVector3(-1,1,0)
|
||||
};
|
||||
|
||||
KRVector3 pa,pb,pc;
|
||||
int nt = 0,ntold;
|
||||
|
||||
/* Create the level 0 object */
|
||||
a = 1 / sqrt(2.0);
|
||||
for (i=0;i<6;i++) {
|
||||
p[i].x *= a;
|
||||
p[i].y *= a;
|
||||
}
|
||||
f[0].p1 = p[0]; f[0].p2 = p[3]; f[0].p3 = p[4];
|
||||
f[1].p1 = p[0]; f[1].p2 = p[4]; f[1].p3 = p[5];
|
||||
f[2].p1 = p[0]; f[2].p2 = p[5]; f[2].p3 = p[2];
|
||||
f[3].p1 = p[0]; f[3].p2 = p[2]; f[3].p3 = p[3];
|
||||
f[4].p1 = p[1]; f[4].p2 = p[4]; f[4].p3 = p[3];
|
||||
f[5].p1 = p[1]; f[5].p2 = p[5]; f[5].p3 = p[4];
|
||||
f[6].p1 = p[1]; f[6].p2 = p[2]; f[6].p3 = p[5];
|
||||
f[7].p1 = p[1]; f[7].p2 = p[3]; f[7].p3 = p[2];
|
||||
nt = 8;
|
||||
|
||||
/* Bisect each edge and move to the surface of a unit sphere */
|
||||
for (it=0;it<iterations;it++) {
|
||||
ntold = nt;
|
||||
for (i=0;i<ntold;i++) {
|
||||
pa.x = (f[i].p1.x + f[i].p2.x) / 2;
|
||||
pa.y = (f[i].p1.y + f[i].p2.y) / 2;
|
||||
pa.z = (f[i].p1.z + f[i].p2.z) / 2;
|
||||
pb.x = (f[i].p2.x + f[i].p3.x) / 2;
|
||||
pb.y = (f[i].p2.y + f[i].p3.y) / 2;
|
||||
pb.z = (f[i].p2.z + f[i].p3.z) / 2;
|
||||
pc.x = (f[i].p3.x + f[i].p1.x) / 2;
|
||||
pc.y = (f[i].p3.y + f[i].p1.y) / 2;
|
||||
pc.z = (f[i].p3.z + f[i].p1.z) / 2;
|
||||
pa.normalize();
|
||||
pb.normalize();
|
||||
pc.normalize();
|
||||
f[nt].p1 = f[i].p1; f[nt].p2 = pa; f[nt].p3 = pc; nt++;
|
||||
f[nt].p1 = pa; f[nt].p2 = f[i].p2; f[nt].p3 = pb; nt++;
|
||||
f[nt].p1 = pb; f[nt].p2 = f[i].p3; f[nt].p3 = pc; nt++;
|
||||
f[i].p1 = pa;
|
||||
f[i].p2 = pb;
|
||||
f[i].p3 = pc;
|
||||
}
|
||||
}
|
||||
|
||||
for(int facet_index=0; facet_index < facet_count; facet_index++) {
|
||||
vertices.push_back(f[facet_index].p1);
|
||||
vertices.push_back(f[facet_index].p2);
|
||||
vertices.push_back(f[facet_index].p3);
|
||||
}
|
||||
|
||||
submesh_starts.push_back(0);
|
||||
submesh_lengths.push_back(vertices.size());
|
||||
material_names.push_back("");
|
||||
|
||||
LoadData(vertices, uva, uvb, normals, tangents, submesh_starts, submesh_lengths, material_names, bone_names, bone_indexes, bone_weights, KRENGINE_MODEL_FORMAT_TRIANGLES);
|
||||
}
|
||||
|
||||
KRModelSphere::~KRModelSphere()
|
||||
{
|
||||
|
||||
}
|
||||
44
KREngine/KREngine/Classes/KRModelSphere.h
Normal file
44
KREngine/KREngine/Classes/KRModelSphere.h
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// KRModelSphere.h
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2012 Kearwood Gilbert. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The views and conclusions contained in the software and documentation are those of the
|
||||
// authors and should not be interpreted as representing official policies, either expressed
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#ifndef KRMODELSPHERE_H
|
||||
#define KRMODELSPHERE_H
|
||||
|
||||
#include "KRModel.h"
|
||||
|
||||
class KRModelSphere : public KRModel {
|
||||
public:
|
||||
KRModelSphere(KRContext &context);
|
||||
virtual ~KRModelSphere();
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -145,6 +145,16 @@ const KRVector3 &KRNode::getLocalRotation() {
|
||||
return m_localRotation;
|
||||
}
|
||||
|
||||
const KRVector3 &KRNode::getInitialLocalTranslation() {
|
||||
return m_initialLocalTranslation;
|
||||
}
|
||||
const KRVector3 &KRNode::getInitialLocalScale() {
|
||||
return m_initialLocalScale;
|
||||
}
|
||||
const KRVector3 &KRNode::getInitialLocalRotation() {
|
||||
return m_initialLocalRotation;
|
||||
}
|
||||
|
||||
const KRVector3 &KRNode::getWorldTranslation() {
|
||||
return m_localTranslation;
|
||||
}
|
||||
@@ -311,42 +321,42 @@ void KRNode::SetAttribute(node_attribute_type attrib, float v)
|
||||
{
|
||||
const float DEGREES_TO_RAD = M_PI / 180.0f;
|
||||
|
||||
printf("%s - ", m_name.c_str());
|
||||
//printf("%s - ", m_name.c_str());
|
||||
switch(attrib) {
|
||||
case KRENGINE_NODE_ATTRIBUTE_TRANSLATE_X:
|
||||
printf("translate_x: %f\n", v);
|
||||
//printf("translate_x: %f\n", v);
|
||||
setLocalTranslation(KRVector3(v, m_localTranslation.y, m_localTranslation.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_TRANSLATE_Y:
|
||||
printf("translate_y: %f\n", v);
|
||||
//printf("translate_y: %f\n", v);
|
||||
setLocalTranslation(KRVector3(m_localTranslation.x, v, m_localTranslation.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_TRANSLATE_Z:
|
||||
printf("translate_z: %f\n", v);
|
||||
//printf("translate_z: %f\n", v);
|
||||
setLocalTranslation(KRVector3(m_localTranslation.x, m_localTranslation.y, v));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_SCALE_X:
|
||||
printf("scale_x: %f\n", v);
|
||||
//printf("scale_x: %f\n", v);
|
||||
setLocalScale(KRVector3(v, m_localScale.y, m_localScale.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_SCALE_Y:
|
||||
printf("scale_y: %f\n", v);
|
||||
//printf("scale_y: %f\n", v);
|
||||
setLocalScale(KRVector3(m_localScale.x, v, m_localScale.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_SCALE_Z:
|
||||
printf("scale_z: %f\n", v);
|
||||
//printf("scale_z: %f\n", v);
|
||||
setLocalScale(KRVector3(m_localScale.x, m_localScale.y, v));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_ROTATE_X:
|
||||
printf("rotate_x: %f\n", v);
|
||||
//printf("rotate_x: %f\n", v);
|
||||
setLocalRotation(KRVector3(v * DEGREES_TO_RAD, m_localRotation.y, m_localRotation.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_ROTATE_Y:
|
||||
printf("rotate_y: %f\n", v);
|
||||
//printf("rotate_y: %f\n", v);
|
||||
setLocalRotation(KRVector3(m_localRotation.x, v * DEGREES_TO_RAD, m_localRotation.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_ROTATE_Z:
|
||||
printf("rotate_z: %f\n", v);
|
||||
//printf("rotate_z: %f\n", v);
|
||||
setLocalRotation(KRVector3(m_localRotation.x, m_localRotation.y, v * DEGREES_TO_RAD));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -63,6 +63,10 @@ public:
|
||||
const KRVector3 &getLocalScale();
|
||||
const KRVector3 &getLocalRotation();
|
||||
|
||||
const KRVector3 &getInitialLocalTranslation();
|
||||
const KRVector3 &getInitialLocalScale();
|
||||
const KRVector3 &getInitialLocalRotation();
|
||||
|
||||
const KRVector3 &getWorldTranslation();
|
||||
const KRVector3 &getWorldScale();
|
||||
const KRVector3 &getWorldRotation();
|
||||
|
||||
@@ -338,7 +338,7 @@ std::vector<KRResource *> KRResource::LoadObj(KRContext &context, const std::str
|
||||
std::vector<std::vector<int> > bone_indexes;
|
||||
std::vector<std::vector<float> > bone_weights;
|
||||
|
||||
new_mesh->LoadData(vertices, uva, uvb, normals, tangents, submesh_starts, submesh_lengths, material_names, bone_names, bone_indexes, bone_weights);
|
||||
new_mesh->LoadData(vertices, uva, uvb, normals, tangents, submesh_starts, submesh_lengths, material_names, bone_names, bone_indexes, bone_weights, KRModel::KRENGINE_MODEL_FORMAT_TRIANGLES);
|
||||
}
|
||||
|
||||
if(pFaces) {
|
||||
|
||||
@@ -166,23 +166,27 @@ void main()
|
||||
{
|
||||
#if BONE_COUNT > 0
|
||||
mediump vec4 scaled_bone_indexes = bone_indexes;
|
||||
mediump vec4 scaled_bone_weights = bone_weights;
|
||||
|
||||
// scaled_bone_indexes = vec4(1.0, 0.0, 0.0, 0.0);
|
||||
// scaled_bone_weights = vec4(1.0, 0.0, 0.0, 0.0);
|
||||
highp vec3 vertex_position_skinned =
|
||||
((bone_transforms[ int(scaled_bone_indexes.x) ] * vec4(vertex_position, 1.0)).xyz * bone_weights.x) +
|
||||
((bone_transforms[ int(scaled_bone_indexes.y) ] * vec4(vertex_position, 1.0)).xyz * bone_weights.y) +
|
||||
((bone_transforms[ int(scaled_bone_indexes.z) ] * vec4(vertex_position, 1.0)).xyz * bone_weights.z) +
|
||||
((bone_transforms[ int(scaled_bone_indexes.w) ] * vec4(vertex_position, 1.0)).xyz * bone_weights.w);
|
||||
((bone_transforms[ int(scaled_bone_indexes.x) ] * vec4(vertex_position, 1.0)).xyz * scaled_bone_weights.x) +
|
||||
((bone_transforms[ int(scaled_bone_indexes.y) ] * vec4(vertex_position, 1.0)).xyz * scaled_bone_weights.y) +
|
||||
((bone_transforms[ int(scaled_bone_indexes.z) ] * vec4(vertex_position, 1.0)).xyz * scaled_bone_weights.z) +
|
||||
((bone_transforms[ int(scaled_bone_indexes.w) ] * vec4(vertex_position, 1.0)).xyz * scaled_bone_weights.w);
|
||||
|
||||
highp vec3 vertex_normal_skinned = normalize(
|
||||
((bone_transforms[ int(scaled_bone_indexes.x) ] * vec4(vertex_normal, 1.0)).xyz * bone_weights.x) +
|
||||
((bone_transforms[ int(scaled_bone_indexes.y) ] * vec4(vertex_normal, 1.0)).xyz * bone_weights.y) +
|
||||
((bone_transforms[ int(scaled_bone_indexes.z) ] * vec4(vertex_normal, 1.0)).xyz * bone_weights.z) +
|
||||
((bone_transforms[ int(scaled_bone_indexes.w) ] * vec4(vertex_normal, 1.0)).xyz * bone_weights.w));
|
||||
((bone_transforms[ int(scaled_bone_indexes.x) ] * vec4(vertex_normal, 1.0)).xyz * scaled_bone_weights.x) +
|
||||
((bone_transforms[ int(scaled_bone_indexes.y) ] * vec4(vertex_normal, 1.0)).xyz * scaled_bone_weights.y) +
|
||||
((bone_transforms[ int(scaled_bone_indexes.z) ] * vec4(vertex_normal, 1.0)).xyz * scaled_bone_weights.z) +
|
||||
((bone_transforms[ int(scaled_bone_indexes.w) ] * vec4(vertex_normal, 1.0)).xyz * scaled_bone_weights.w));
|
||||
|
||||
highp vec3 vertex_tangent_skinned = normalize(
|
||||
((bone_transforms[ int(scaled_bone_indexes.x) ] * vec4(vertex_tangent, 1.0)).xyz * bone_weights.x) +
|
||||
((bone_transforms[ int(scaled_bone_indexes.y) ] * vec4(vertex_tangent, 1.0)).xyz * bone_weights.y) +
|
||||
((bone_transforms[ int(scaled_bone_indexes.z) ] * vec4(vertex_tangent, 1.0)).xyz * bone_weights.z) +
|
||||
((bone_transforms[ int(scaled_bone_indexes.w) ] * vec4(vertex_tangent, 1.0)).xyz * bone_weights.w));
|
||||
((bone_transforms[ int(scaled_bone_indexes.x) ] * vec4(vertex_tangent, 1.0)).xyz * scaled_bone_weights.x) +
|
||||
((bone_transforms[ int(scaled_bone_indexes.y) ] * vec4(vertex_tangent, 1.0)).xyz * scaled_bone_weights.y) +
|
||||
((bone_transforms[ int(scaled_bone_indexes.z) ] * vec4(vertex_tangent, 1.0)).xyz * scaled_bone_weights.z) +
|
||||
((bone_transforms[ int(scaled_bone_indexes.w) ] * vec4(vertex_tangent, 1.0)).xyz * scaled_bone_weights.w));
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user