From cc78975349f37745146d1d925d10730625e367db Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Sat, 27 Jul 2013 14:57:50 -0700 Subject: [PATCH 01/12] Fixed an issue that caused some textures to be unloaded permanently when streaming a world. This manifested itself in cases where a texture unit would hold only a single texture for many frames, such as in scenes where only one object had a normal map in view. --HG-- extra : source : 5b9b6d6d1c0f9d35490f0739670d729fb6ea1c9c --- KREngine/kraken/KRTextureManager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/KREngine/kraken/KRTextureManager.cpp b/KREngine/kraken/KRTextureManager.cpp index e6fb8f5..c81d104 100644 --- a/KREngine/kraken/KRTextureManager.cpp +++ b/KREngine/kraken/KRTextureManager.cpp @@ -63,6 +63,7 @@ void KRTextureManager::_clearGLState() m_wrapModeS[i] = 0; m_wrapModeT[i] = 0; m_maxAnisotropy[i] = -1.0f; + selectTexture(i, NULL); } m_iActiveTexture = -1; From 0efee25da89f8e66e26f79c9a8e78015d28e635e Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Sat, 24 Aug 2013 16:37:07 -0700 Subject: [PATCH 02/12] Implemented animation splitting --HG-- extra : source : e2686eec48ec9fa9da4359ce8fb75efa6ebba62c --- KREngine/kraken/KRAnimation.cpp | 82 ++++++++++++++++++++- KREngine/kraken/KRAnimation.h | 7 ++ KREngine/kraken/KRAnimationAttribute.cpp | 10 +++ KREngine/kraken/KRAnimationAttribute.h | 2 + KREngine/kraken/KRAnimationCurve.cpp | 43 ++++++++++- KREngine/kraken/KRAnimationCurve.h | 5 ++ KREngine/kraken/KRAnimationCurveManager.cpp | 5 ++ KREngine/kraken/KRAnimationCurveManager.h | 2 + KREngine/kraken/KRAnimationManager.cpp | 9 +++ KREngine/kraken/KRAnimationManager.h | 1 + 10 files changed, 162 insertions(+), 4 deletions(-) diff --git a/KREngine/kraken/KRAnimation.cpp b/KREngine/kraken/KRAnimation.cpp index 47ea76b..1be1203 100644 --- a/KREngine/kraken/KRAnimation.cpp +++ b/KREngine/kraken/KRAnimation.cpp @@ -28,7 +28,8 @@ // authors and should not be interpreted as representing official policies, either expressed // or implied, of Kearwood Gilbert. // - +#include +#include #include "KRAnimation.h" #include "KRAnimationManager.h" #include "KRContext.h" @@ -44,6 +45,7 @@ KRAnimation::KRAnimation(KRContext &context, std::string name) : KRResource(cont m_playing = false; m_local_time = 0.0f; m_duration = 0.0f; + m_start_time = 0.0f; } KRAnimation::~KRAnimation() { @@ -68,6 +70,7 @@ bool KRAnimation::save(KRDataBlock &data) { animation_node->SetAttribute("loop", m_loop ? "true" : "false"); animation_node->SetAttribute("auto_play", m_auto_play ? "true" : "false"); animation_node->SetAttribute("duration", m_duration); + animation_node->SetAttribute("start_time", m_start_time); for(unordered_map::iterator itr = m_layers.begin(); itr != m_layers.end(); ++itr){ (*itr).second->saveXML(animation_node); @@ -93,6 +96,10 @@ KRAnimation *KRAnimation::Load(KRContext &context, const std::string &name, KRDa new_animation->m_duration = 0.0f; // Default value } + if(animation_node->QueryFloatAttribute("start_time", &new_animation->m_start_time) != tinyxml2::XML_SUCCESS) { + new_animation->m_start_time = 0.0f; // Default value + } + if(animation_node->QueryBoolAttribute("loop", &new_animation->m_loop) != tinyxml2::XML_SUCCESS) { new_animation->m_loop = false; // Default value } @@ -157,9 +164,9 @@ void KRAnimation::update(float deltaTime) KRNode::node_attribute_type attribute_type = attribute->getTargetAttribute(); if(curve != NULL && target != NULL) { - int frame_number = (int)(m_local_time * curve->getFrameRate()); + int frame_number = (int)((m_local_time + m_start_time) * curve->getFrameRate()); if(frame_number < curve->getFrameStart()) { - target->SetAttribute(attribute_type, curve->getValue(0)); + target->SetAttribute(attribute_type, curve->getValue(m_start_time)); } else if(frame_number - curve->getFrameStart() >= curve->getFrameCount()) { target->SetAttribute(attribute_type, curve->getValue(curve->getFrameCount() - 1)); } else { @@ -203,6 +210,16 @@ void KRAnimation::setDuration(float duration) m_duration = duration; } +float KRAnimation::getStartTime() +{ + return m_start_time; +} + +void KRAnimation::setStartTime(float start_time) +{ + m_start_time = start_time; +} + bool KRAnimation::isPlaying() { return m_playing; @@ -227,3 +244,62 @@ void KRAnimation::setLooping(bool looping) { m_loop = looping; } + +KRAnimation *KRAnimation::split(const std::string &name, float start_time, float duration, bool strip_unchanging_attributes, bool clone_curves) +{ + KRAnimation *new_animation = new KRAnimation(getContext(), name); + new_animation->setStartTime(start_time); + new_animation->setDuration(duration); + new_animation->m_loop = m_loop; + new_animation->m_auto_play = m_auto_play; + int new_curve_count = 0; + for(unordered_map::iterator layer_itr = m_layers.begin(); layer_itr != m_layers.end(); layer_itr++) { + KRAnimationLayer *layer = (*layer_itr).second; + KRAnimationLayer *new_layer = new KRAnimationLayer(getContext()); + new_layer->setName(layer->getName()); + new_layer->setRotationAccumulationMode(layer->getRotationAccumulationMode()); + new_layer->setScaleAccumulationMode(layer->getScaleAccumulationMode()); + new_layer->setWeight(layer->getWeight()); + new_animation->m_layers[new_layer->getName()] = new_layer; + for(std::vector::iterator attribute_itr = layer->getAttributes().begin(); attribute_itr != layer->getAttributes().end(); attribute_itr++) { + KRAnimationAttribute *attribute = *attribute_itr; + KRAnimationCurve *curve = attribute->getCurve(); + if(curve != NULL) { + bool include_attribute = true; + if(strip_unchanging_attributes) { + if(!curve->valueChanges(start_time, duration)) { + include_attribute = false; + } + } + + if(include_attribute) { + KRAnimationAttribute *new_attribute = new KRAnimationAttribute(getContext()); + KRAnimationCurve *new_curve = curve; + if(clone_curves) { + std::string new_curve_name = name + "_curve" + boost::lexical_cast(++new_curve_count); + new_curve = curve->split(new_curve_name, start_time, duration); + } + + new_attribute->setCurveName(new_curve->getName()); + new_attribute->setTargetName(attribute->getTargetName()); + new_layer->addAttribute(new_attribute); + } + } + } + } + + getContext().getAnimationManager()->addAnimation(new_animation); + return new_animation; +} + +void KRAnimation::deleteCurves() +{ + for(unordered_map::iterator layer_itr = m_layers.begin(); layer_itr != m_layers.end(); layer_itr++) { + KRAnimationLayer *layer = (*layer_itr).second; + for(std::vector::iterator attribute_itr = layer->getAttributes().begin(); attribute_itr != layer->getAttributes().end(); attribute_itr++) { + KRAnimationAttribute *attribute = *attribute_itr; + attribute->deleteCurve(); + } + } +} + diff --git a/KREngine/kraken/KRAnimation.h b/KREngine/kraken/KRAnimation.h index 38166a6..a052177 100644 --- a/KREngine/kraken/KRAnimation.h +++ b/KREngine/kraken/KRAnimation.h @@ -64,7 +64,13 @@ public: void setTime(float time); float getDuration(); void setDuration(float duration); + float getStartTime(); + void setStartTime(float start_time); bool isPlaying(); + + KRAnimation *split(const std::string &name, float start_time, float duration, bool strip_unchanging_attributes = true, bool clone_curves = true); + void deleteCurves(); + private: unordered_map m_layers; bool m_auto_play; @@ -72,6 +78,7 @@ private: bool m_playing; float m_local_time; float m_duration; + float m_start_time; }; diff --git a/KREngine/kraken/KRAnimationAttribute.cpp b/KREngine/kraken/KRAnimationAttribute.cpp index 48d3943..9133f6a 100644 --- a/KREngine/kraken/KRAnimationAttribute.cpp +++ b/KREngine/kraken/KRAnimationAttribute.cpp @@ -152,6 +152,8 @@ void KRAnimationAttribute::loadXML(tinyxml2::XMLElement *e) m_curve = NULL; m_curve_name = e->Attribute("curve"); m_target_name = e->Attribute("target"); + + m_node_attribute = KRNode::KRENGINE_NODE_ATTRIBUTE_NONE; const char *szAttribute = e->Attribute("attribute"); @@ -267,4 +269,12 @@ KRAnimationCurve *KRAnimationAttribute::getCurve() return m_curve; } +void KRAnimationAttribute::deleteCurve() +{ + KRAnimationCurve *curve = getCurve(); + if(curve) { + getContext().getAnimationCurveManager()->deleteAnimationCurve(curve); + m_curve = NULL; + } +} diff --git a/KREngine/kraken/KRAnimationAttribute.h b/KREngine/kraken/KRAnimationAttribute.h index 7ddcfb8..6a4f695 100644 --- a/KREngine/kraken/KRAnimationAttribute.h +++ b/KREngine/kraken/KRAnimationAttribute.h @@ -58,6 +58,8 @@ public: KRNode *getTarget(); KRAnimationCurve *getCurve(); + void deleteCurve(); + private: std::string m_target_name; std::string m_curve_name; diff --git a/KREngine/kraken/KRAnimationCurve.cpp b/KREngine/kraken/KRAnimationCurve.cpp index a1abbd7..b85ad15 100644 --- a/KREngine/kraken/KRAnimationCurve.cpp +++ b/KREngine/kraken/KRAnimationCurve.cpp @@ -29,6 +29,7 @@ // or implied, of Kearwood Gilbert. // +#include "KRContext.h" #include "KRAnimationCurve.h" #include "KRDataBlock.h" @@ -48,7 +49,6 @@ KRAnimationCurve::~KRAnimationCurve() m_pData->unload(); delete m_pData; } - bool KRAnimationCurve::load(KRDataBlock *data) { m_pData->unload(); @@ -152,3 +152,44 @@ float KRAnimationCurve::getValue(float local_time) return getValue((int)(local_time * getFrameRate())); } +bool KRAnimationCurve::valueChanges(float start_time, float duration) +{ + return valueChanges((int)(start_time * getFrameRate()), (int)(duration * getFrameRate())); +} + +bool KRAnimationCurve::valueChanges(int start_frame, int frame_count) +{ + + float first_value = getValue(start_frame); + + // Range of frames is not inclusive of last frame + for(int frame_number = start_frame + 1; frame_number < start_frame + frame_count; frame_number++) { + if(getValue(frame_number) != first_value) { + return true; + } + } + + return false; +} + +KRAnimationCurve *KRAnimationCurve::split(const std::string &name, float start_time, float duration) +{ + return split(name, (int)(start_time * getFrameRate()), (int)(duration * getFrameRate())); +} + +KRAnimationCurve *KRAnimationCurve::split(const std::string &name, int start_frame, int frame_count) +{ + KRAnimationCurve *new_curve = new KRAnimationCurve(getContext(), name); + + new_curve->setFrameRate(getFrameRate()); + new_curve->setFrameStart(start_frame); + new_curve->setFrameCount(frame_count); + + // Range of frames is not inclusive of last frame + for(int frame_number = start_frame; frame_number < start_frame + frame_count; frame_number++) { + new_curve->setValue(frame_number, getValue(frame_number)); // TODO - MEMCPY here? + } + + getContext().getAnimationCurveManager()->addAnimationCurve(new_curve); + return new_curve; +} diff --git a/KREngine/kraken/KRAnimationCurve.h b/KREngine/kraken/KRAnimationCurve.h index 3b4f334..ff5309c 100644 --- a/KREngine/kraken/KRAnimationCurve.h +++ b/KREngine/kraken/KRAnimationCurve.h @@ -61,6 +61,11 @@ public: static KRAnimationCurve *Load(KRContext &context, const std::string &name, KRDataBlock *data); + bool valueChanges(float start_time, float duration); + bool valueChanges(int start_frame, int frame_count); + + KRAnimationCurve *split(const std::string &name, float start_time, float duration); + KRAnimationCurve *split(const std::string &name, int start_frame, int frame_count); private: KRDataBlock *m_pData; diff --git a/KREngine/kraken/KRAnimationCurveManager.cpp b/KREngine/kraken/KRAnimationCurveManager.cpp index 017b13a..548d378 100644 --- a/KREngine/kraken/KRAnimationCurveManager.cpp +++ b/KREngine/kraken/KRAnimationCurveManager.cpp @@ -43,6 +43,11 @@ KRAnimationCurveManager::~KRAnimationCurveManager() { } } +void KRAnimationCurveManager::deleteAnimationCurve(KRAnimationCurve *curve) { + m_animationCurves.erase(curve->getName()); + delete curve; +} + KRAnimationCurve *KRAnimationCurveManager::loadAnimationCurve(const std::string &name, KRDataBlock *data) { KRAnimationCurve *pAnimationCurve = KRAnimationCurve::Load(*m_pContext, name, data); m_animationCurves[name] = pAnimationCurve; diff --git a/KREngine/kraken/KRAnimationCurveManager.h b/KREngine/kraken/KRAnimationCurveManager.h index b2a007c..4d59be2 100644 --- a/KREngine/kraken/KRAnimationCurveManager.h +++ b/KREngine/kraken/KRAnimationCurveManager.h @@ -50,6 +50,8 @@ public: void addAnimationCurve(KRAnimationCurve *new_animation_curve); unordered_map &getAnimationCurves(); + void deleteAnimationCurve(KRAnimationCurve *curve); + private: unordered_map m_animationCurves; }; diff --git a/KREngine/kraken/KRAnimationManager.cpp b/KREngine/kraken/KRAnimationManager.cpp index e55c166..76224e7 100644 --- a/KREngine/kraken/KRAnimationManager.cpp +++ b/KREngine/kraken/KRAnimationManager.cpp @@ -100,3 +100,12 @@ void KRAnimationManager::updateActiveAnimations(KRAnimation *animation) m_animationsToUpdate.insert(animation); } +void KRAnimationManager::deleteAnimation(KRAnimation *animation, bool delete_curves) +{ + if(delete_curves) + { + animation->deleteCurves(); + } + m_animations.erase(animation->getName()); + delete animation; +} diff --git a/KREngine/kraken/KRAnimationManager.h b/KREngine/kraken/KRAnimationManager.h index 6456d65..34a06f0 100644 --- a/KREngine/kraken/KRAnimationManager.h +++ b/KREngine/kraken/KRAnimationManager.h @@ -49,6 +49,7 @@ public: KRAnimation *getAnimation(const char *szName); void addAnimation(KRAnimation *new_animation); unordered_map &getAnimations(); + void deleteAnimation(KRAnimation *animation, bool delete_curves); void startFrame(float deltaTime); void endFrame(float deltaTime); From 58d4bae6b65538e11bb0a82badbd0dca488cd5e4 Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Sat, 24 Aug 2013 17:04:20 -0700 Subject: [PATCH 03/12] Fixed bug in animation import that caused the attributes to be un-assigned to nodes. --HG-- extra : source : 9cf011cb5f014ef330dfdf4150e0523b64400e03 --- KREngine/kraken/KRAnimation.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/KREngine/kraken/KRAnimation.cpp b/KREngine/kraken/KRAnimation.cpp index 1be1203..093ef13 100644 --- a/KREngine/kraken/KRAnimation.cpp +++ b/KREngine/kraken/KRAnimation.cpp @@ -281,6 +281,7 @@ KRAnimation *KRAnimation::split(const std::string &name, float start_time, float } new_attribute->setCurveName(new_curve->getName()); + new_attribute->setTargetAttribute(attribute->getTargetAttribute()); new_attribute->setTargetName(attribute->getTargetName()); new_layer->addAttribute(new_attribute); } From b4a3dc369ff65362bc675100ff0a32ce8efc894f Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Sat, 31 Aug 2013 15:31:17 -0700 Subject: [PATCH 04/12] Fixed bug in animation splitting that would cause curves that don't start at frame 0 to be offset incorrectly --HG-- extra : source : c293b845a630673ed0a62c9855e2f295235e3e28 --- KREngine/kraken/KRAnimationCurve.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/KREngine/kraken/KRAnimationCurve.cpp b/KREngine/kraken/KRAnimationCurve.cpp index b85ad15..8c6d8eb 100644 --- a/KREngine/kraken/KRAnimationCurve.cpp +++ b/KREngine/kraken/KRAnimationCurve.cpp @@ -127,7 +127,7 @@ void KRAnimationCurve::setFrameStart(int frame_number) float KRAnimationCurve::getValue(int frame_number) { //printf("frame_number: %i\n", frame_number); - int clamped_frame = frame_number; + int clamped_frame = frame_number - getFrameStart(); if(frame_number < 0) { clamped_frame = 0; } else if(frame_number >= getFrameCount()) { @@ -139,9 +139,10 @@ float KRAnimationCurve::getValue(int frame_number) void KRAnimationCurve::setValue(int frame_number, float value) { - if(frame_number >= 0 && frame_number < getFrameCount()) { + int clamped_frame = frame_number - getFrameStart(); + if(clamped_frame >= 0 && clamped_frame < getFrameCount()) { float *frame_data = (float *)((char *)m_pData->getStart() + sizeof(animation_curve_header)); - frame_data[frame_number] = value; + frame_data[clamped_frame] = value; } } From fdfa13fc898bd9a96639b113d3e538de090258fd Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Sat, 31 Aug 2013 17:38:20 -0700 Subject: [PATCH 05/12] Animation fixes for curves that do not start on frame 0 --HG-- extra : source : e6f80422c39a1a6a2f5b9ee4830b65f0ad92c37a --- KREngine/kraken/KRAnimation.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/KREngine/kraken/KRAnimation.cpp b/KREngine/kraken/KRAnimation.cpp index 093ef13..02b99a8 100644 --- a/KREngine/kraken/KRAnimation.cpp +++ b/KREngine/kraken/KRAnimation.cpp @@ -164,16 +164,8 @@ void KRAnimation::update(float deltaTime) KRNode::node_attribute_type attribute_type = attribute->getTargetAttribute(); if(curve != NULL && target != NULL) { - int frame_number = (int)((m_local_time + m_start_time) * curve->getFrameRate()); - if(frame_number < curve->getFrameStart()) { - target->SetAttribute(attribute_type, curve->getValue(m_start_time)); - } else if(frame_number - curve->getFrameStart() >= curve->getFrameCount()) { - target->SetAttribute(attribute_type, curve->getValue(curve->getFrameCount() - 1)); - } else { - target->SetAttribute(attribute_type, curve->getValue(frame_number - curve->getFrameStart())); - } + target->SetAttribute(attribute_type, curve->getValue(m_local_time + m_start_time)); } - } } } From 4d71287d1707418b23662ba6f3f14f31756d5617 Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Sat, 31 Aug 2013 19:22:37 -0700 Subject: [PATCH 06/12] More animation fixes for curves that don't start on frame 0. --HG-- extra : source : a70d3a871173dc2ba354825be8828d739699a2aa --- KREngine/kraken/KRAnimationCurve.cpp | 4 ++-- KREngine/kraken/KRResource+fbx.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/KREngine/kraken/KRAnimationCurve.cpp b/KREngine/kraken/KRAnimationCurve.cpp index 8c6d8eb..48077e9 100644 --- a/KREngine/kraken/KRAnimationCurve.cpp +++ b/KREngine/kraken/KRAnimationCurve.cpp @@ -128,9 +128,9 @@ float KRAnimationCurve::getValue(int frame_number) { //printf("frame_number: %i\n", frame_number); int clamped_frame = frame_number - getFrameStart(); - if(frame_number < 0) { + if(clamped_frame < 0) { clamped_frame = 0; - } else if(frame_number >= getFrameCount()) { + } else if(clamped_frame >= getFrameCount()) { clamped_frame = getFrameCount()-1; } float *frame_data = (float *)((char *)m_pData->getStart() + sizeof(animation_curve_header)); diff --git a/KREngine/kraken/KRResource+fbx.cpp b/KREngine/kraken/KRResource+fbx.cpp index 37c7dda..360f002 100644 --- a/KREngine/kraken/KRResource+fbx.cpp +++ b/KREngine/kraken/KRResource+fbx.cpp @@ -359,19 +359,19 @@ KRAnimationCurve *LoadAnimationCurve(KRContext &context, FbxAnimCurve* pAnimCurv return NULL; } - float frame_rate = 30.0f; // FINDME, TODO - This needs to be dynamic - int frame_start = time_span.GetStart().GetSecondDouble() * frame_rate; - int frame_count = (time_span.GetStop().GetSecondDouble() * frame_rate) - frame_start; + float dest_frame_rate = 30.0f; // FINDME, TODO - This needs to be dynamic + int frame_start = time_span.GetStart().GetSecondDouble() * dest_frame_rate; + int frame_count = (time_span.GetStop().GetSecondDouble() * dest_frame_rate) - frame_start; KRAnimationCurve *new_curve = new KRAnimationCurve(context, name); - new_curve->setFrameRate(frame_rate); + new_curve->setFrameRate(dest_frame_rate); new_curve->setFrameStart(frame_start); new_curve->setFrameCount(frame_count); // Resample animation curve int last_frame = 0; // Used by FBX sdk for faster keyframe searches for(int frame_number=0; frame_number < frame_count; frame_number++) { - float frame_seconds = (frame_start + frame_number) / frame_rate; + float frame_seconds = (frame_start + frame_number) / dest_frame_rate; FbxTime frame_time; frame_time.SetSecondDouble(frame_seconds); float frame_value = pAnimCurve->Evaluate(frame_time, &last_frame); From 8484fe95d4c3fc9d8e2b9a88f9140e90745edcdf Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Sat, 7 Sep 2013 16:57:18 -0700 Subject: [PATCH 07/12] Fixed shader compile error that occurred when using Reflection Map scale or offset attributes in a material. Fixed bug that caused the Reflection Map scale to be swapped with the Normal Map scale material parameter. Fixed bug that caused the Reflection Map offset to be swapped with the Normal Map offset material parameter. --HG-- extra : source : 76835810d2acad4b58299024c7d23a3d29c7ccbb --- KREngine/kraken/KRMaterial.cpp | 2 +- KREngine/kraken_standard_assets_ios/Shaders/ObjectShader.vsh | 4 ++-- .../kraken_standard_assets_osx/Shaders/ObjectShader_osx.vsh | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/KREngine/kraken/KRMaterial.cpp b/KREngine/kraken/KRMaterial.cpp index 95e836e..3a29612 100644 --- a/KREngine/kraken/KRMaterial.cpp +++ b/KREngine/kraken/KRMaterial.cpp @@ -252,7 +252,7 @@ bool KRMaterial::bind(KRCamera *pCamera, std::vector &point_ligh bool bAlphaBlend = (m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDONESIDE) || (m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE); - KRShader *pShader = getContext().getShaderManager()->getShader("ObjectShader", pCamera, point_lights, directional_lights, spot_lights, bones.size(), bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, bLightMap, m_diffuseMapScale != default_scale && bDiffuseMap, m_specularMapScale != default_scale && bSpecMap, m_reflectionMapScale != default_scale && bReflectionMap, m_normalMapScale != default_scale && bNormalMap, m_diffuseMapOffset != default_offset && bDiffuseMap, m_specularMapOffset != default_offset && bSpecMap, m_reflectionMapOffset != default_offset && bReflectionMap, m_normalMapOffset != default_offset && bNormalMap, bAlphaTest, bAlphaBlend, renderPass); + KRShader *pShader = getContext().getShaderManager()->getShader("ObjectShader", pCamera, point_lights, directional_lights, spot_lights, bones.size(), bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, bLightMap, m_diffuseMapScale != default_scale && bDiffuseMap, m_specularMapScale != default_scale && bSpecMap, m_normalMapScale != default_scale && bNormalMap, m_reflectionMapScale != default_scale && bReflectionMap, m_diffuseMapOffset != default_offset && bDiffuseMap, m_specularMapOffset != default_offset && bSpecMap, m_normalMapOffset != default_offset && bNormalMap, m_reflectionMapOffset != default_offset && bReflectionMap, bAlphaTest, bAlphaBlend, renderPass); if(!getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, matModel, point_lights, directional_lights, spot_lights, 0, renderPass)) { return false; diff --git a/KREngine/kraken_standard_assets_ios/Shaders/ObjectShader.vsh b/KREngine/kraken_standard_assets_ios/Shaders/ObjectShader.vsh index 353f5b2..6d2b3fe 100644 --- a/KREngine/kraken_standard_assets_ios/Shaders/ObjectShader.vsh +++ b/KREngine/kraken_standard_assets_ios/Shaders/ObjectShader.vsh @@ -111,11 +111,11 @@ uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying t #endif #if HAS_REFLECTION_MAP_SCALE == 1 - uniform highp vec2 reflection_Scale; + uniform highp vec2 reflectionTexture_Scale; #endif #if HAS_REFLECTION_MAP_OFFSET == 1 - uniform highp vec2 reflection_Offset; + uniform highp vec2 reflectionTexture_Offset; #endif #if SHADOW_QUALITY >= 1 diff --git a/KREngine/kraken_standard_assets_osx/Shaders/ObjectShader_osx.vsh b/KREngine/kraken_standard_assets_osx/Shaders/ObjectShader_osx.vsh index fd08cb2..4aaad3b 100644 --- a/KREngine/kraken_standard_assets_osx/Shaders/ObjectShader_osx.vsh +++ b/KREngine/kraken_standard_assets_osx/Shaders/ObjectShader_osx.vsh @@ -107,11 +107,11 @@ uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying t #endif #if HAS_REFLECTION_MAP_SCALE == 1 - uniform highp vec2 reflection_Scale; + uniform highp vec2 reflectionTexture_Scale; #endif #if HAS_REFLECTION_MAP_OFFSET == 1 - uniform highp vec2 reflection_Offset; + uniform highp vec2 reflectionTexture_Offset; #endif #if SHADOW_QUALITY >= 1 From 44ea4925561f36086910ebbee0b8a559b244a2d9 Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Sat, 7 Sep 2013 17:34:06 -0700 Subject: [PATCH 08/12] Fixed bug in KROctreeNode::lineCast that would cause it to always return false --HG-- extra : source : a47a7a9a0b39a68629eb72aecc093400e4bb1568 --- KREngine/kraken/KROctreeNode.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/KREngine/kraken/KROctreeNode.cpp b/KREngine/kraken/KROctreeNode.cpp index 490b7f7..7332275 100644 --- a/KREngine/kraken/KROctreeNode.cpp +++ b/KREngine/kraken/KROctreeNode.cpp @@ -203,7 +203,6 @@ bool KROctreeNode::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo // Optimization: If we already have a hit, only search for hits that are closer hit_found = lineCast(v0, hitinfo.getPosition(), hitinfo, layer_mask); } else { - bool hit_found = false; if(getBounds().intersectsLine(v0, v1)) { for(std::set::iterator nodes_itr=m_sceneNodes.begin(); nodes_itr != m_sceneNodes.end(); nodes_itr++) { KRCollider *collider = dynamic_cast(*nodes_itr); From 29b518610b7cae44a59aec955484803f1a3ba6e3 Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Sun, 17 Nov 2013 01:46:12 -0800 Subject: [PATCH 09/12] Implemented API to read and seek the audio playback position of KRAudioSource --HG-- extra : source : 5ef720e0f476c72b85a7e2fc841af965d2038264 --- KREngine/kraken/KRAudioSource.cpp | 96 +++++++++++++++++++++++-------- KREngine/kraken/KRAudioSource.h | 39 +++++++++++-- 2 files changed, 106 insertions(+), 29 deletions(-) diff --git a/KREngine/kraken/KRAudioSource.cpp b/KREngine/kraken/KRAudioSource.cpp index afef53d..094817d 100644 --- a/KREngine/kraken/KRAudioSource.cpp +++ b/KREngine/kraken/KRAudioSource.cpp @@ -56,6 +56,7 @@ KRAudioSource::KRAudioSource(KRScene &scene, std::string name) : KRNode(scene, n m_enable_obstruction = true; m_start_audio_frame = -1; + m_paused_audio_frame = 0; } KRAudioSource::~KRAudioSource() @@ -314,12 +315,13 @@ void KRAudioSource::setRolloffFactor(float rolloff_factor) void KRAudioSource::setLooping(bool looping) { + // Enable or disable looping playback; Audio source must be stopped and re-started for loop mode changes to take effect m_looping = looping; - // Audio source must be stopped and re-started for loop mode changes to take effect } bool KRAudioSource::getLooping() { + // Returns true if the playback will automatically loop return m_looping; } @@ -400,38 +402,54 @@ void KRAudioSource::physicsUpdate(float deltaTime) void KRAudioSource::play() { - KRAudioManager *audioManager = getContext().getAudioManager(); - m_start_audio_frame = audioManager->getAudioFrame(); - audioManager->activateAudioSource(this); - if(audioManager->getAudioEngine() == KRAudioManager::KRAKEN_AUDIO_OPENAL) { - getContext().getAudioManager()->makeCurrentContext(); - prime(); - updatePosition(); + // Start playback of audio at the current audio sample position. If audio is already playing, this has no effect. + // play() does not automatically seek to the beginning of the sample. Call setAudioFrame( 0 ) first if you wish the playback to begin at the start of the audio sample. + // If not set to looping, audio playback ends automatically at the end of the sample + + if(!m_playing) { + KRAudioManager *audioManager = getContext().getAudioManager(); + assert(m_start_audio_frame == -1); + m_start_audio_frame = audioManager->getAudioFrame() - m_paused_audio_frame; + m_paused_audio_frame = -1; + audioManager->activateAudioSource(this); + if(audioManager->getAudioEngine() == KRAudioManager::KRAKEN_AUDIO_OPENAL) { + getContext().getAudioManager()->makeCurrentContext(); + prime(); + updatePosition(); - if(m_is3d) { - ALDEBUG(alSource3f(m_sourceID, AL_VELOCITY, 0.0f, 0.0f, 0.0f)); - ALDEBUG(alSourcef(m_sourceID, AL_REFERENCE_DISTANCE, m_referenceDistance)); - ALDEBUG(alSourcef(m_sourceID, AL_ROLLOFF_FACTOR, m_rolloffFactor)); - ALDEBUG(alcASASetSourceProc(ALC_ASA_REVERB_SEND_LEVEL, m_sourceID, &m_reverb, sizeof(m_reverb))); - ALDEBUG(alSourcei(m_sourceID, AL_SOURCE_RELATIVE, AL_FALSE)); - } else { - ALDEBUG(alSourcei(m_sourceID, AL_SOURCE_RELATIVE, AL_TRUE)); - ALDEBUG(alSource3f(m_sourceID, AL_POSITION, 0.0, 0.0, 0.0)); + if(m_is3d) { + ALDEBUG(alSource3f(m_sourceID, AL_VELOCITY, 0.0f, 0.0f, 0.0f)); + ALDEBUG(alSourcef(m_sourceID, AL_REFERENCE_DISTANCE, m_referenceDistance)); + ALDEBUG(alSourcef(m_sourceID, AL_ROLLOFF_FACTOR, m_rolloffFactor)); + ALDEBUG(alcASASetSourceProc(ALC_ASA_REVERB_SEND_LEVEL, m_sourceID, &m_reverb, sizeof(m_reverb))); + ALDEBUG(alSourcei(m_sourceID, AL_SOURCE_RELATIVE, AL_FALSE)); + } else { + ALDEBUG(alSourcei(m_sourceID, AL_SOURCE_RELATIVE, AL_TRUE)); + ALDEBUG(alSource3f(m_sourceID, AL_POSITION, 0.0, 0.0, 0.0)); + } + ALDEBUG(alSourcePlay(m_sourceID)); } - ALDEBUG(alSourcePlay(m_sourceID)); } m_playing = true; } void KRAudioSource::stop() { - m_start_audio_frame = -1; - m_playing = false; - getContext().getAudioManager()->deactivateAudioSource(this); + // Stop playback of audio. If audio is already stopped, this has no effect. + // If play() is called afterwards, playback will continue at the current audio sample position. + + if(m_playing) { + m_paused_audio_frame = getAudioFrame(); + m_start_audio_frame = -1; + m_playing = false; + getContext().getAudioManager()->deactivateAudioSource(this); + } } bool KRAudioSource::isPlaying() { + // Returns true if audio is playing. Will return false if a non-looped playback has reached the end of the audio sample. + return m_playing; } @@ -504,16 +522,46 @@ int KRAudioSource::getBufferFrame() return m_currentBufferFrame; } -__int64_t KRAudioSource::getStartAudioFrame() +__int64_t KRAudioSource::getAudioFrame() { - return m_start_audio_frame; + // Returns the audio playback position in units of integer audio frames. + + if(m_playing) { + return getContext().getAudioManager()->getAudioFrame() - m_start_audio_frame; + } else { + return m_paused_audio_frame; + } +} + +void KRAudioSource::setAudioFrame(__int64_t next_frame) +{ + // Sets the audio playback position with units of integer audio frames. + if(m_playing) { + m_start_audio_frame = getContext().getAudioManager()->getAudioFrame() - next_frame; + } else { + m_paused_audio_frame = next_frame; + } +} + + +float KRAudioSource::getAudioTime() +{ + // Gets the audio playback position with units of floating point seconds. + + return getAudioFrame() / 44100.0f; +} + +void KRAudioSource::setAudioTime(float new_position) +{ + // Sets the audio playback position with units of floating point seconds. + setAudioFrame(new_position * 44100.0f); } void KRAudioSource::sample(int frame_count, int channel, float *buffer, float gain) { KRAudioSample *source_sample = getAudioSample(); if(source_sample && m_playing) { - __int64_t next_frame = getContext().getAudioManager()->getAudioFrame() - getStartAudioFrame(); + __int64_t next_frame = getAudioFrame(); source_sample->sample(next_frame, frame_count, channel, buffer, gain, m_looping); if(!m_looping && next_frame > source_sample->getFrameCount()) { stop(); diff --git a/KREngine/kraken/KRAudioSource.h b/KREngine/kraken/KRAudioSource.h index 8472f36..a82343e 100644 --- a/KREngine/kraken/KRAudioSource.h +++ b/KREngine/kraken/KRAudioSource.h @@ -51,10 +51,41 @@ public: virtual void physicsUpdate(float deltaTime); void render(KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass); + + // ---- Audio Playback Controls ---- + + // Start playback of audio at the current audio sample position. If audio is already playing, this has no effect. + // play() does not automatically seek to the beginning of the sample. Call setAudioFrame( 0 ) first if you wish the playback to begin at the start of the audio sample. + // If not set to looping, audio playback ends automatically at the end of the sample void play(); + + // Stop playback of audio. If audio is already stopped, this has no effect. + // If play() is called afterwards, playback will continue at the current audio sample position. void stop(); + + // Returns true if audio is playing. Will return false if a non-looped playback has reached the end of the audio sample. bool isPlaying(); + // Returns the audio playback position in units of integer audio frames. + __int64_t getAudioFrame(); + + // Sets the audio playback position with units of integer audio frames. + void setAudioFrame(__int64_t next_frame); + + // Gets the audio playback position with units of floating point seconds. + float getAudioTime(); + + // Sets the audio playback position with units of floating point seconds. + void setAudioTime(float new_position); + + // Returns true if the playback will automatically loop + bool getLooping(); + + // Enable or disable looping playback; Audio source must be stopped and re-started for loop mode changes to take effect + void setLooping(bool looping); + + // ---- End: Audio Playback Controls ---- + void setSample(const std::string &sound_name); std::string getSample(); @@ -66,8 +97,7 @@ public: float getPitch(); void setPitch(float pitch); - bool getLooping(); - void setLooping(bool looping); + bool getIs3D(); void setIs3D(bool is3D); @@ -94,12 +124,11 @@ public: KRAudioBuffer *getBuffer(); int getBufferFrame(); - - __int64_t getStartAudioFrame(); void sample(int frame_count, int channel, float *buffer, float gain); private: - __int64_t m_start_audio_frame; // Global audio frame that matches the start of the audio sample playback + __int64_t m_start_audio_frame; // Global audio frame that matches the start of the audio sample playback; when paused or not playing, this contains a value of -1 + __int64_t m_paused_audio_frame; // When paused or not playing, this contains the local audio frame number. When playing, this contains a value of -1 int m_currentBufferFrame; // Siren Audio Engine frame number within current buffer void advanceBuffer(); From a8a8f32e77b803c4242d9f315ab0f3b4e835703f Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Mon, 18 Nov 2013 23:52:03 -0800 Subject: [PATCH 10/12] Implemented KRNode::getParent() --HG-- extra : source : 1bad435929f774f4da192fba4204fd7a85b17f01 --- KREngine/kraken/KRNode.cpp | 4 ++++ KREngine/kraken/KRNode.h | 1 + 2 files changed, 5 insertions(+) diff --git a/KREngine/kraken/KRNode.cpp b/KREngine/kraken/KRNode.cpp index 70e5ae1..aab2759 100644 --- a/KREngine/kraken/KRNode.cpp +++ b/KREngine/kraken/KRNode.cpp @@ -450,6 +450,10 @@ const std::set &KRNode::getChildren() { return m_childNodes; } +KRNode *KRNode::getParent() { + return m_parentNode; +} + const std::string &KRNode::getName() const { return m_name; } diff --git a/KREngine/kraken/KRNode.h b/KREngine/kraken/KRNode.h index 61cea10..e8d0f9d 100644 --- a/KREngine/kraken/KRNode.h +++ b/KREngine/kraken/KRNode.h @@ -58,6 +58,7 @@ public: void addChild(KRNode *child); const std::set &getChildren(); + KRNode *getParent(); void setLocalTranslation(const KRVector3 &v, bool set_original = false); void setLocalScale(const KRVector3 &v, bool set_original = false); From 9cd9a8474cfc452aaebd8e4d112a81b9fa884cce Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Sat, 23 Nov 2013 12:16:31 -0800 Subject: [PATCH 11/12] Updated to FBX SDK 2014.2 Nodes in the FBX file starting with so_ will no longer be decorated with fbx_##_ prefixes. Updated import pipeline for compatibility with C++11 --HG-- extra : source : 39b8803b34f432b24279d4c6ca4c05f4f505174b --- KREngine/Kraken.xcodeproj/project.pbxproj | 34 ++- KREngine/kraken/KRContext.cpp | 2 +- KREngine/kraken/KRDataBlock.cpp | 4 + KREngine/kraken/KREngine-common.h | 21 +- KREngine/kraken/KRMeshStreamer.mm | 35 ++- KREngine/kraken/KRResource+fbx.cpp | 248 ++++++++++++---------- KREngine/kraken/KRTextureStreamer.mm | 40 ++++ 7 files changed, 227 insertions(+), 157 deletions(-) diff --git a/KREngine/Kraken.xcodeproj/project.pbxproj b/KREngine/Kraken.xcodeproj/project.pbxproj index b3554fb..e9aabca 100644 --- a/KREngine/Kraken.xcodeproj/project.pbxproj +++ b/KREngine/Kraken.xcodeproj/project.pbxproj @@ -76,15 +76,15 @@ E43F70DC181B20E400136169 /* KRLODSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43F70DA181B20E300136169 /* KRLODSet.cpp */; }; E43F70DD181B20E400136169 /* KRLODSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43F70DA181B20E300136169 /* KRLODSet.cpp */; }; E43F70DE181B20E400136169 /* KRLODSet.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70DB181B20E400136169 /* KRLODSet.h */; }; - E43F70DF181B20E400136169 /* KRLODSet.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70DB181B20E400136169 /* KRLODSet.h */; }; + E43F70DF181B20E400136169 /* KRLODSet.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70DB181B20E400136169 /* KRLODSet.h */; settings = {ATTRIBUTES = (Public, ); }; }; E43F70E51824D9AB00136169 /* KRTextureStreamer.mm in Sources */ = {isa = PBXBuildFile; fileRef = E43F70E31824D9AB00136169 /* KRTextureStreamer.mm */; }; E43F70E61824D9AB00136169 /* KRTextureStreamer.mm in Sources */ = {isa = PBXBuildFile; fileRef = E43F70E31824D9AB00136169 /* KRTextureStreamer.mm */; }; E43F70E71824D9AB00136169 /* KRTextureStreamer.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70E41824D9AB00136169 /* KRTextureStreamer.h */; }; - E43F70E81824D9AB00136169 /* KRTextureStreamer.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70E41824D9AB00136169 /* KRTextureStreamer.h */; }; + E43F70E81824D9AB00136169 /* KRTextureStreamer.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70E41824D9AB00136169 /* KRTextureStreamer.h */; settings = {ATTRIBUTES = (Public, ); }; }; E43F70FF1824E73100136169 /* KRMeshStreamer.mm in Sources */ = {isa = PBXBuildFile; fileRef = E43F70FD1824E73100136169 /* KRMeshStreamer.mm */; }; E43F71001824E73100136169 /* KRMeshStreamer.mm in Sources */ = {isa = PBXBuildFile; fileRef = E43F70FD1824E73100136169 /* KRMeshStreamer.mm */; }; E43F71011824E73100136169 /* KRMeshStreamer.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70FE1824E73100136169 /* KRMeshStreamer.h */; }; - E43F71021824E73100136169 /* KRMeshStreamer.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70FE1824E73100136169 /* KRMeshStreamer.h */; }; + E43F71021824E73100136169 /* KRMeshStreamer.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70FE1824E73100136169 /* KRMeshStreamer.h */; settings = {ATTRIBUTES = (Public, ); }; }; E4409D2916FA748700310F76 /* font.tga in Resources */ = {isa = PBXBuildFile; fileRef = E41AE1DD16B124CA00980428 /* font.tga */; }; E44F38241683B23000399B5D /* KRRenderSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = E44F38231683B22C00399B5D /* KRRenderSettings.h */; settings = {ATTRIBUTES = (); }; }; E44F38251683B23000399B5D /* KRRenderSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = E44F38231683B22C00399B5D /* KRRenderSettings.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -102,7 +102,7 @@ E459040616C30CD9002B00A0 /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E459040516C30CD9002B00A0 /* AudioUnit.framework */; }; E460292616681CFF00261BB9 /* KRTextureAnimated.h in Headers */ = {isa = PBXBuildFile; fileRef = E460292516681CFE00261BB9 /* KRTextureAnimated.h */; settings = {ATTRIBUTES = (); }; }; E460292816681D1000261BB9 /* KRTextureAnimated.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E460292716681D1000261BB9 /* KRTextureAnimated.cpp */; }; - E460292B16682BF700261BB9 /* libfbxsdk-2013.3-static.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E460292916682BD900261BB9 /* libfbxsdk-2013.3-static.a */; }; + E460292B16682BF700261BB9 /* libfbxsdk.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E460292916682BD900261BB9 /* libfbxsdk.a */; }; E460292C166834AB00261BB9 /* KRTextureAnimated.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E460292716681D1000261BB9 /* KRTextureAnimated.cpp */; }; E461A152152E54B500F2044A /* KRLight.h in Headers */ = {isa = PBXBuildFile; fileRef = E461A151152E54B500F2044A /* KRLight.h */; settings = {ATTRIBUTES = (); }; }; E461A153152E54B500F2044A /* KRLight.h in Headers */ = {isa = PBXBuildFile; fileRef = E461A151152E54B500F2044A /* KRLight.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -124,7 +124,7 @@ E468447F17FFDF51001F1FA1 /* KRLocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E468447D17FFDF51001F1FA1 /* KRLocator.cpp */; }; E468448017FFDF51001F1FA1 /* KRLocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E468447D17FFDF51001F1FA1 /* KRLocator.cpp */; }; E468448117FFDF51001F1FA1 /* KRLocator.h in Headers */ = {isa = PBXBuildFile; fileRef = E468447E17FFDF51001F1FA1 /* KRLocator.h */; }; - E468448217FFDF51001F1FA1 /* KRLocator.h in Headers */ = {isa = PBXBuildFile; fileRef = E468447E17FFDF51001F1FA1 /* KRLocator.h */; }; + E468448217FFDF51001F1FA1 /* KRLocator.h in Headers */ = {isa = PBXBuildFile; fileRef = E468447E17FFDF51001F1FA1 /* KRLocator.h */; settings = {ATTRIBUTES = (Public, ); }; }; E46A6B6D1559E97D000DBD37 /* KRResource+blend.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46A6B6C1559E97D000DBD37 /* KRResource+blend.cpp */; }; E46A6B701559EF0A000DBD37 /* KRResource+blend.h in Headers */ = {isa = PBXBuildFile; fileRef = E46A6B6F1559EF0A000DBD37 /* KRResource+blend.h */; settings = {ATTRIBUTES = (Public, ); }; }; E46C214515364BC8009CABF3 /* tinyxml2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46C214215364BC8009CABF3 /* tinyxml2.cpp */; }; @@ -451,7 +451,7 @@ E459040516C30CD9002B00A0 /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = System/Library/Frameworks/AudioUnit.framework; sourceTree = SDKROOT; }; E460292516681CFE00261BB9 /* KRTextureAnimated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRTextureAnimated.h; sourceTree = ""; }; E460292716681D1000261BB9 /* KRTextureAnimated.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRTextureAnimated.cpp; sourceTree = ""; }; - E460292916682BD900261BB9 /* libfbxsdk-2013.3-static.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libfbxsdk-2013.3-static.a"; path = "lib/gcc4/ub/libfbxsdk-2013.3-static.a"; sourceTree = FBXSDK; }; + E460292916682BD900261BB9 /* libfbxsdk.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libfbxsdk.a; path = "../../FBX SDK/2014.2/lib/ios-i386/release/libfbxsdk.a"; sourceTree = FBXSDK; }; E461A151152E54B500F2044A /* KRLight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRLight.h; sourceTree = ""; }; E461A155152E54F700F2044A /* KRLight.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = KRLight.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E461A157152E555400F2044A /* KRPointLight.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = KRPointLight.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; @@ -671,7 +671,7 @@ E4BBBB9F1512A4B100F43B5B /* Cocoa.framework in Frameworks */, E497B95D151BF05F00D3DC67 /* CoreServices.framework in Frameworks */, E497B95F151BF09600D3DC67 /* SystemConfiguration.framework in Frameworks */, - E460292B16682BF700261BB9 /* libfbxsdk-2013.3-static.a in Frameworks */, + E460292B16682BF700261BB9 /* libfbxsdk.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1091,7 +1091,7 @@ E459040316C30CC5002B00A0 /* AudioUnit.framework */, E41B6BA916BE437800B510EB /* CoreAudio.framework */, 10CC33A3168530A300BB9846 /* libPVRTexLib.a */, - E460292916682BD900261BB9 /* libfbxsdk-2013.3-static.a */, + E460292916682BD900261BB9 /* libfbxsdk.a */, E4BBBB9A1512A48200F43B5B /* Foundation.framework */, E46DBE7D1512AD4900D59F86 /* OpenGL.framework */, E4F027D41697A02D00D4427D /* OpenAL.framework */, @@ -1293,7 +1293,6 @@ E497B948151BB89D00D3DC67 /* KRVector2.h in Headers */, E4D0683F1512A790005FFBEB /* KRVector3.h in Headers */, E461A177152E5C6600F2044A /* KRMat4.h in Headers */, - E468448217FFDF51001F1FA1 /* KRLocator.h in Headers */, E4F975461536327C00FD60B2 /* KRMeshManager.h in Headers */, E497B94B151BCEE900D3DC67 /* KRResource.h in Headers */, E43B0AD915DDCA0F00A5CB9F /* KRContextObject.h in Headers */, @@ -1309,9 +1308,7 @@ E4F9754C153632F000FD60B2 /* KRCamera.h in Headers */, E4F975501536333500FD60B2 /* KRMesh.h in Headers */, E488399F15F92BE000BD66D5 /* KRBundleManager.h in Headers */, - E43F71021824E73100136169 /* KRMeshStreamer.h in Headers */, E4AFC6BC15F7C95D00DDB4C8 /* KRSceneManager.h in Headers */, - E43F70E81824D9AB00136169 /* KRTextureStreamer.h in Headers */, E428C2F31669610500A16EDF /* KRAnimationManager.h in Headers */, E4D133661537685A0070068C /* KRShader.h in Headers */, E461A153152E54B500F2044A /* KRLight.h in Headers */, @@ -1328,7 +1325,6 @@ E428C312166971FF00A16EDF /* KRAnimationLayer.h in Headers */, E4AFC6B615F7C46800DDB4C8 /* KRAABB.cpp in Headers */, E428C3171669A24B00A16EDF /* KRAnimationAttribute.h in Headers */, - E43F70DF181B20E400136169 /* KRLODSet.h in Headers */, E4AFC6BE15F7C9E600DDB4C8 /* KROctreeNode.h in Headers */, E4AFC6BD15F7C9DA00DDB4C8 /* KROctree.h in Headers */, E46A6B701559EF0A000DBD37 /* KRResource+blend.h in Headers */, @@ -1361,8 +1357,12 @@ E44F38251683B23000399B5D /* KRRenderSettings.h in Headers */, E499BF1D16AE74FF007FCDBE /* KRTextureAnimated.h in Headers */, E4EC73C41720B1FF0065299F /* KRVector4.h in Headers */, + E468448217FFDF51001F1FA1 /* KRLocator.h in Headers */, + E43F70DF181B20E400136169 /* KRLODSet.h in Headers */, E4AE63601704FB0A00B460CD /* KRLODGroup.h in Headers */, E45134B91746A4A300443C21 /* KRBehavior.h in Headers */, + E43F71021824E73100136169 /* KRMeshStreamer.h in Headers */, + E43F70E81824D9AB00136169 /* KRTextureStreamer.h in Headers */, E48CF945173453990005EBBB /* KRFloat.h in Headers */, E499BF1F16AE753E007FCDBE /* KRCollider.h in Headers */, E499BF2316AE7636007FCDBE /* kraken-prefix.pch in Headers */, @@ -1847,7 +1847,6 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = YES; ARCHS = "$(ARCHS_STANDARD_64_BIT)"; - CLANG_CXX_LIBRARY = "libstdc++"; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; DYLIB_COMPATIBILITY_VERSION = 1; @@ -1866,14 +1865,14 @@ GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; HEADER_SEARCH_PATHS = ( - "\"/Applications/Autodesk/FBX SDK/2013.3/include\"", + "\"/Applications/Autodesk/FBX SDK/2014.2/include\"", /usr/local/include, ); INFOPLIST_FILE = "kraken_osx/Kraken-Info.plist"; LD_DYLIB_INSTALL_NAME = "@rpath/${EXECUTABLE_PATH}"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", - "\"$(SYSTEM_APPS_DIR)/Autodesk/FBX SDK/2013.3/lib/gcc4/ub\"", + "\"$(SYSTEM_APPS_DIR)/Autodesk/FBX SDK/2014.2/lib/ios-i386/release\"", "\"$(SYSTEM_APPS_DIR)/Imagination/PowerVR/GraphicsSDK/PVRTexTool/Library/OSX_x86/Static\"", ); MACOSX_DEPLOYMENT_TARGET = 10.7; @@ -1891,7 +1890,6 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = YES; ARCHS = "$(ARCHS_STANDARD_64_BIT)"; - CLANG_CXX_LIBRARY = "libstdc++"; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; @@ -1910,14 +1908,14 @@ GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; HEADER_SEARCH_PATHS = ( - "\"/Applications/Autodesk/FBX SDK/2013.3/include\"", + "\"/Applications/Autodesk/FBX SDK/2014.2/include\"", /usr/local/include, ); INFOPLIST_FILE = "kraken_osx/Kraken-Info.plist"; LD_DYLIB_INSTALL_NAME = "@rpath/${EXECUTABLE_PATH}"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", - "\"$(SYSTEM_APPS_DIR)/Autodesk/FBX SDK/2013.3/lib/gcc4/ub\"", + "\"$(SYSTEM_APPS_DIR)/Autodesk/FBX SDK/2014.2/lib/ios-i386/release\"", "\"$(SYSTEM_APPS_DIR)/Imagination/PowerVR/GraphicsSDK/PVRTexTool/Library/OSX_x86/Static\"", ); MACOSX_DEPLOYMENT_TARGET = 10.7; diff --git a/KREngine/kraken/KRContext.cpp b/KREngine/kraken/KRContext.cpp index fa4d2b9..a26e398 100644 --- a/KREngine/kraken/KRContext.cpp +++ b/KREngine/kraken/KRContext.cpp @@ -284,7 +284,7 @@ void KRContext::setStreamingEnabled(bool enable) void KRContext::getMemoryStats(long &free_memory) { free_memory = 0; -#if TARGET_OS_IPHONE +#if TARGET_OS_IPHONE || TARGET_OS_MAC mach_port_t host_port = mach_host_self(); mach_msg_type_number_t host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t); vm_size_t pagesize = 0; diff --git a/KREngine/kraken/KRDataBlock.cpp b/KREngine/kraken/KRDataBlock.cpp index 28578f8..cfc2421 100644 --- a/KREngine/kraken/KRDataBlock.cpp +++ b/KREngine/kraken/KRDataBlock.cpp @@ -35,6 +35,10 @@ #include +int KRAKEN_MEM_PAGE_SIZE = getpagesize(); +#define KRAKEN_MEM_ROUND_DOWN_PAGE(x) ((x) & ~(KRAKEN_MEM_PAGE_SIZE - 1)) +#define KRAKEN_MEM_ROUND_UP_PAGE(x) ((((x) - 1) & ~(KRAKEN_MEM_PAGE_SIZE - 1)) + KRAKEN_MEM_PAGE_SIZE) + int m_mapCount = 0; size_t m_mapSize = 0; size_t m_mapOverhead = 0; diff --git a/KREngine/kraken/KREngine-common.h b/KREngine/kraken/KREngine-common.h index 1edc1af..1b60047 100644 --- a/KREngine/kraken/KREngine-common.h +++ b/KREngine/kraken/KREngine-common.h @@ -71,10 +71,6 @@ using std::queue; #define KRAKEN_HAVE_BLAS 1 #endif -int KRAKEN_MEM_PAGE_SIZE = getpagesize(); - -#define KRAKEN_MEM_ROUND_DOWN_PAGE(x) ((x) & ~(KRAKEN_MEM_PAGE_SIZE - 1)) -#define KRAKEN_MEM_ROUND_UP_PAGE(x) ((((x) - 1) & ~(KRAKEN_MEM_PAGE_SIZE - 1)) + KRAKEN_MEM_PAGE_SIZE) #define KRENGINE_MAX_TEXTURE_UNITS 8 @@ -83,23 +79,11 @@ int KRAKEN_MEM_PAGE_SIZE = getpagesize(); #endif -#if TARGET_OS_IPHONE - #include using std::unordered_map; using std::unordered_multimap; using std::hash; -#else - -#include -using std::tr1::unordered_map; -using std::tr1::unordered_multimap; -using std::tr1::hash; - -#endif - - #if TARGET_OS_IPHONE #include @@ -137,9 +121,6 @@ using std::tr1::hash; #include #endif -#endif - - #if DEBUG #define GLDEBUG(x) \ @@ -205,3 +186,5 @@ fprintf(stderr, "Error at line number %d, in file %s. Returned %d for call %s\n" #include "KRVector3.h" #include "KRVector2.h" #include "KRBehavior.h" + +#endif diff --git a/KREngine/kraken/KRMeshStreamer.mm b/KREngine/kraken/KRMeshStreamer.mm index 1940386..3067fe3 100644 --- a/KREngine/kraken/KRMeshStreamer.mm +++ b/KREngine/kraken/KRMeshStreamer.mm @@ -13,11 +13,36 @@ #include -EAGLContext *gMeshStreamerContext; +#if TARGET_OS_IPHONE + +EAGLContext *gMeshStreamerContext = nil; + +#elif TARGET_OS_MAC + +NSOpenGLContext *gMeshStreamerContext = nil; + +#else + +#error Unsupported Platform +#endif KRMeshStreamer::KRMeshStreamer(KRContext &context) : m_context(context) { + +#if TARGET_OS_IPHONE gMeshStreamerContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup: [EAGLContext currentContext].sharegroup]; +#elif TARGET_OS_MAC + NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = + { + NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, + 0 + }; + NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes] autorelease]; + gMeshStreamerContext = [[[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext: [NSOpenGLContext currentContext] ] autorelease]; +#else + #error Unsupported Platform +#endif + m_stop = false; m_thread = std::thread(&KRMeshStreamer::run, this); } @@ -35,7 +60,15 @@ void KRMeshStreamer::run() pthread_setname_np("Kraken - Mesh Streamer"); std::chrono::microseconds sleep_duration( 100 ); + +#if TARGET_OS_IPHONE [EAGLContext setCurrentContext: gMeshStreamerContext]; +#elif TARGET_OS_MAC + [gMeshStreamerContext makeCurrentContext]; +#else + #error Unsupported Platform +#endif + while(!m_stop) { diff --git a/KREngine/kraken/KRResource+fbx.cpp b/KREngine/kraken/KRResource+fbx.cpp index c5ee30d..bb82a8f 100644 --- a/KREngine/kraken/KRResource+fbx.cpp +++ b/KREngine/kraken/KRResource+fbx.cpp @@ -34,21 +34,21 @@ #define IOS_REF (*(pSdkManager->GetIOSettings())) #endif -void InitializeSdkObjects(KFbxSdkManager*& pSdkManager, KFbxScene*& pScene); -void DestroySdkObjects(KFbxSdkManager* pSdkManager); -bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pFilename); +void InitializeSdkObjects(FbxManager*& pSdkManager, FbxScene*& pScene); +void DestroySdkObjects(FbxManager* pSdkManager); +bool LoadScene(FbxManager* pSdkManager, FbxDocument* pScene, const char* pFilename); KRAnimation *LoadAnimation(KRContext &context, FbxAnimStack* pAnimStack); KRAnimationCurve *LoadAnimationCurve(KRContext &context, FbxAnimCurve* pAnimCurve); KRAnimationLayer *LoadAnimationLayer(KRContext &context, FbxAnimLayer *pAnimLayer); -void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode); +void LoadNode(FbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pGeometryConverter, FbxNode* pNode); //void BakeNode(KFbxNode* pNode); void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial); -void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, KFbxMesh* pSourceMesh); -KRNode *LoadMesh(KRNode *parent_node, KFbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode); -KRNode *LoadLight(KRNode *parent_node, KFbxNode* pNode); -KRNode *LoadSkeleton(KRNode *parent_node, FbxScene* pScene, KFbxNode* pNode); -KRNode *LoadLocator(KRNode *parent_node, FbxScene* pScene, KFbxNode* pNode); -KRNode *LoadCamera(KRNode *parent_node, KFbxNode* pNode); +void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, FbxMesh* pSourceMesh); +KRNode *LoadMesh(KRNode *parent_node, FbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, FbxNode* pNode); +KRNode *LoadLight(KRNode *parent_node, FbxNode* pNode); +KRNode *LoadSkeleton(KRNode *parent_node, FbxScene* pScene, FbxNode* pNode); +KRNode *LoadLocator(KRNode *parent_node, FbxScene* pScene, FbxNode* pNode); +KRNode *LoadCamera(KRNode *parent_node, FbxNode* pNode); std::string GetFbxObjectName(FbxObject *obj); const float KRAKEN_FBX_ANIMATION_FRAMERATE = 30.0f; // FINDME - This should be configurable @@ -57,12 +57,12 @@ const float KRAKEN_FBX_ANIMATION_FRAMERATE = 30.0f; // FINDME - This should be c std::string GetFbxObjectName(FbxObject *obj) { bool is_locator = false; - KFbxNode *node = FbxCast(obj); + FbxNode *node = FbxCast(obj); if(node) { - KFbxNodeAttribute::EType attribute_type = (node->GetNodeAttribute()->GetAttributeType()); - if(attribute_type == KFbxNodeAttribute::eNull) { - KFbxNull* pSourceNull = (KFbxNull*) node->GetNodeAttribute(); - if(pSourceNull->Look.Get() == KFbxNull::eCross ) { + FbxNodeAttribute::EType attribute_type = (node->GetNodeAttribute()->GetAttributeType()); + if(attribute_type == FbxNodeAttribute::eNull) { + FbxNull* pSourceNull = (FbxNull*) node->GetNodeAttribute(); + if(pSourceNull->Look.Get() == FbxNull::eCross ) { is_locator = true; } } @@ -74,6 +74,9 @@ std::string GetFbxObjectName(FbxObject *obj) if(is_locator) { // We do not rename locators return std::string(obj->GetName()); + } else if(strncmp(obj->GetName(), "so_", 3) == 0) { + // An so_ prefix indicates that this is a "Scriptable Object" that should not have the name decorated; + return obj->GetName(); } else if(strcmp(obj->GetName(), "default_camera") == 0) { // There is currently support for rendering from only one camera, "default_camera". We don't translate this node's name, so that animations can drive the camera return "default_camera"; @@ -94,8 +97,8 @@ void KRResource::LoadFbx(KRContext &context, const std::string& path) KRScene *pScene = new KRScene(context, KRResource::GetFileBase(path)); context.getSceneManager()->add(pScene); - KFbxSdkManager* lSdkManager = NULL; - KFbxScene* pFbxScene = NULL; + FbxManager* lSdkManager = NULL; + FbxScene* pFbxScene = NULL; bool lResult; FbxGeometryConverter *pGeometryConverter = NULL; @@ -108,7 +111,7 @@ void KRResource::LoadFbx(KRContext &context, const std::string& path) // Load the scene. lResult = LoadScene(lSdkManager, pFbxScene, path.c_str()); - KFbxNode* pNode = pFbxScene->GetRootNode(); + FbxNode* pNode = pFbxScene->GetRootNode(); // ----====---- Bake pivots into transforms, as Kraken doesn't support them directly ----====---- /* @@ -189,11 +192,11 @@ void KRResource::LoadFbx(KRContext &context, const std::string& path) DestroySdkObjects(lSdkManager); } -void InitializeSdkObjects(KFbxSdkManager*& pSdkManager, KFbxScene*& pScene) +void InitializeSdkObjects(FbxManager*& pSdkManager, FbxScene*& pScene) { // The first thing to do is to create the FBX SDK manager which is the // object allocator for almost all the classes in the SDK. - pSdkManager = KFbxSdkManager::Create(); + pSdkManager = FbxManager::Create(); if (!pSdkManager) { @@ -202,25 +205,27 @@ void InitializeSdkObjects(KFbxSdkManager*& pSdkManager, KFbxScene*& pScene) } // create an IOSettings object - KFbxIOSettings * ios = KFbxIOSettings::Create(pSdkManager, IOSROOT ); + FbxIOSettings * ios = FbxIOSettings::Create(pSdkManager, IOSROOT ); pSdkManager->SetIOSettings(ios); // Load plugins from the executable directory - KString lPath = FbxGetApplicationDirectory(); -#if defined(KARCH_ENV_WIN) - KString lExtension = "dll"; -#elif defined(KARCH_ENV_MACOSX) - KString lExtension = "dylib"; -#elif defined(KARCH_ENV_LINUX) - KString lExtension = "so"; + FbxString lPath = FbxGetApplicationDirectory(); +#if TARGET_OS_WIN32 + FbxString lExtension = "dll"; +#elif TARGET_OS_MAC + FbxString lExtension = "dylib"; +#elif TARGET_OS_UNIX + FbxString lExtension = "so"; +#elif + #error Unsupported Platform #endif pSdkManager->LoadPluginsDirectory(lPath.Buffer(), lExtension.Buffer()); // Create the entity that will hold the scene. - pScene = KFbxScene::Create(pSdkManager,""); + pScene = FbxScene::Create(pSdkManager,""); } -void DestroySdkObjects(KFbxSdkManager* pSdkManager) +void DestroySdkObjects(FbxManager* pSdkManager) { // Delete the FBX SDK manager. All the objects that have been allocated // using the FBX SDK manager and that haven't been explicitly destroyed @@ -230,7 +235,7 @@ void DestroySdkObjects(KFbxSdkManager* pSdkManager) } -bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pFilename) +bool LoadScene(FbxManager* pSdkManager, FbxDocument* pScene, const char* pFilename) { int lFileMajor, lFileMinor, lFileRevision; int lSDKMajor, lSDKMinor, lSDKRevision; @@ -240,10 +245,10 @@ bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pF char lPassword[1024]; // Get the file version number generate by the FBX SDK. - KFbxSdkManager::GetFileFormatVersion(lSDKMajor, lSDKMinor, lSDKRevision); + FbxManager::GetFileFormatVersion(lSDKMajor, lSDKMinor, lSDKRevision); // Create an importer. - KFbxImporter* lImporter = KFbxImporter::Create(pSdkManager,""); + FbxImporter* lImporter = FbxImporter::Create(pSdkManager,""); // Initialize the importer by providing a filename. const bool lImportStatus = lImporter->Initialize(pFilename, -1, pSdkManager->GetIOSettings()); @@ -251,11 +256,14 @@ bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pF if( !lImportStatus ) { - printf("Call to KFbxImporter::Initialize() failed.\n"); - printf("Error returned: %s\n\n", lImporter->GetLastErrorString()); + FbxStatus &status = lImporter->GetStatus(); - if (lImporter->GetLastErrorID() == FbxIOBase::eFileVersionNotSupportedYet || - lImporter->GetLastErrorID() == FbxIOBase::eFileVersionNotSupportedAnymore) + printf("Call to KFbxImporter::Initialize() failed.\n"); + printf("Error returned: %s\n\n", status.GetErrorString()); + + + + if (status.GetCode() == FbxStatus::EStatusCode::eInvalidFileVersion) { printf("FBX version number for this FBX SDK is %d.%d.%d\n", lSDKMajor, lSDKMinor, lSDKRevision); printf("FBX version number for file %s is %d.%d.%d\n\n", pFilename, lFileMajor, lFileMinor, lFileRevision); @@ -299,21 +307,21 @@ bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pF // Import the scene. lStatus = lImporter->Import(pScene); - if(lStatus == false && lImporter->GetLastErrorID() == FbxIOBase::ePasswordError) + if(lStatus == false && lImporter->GetStatus().GetCode() == FbxStatus::EStatusCode::ePasswordError) { printf("Please enter password: "); lPassword[0] = '\0'; scanf("%s", lPassword); - KString lString(lPassword); + FbxString lString(lPassword); IOS_REF.SetStringProp(IMP_FBX_PASSWORD, lString); IOS_REF.SetBoolProp(IMP_FBX_PASSWORD_ENABLE, true); lStatus = lImporter->Import(pScene); - if(lStatus == false && lImporter->GetLastErrorID() == FbxIOBase::ePasswordError) + if(lStatus == false && lImporter->GetStatus().GetCode() == FbxStatus::EStatusCode::ePasswordError) { printf("\nPassword is wrong, import aborted.\n"); } @@ -561,8 +569,8 @@ KRAnimationLayer *LoadAnimationLayer(KRContext &context, FbxAnimLayer *pAnimLaye // } //} -void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode) { - KFbxVector4 lTmpVector; +void LoadNode(FbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pGeometryConverter, FbxNode* pNode) { + FbxVector4 lTmpVector; pNode->UpdatePropertiesFromPivotsAndLimits(); @@ -832,26 +840,26 @@ void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *p } } - fbxDouble3 local_rotation = pNode->LclRotation.Get(); // pNode->GetGeometricRotation(KFbxNode::eSourcePivot); - fbxDouble3 local_translation = pNode->LclTranslation.Get(); // pNode->GetGeometricTranslation(KFbxNode::eSourcePivot); - fbxDouble3 local_scale = pNode->LclScaling.Get(); // pNode->GetGeometricScaling(KFbxNode::eSourcePivot); + FbxDouble3 local_rotation = pNode->LclRotation.Get(); // pNode->GetGeometricRotation(KFbxNode::eSourcePivot); + FbxDouble3 local_translation = pNode->LclTranslation.Get(); // pNode->GetGeometricTranslation(KFbxNode::eSourcePivot); + FbxDouble3 local_scale = pNode->LclScaling.Get(); // pNode->GetGeometricScaling(KFbxNode::eSourcePivot); bool rotation_active = pNode->RotationActive.Get(); - fbxDouble3 post_rotation = pNode->PostRotation.Get(); - fbxDouble3 pre_rotation = pNode->PreRotation.Get(); - fbxDouble3 rotation_offset = pNode->RotationOffset.Get(); - fbxDouble3 scaling_offset = pNode->ScalingOffset.Get(); - fbxDouble3 rotation_pivot = pNode->RotationPivot.Get(); - fbxDouble3 scaling_pivot = pNode->ScalingPivot.Get(); - fbxDouble3 geometric_rotation = pNode->GeometricRotation.Get(); - fbxDouble3 geometric_translation = pNode->GeometricTranslation.Get(); - fbxDouble3 geometric_scaling = pNode->GeometricScaling.Get(); - ERotationOrder rotation_order = pNode->RotationOrder.Get(); + FbxDouble3 post_rotation = pNode->PostRotation.Get(); + FbxDouble3 pre_rotation = pNode->PreRotation.Get(); + FbxDouble3 rotation_offset = pNode->RotationOffset.Get(); + FbxDouble3 scaling_offset = pNode->ScalingOffset.Get(); + FbxDouble3 rotation_pivot = pNode->RotationPivot.Get(); + FbxDouble3 scaling_pivot = pNode->ScalingPivot.Get(); + FbxDouble3 geometric_rotation = pNode->GeometricRotation.Get(); + FbxDouble3 geometric_translation = pNode->GeometricTranslation.Get(); + FbxDouble3 geometric_scaling = pNode->GeometricScaling.Get(); + EFbxRotationOrder rotation_order = pNode->RotationOrder.Get(); - KFbxVector4 lZero(0.0, 0.0, 0.0); - KFbxVector4 lOne(1.0, 1.0, 1.0); + FbxVector4 lZero(0.0, 0.0, 0.0); + FbxVector4 lOne(1.0, 1.0, 1.0); assert(geometric_rotation == lZero); assert(geometric_translation == lZero); @@ -879,8 +887,8 @@ void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *p // printf(" Local Rotation: %f %f %f\n", local_rotation[0], local_rotation[1], local_rotation[2]); // printf(" Local Scaling: %f %f %f\n", local_scale[0], local_scale[1], local_scale[2]); - KFbxNodeAttribute::EType attribute_type = (pNode->GetNodeAttribute()->GetAttributeType()); - if(attribute_type == KFbxNodeAttribute::eLODGroup) { + FbxNodeAttribute::EType attribute_type = (pNode->GetNodeAttribute()->GetAttributeType()); + if(attribute_type == FbxNodeAttribute::eLODGroup) { std::string name = GetFbxObjectName(pNode); FbxLODGroup *fbx_lod_group = (FbxLODGroup*) pNode->GetNodeAttribute(); // FbxCast(pNode); bool use_world_space_units = fbx_lod_group->WorldSpace.Get(); @@ -964,25 +972,25 @@ void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *p } else { KRNode *new_node = NULL; switch(attribute_type) { - case KFbxNodeAttribute::eMesh: + case FbxNodeAttribute::eMesh: new_node = LoadMesh(parent_node, pFbxScene, pGeometryConverter, pNode); break; - case KFbxNodeAttribute::eLight: + case FbxNodeAttribute::eLight: new_node = LoadLight(parent_node, pNode); break; - case KFbxNodeAttribute::eSkeleton: + case FbxNodeAttribute::eSkeleton: new_node = LoadSkeleton(parent_node, pFbxScene, pNode); break; - case KFbxNodeAttribute::eCamera: + case FbxNodeAttribute::eCamera: new_node = LoadCamera(parent_node, pNode); break; default: { bool is_locator = false; - if(attribute_type == KFbxNodeAttribute::eNull) { - KFbxNull* pSourceNull = (KFbxNull*) pNode->GetNodeAttribute(); - if(pSourceNull->Look.Get() == KFbxNull::eCross ) { + if(attribute_type == FbxNodeAttribute::eNull) { + FbxNull* pSourceNull = (FbxNull*) pNode->GetNodeAttribute(); + if(pSourceNull->Look.Get() == FbxNull::eCross ) { is_locator = true; } } @@ -1059,7 +1067,7 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { FbxPropertyT lKFbxDouble3; FbxPropertyT lKFbxDouble1; - if (pMaterial->GetClassId().Is(KFbxSurfacePhong::ClassId)) { + if (pMaterial->GetClassId().Is(FbxSurfacePhong::ClassId)) { // We found a Phong material. // Ambient Color @@ -1067,11 +1075,11 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { new_material->setAmbient(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Diffuse Color - lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Diffuse; + lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Diffuse; new_material->setDiffuse(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Specular Color (unique to Phong materials) - lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Specular; + lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Specular; new_material->setSpecular(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Emissive Color @@ -1084,7 +1092,7 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { */ // Shininess - lKFbxDouble1 =((KFbxSurfacePhong *) pMaterial)->Shininess; + lKFbxDouble1 =((FbxSurfacePhong *) pMaterial)->Shininess; new_material->setShininess(lKFbxDouble1.Get()); /* @@ -1094,27 +1102,27 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { */ // Transparency Color - lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->TransparentColor; + lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->TransparentColor; new_material->setTransparency( 1.0f - (lKFbxDouble3.Get()[0] + lKFbxDouble3.Get()[1] + lKFbxDouble3.Get()[2]) / 3.0f); // Reflection factor - lKFbxDouble1 =((KFbxSurfacePhong *) pMaterial)->ReflectionFactor; + lKFbxDouble1 =((FbxSurfacePhong *) pMaterial)->ReflectionFactor; // Reflection color - lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Reflection; + lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Reflection; // We modulate Relection color by reflection factor, as we only have one "reflection color" variable in Kraken new_material->setReflection(KRVector3(lKFbxDouble3.Get()[0] * lKFbxDouble1.Get(), lKFbxDouble3.Get()[1] * lKFbxDouble1.Get(), lKFbxDouble3.Get()[2] * lKFbxDouble1.Get())); - } else if(pMaterial->GetClassId().Is(KFbxSurfaceLambert::ClassId) ) { + } else if(pMaterial->GetClassId().Is(FbxSurfaceLambert::ClassId) ) { // We found a Lambert material. // Ambient Color - lKFbxDouble3=((KFbxSurfaceLambert *)pMaterial)->Ambient; + lKFbxDouble3=((FbxSurfaceLambert *)pMaterial)->Ambient; new_material->setAmbient(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Diffuse Color - lKFbxDouble3 =((KFbxSurfaceLambert *)pMaterial)->Diffuse; + lKFbxDouble3 =((FbxSurfaceLambert *)pMaterial)->Diffuse; new_material->setDiffuse(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Emissive @@ -1126,7 +1134,7 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { */ // Transparency Color - lKFbxDouble3 =((KFbxSurfaceLambert *) pMaterial)->TransparentColor; + lKFbxDouble3 =((FbxSurfaceLambert *) pMaterial)->TransparentColor; new_material->setTransparency(1.0f - (lKFbxDouble3.Get()[0] + lKFbxDouble3.Get()[1] + lKFbxDouble3.Get()[2]) / 3.0f); } else { @@ -1135,31 +1143,31 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { - KFbxProperty pProperty; + FbxProperty pProperty; // Diffuse Map Texture - pProperty = pMaterial->FindProperty(KFbxSurfaceMaterial::sDiffuse); - if(pProperty.GetSrcObjectCount(KFbxLayeredTexture::ClassId) > 0) { + pProperty = pMaterial->FindProperty(FbxSurfaceMaterial::sDiffuse); + if(pProperty.GetSrcObjectCount(FbxLayeredTexture::ClassId) > 0) { printf("Warning! Layered textures not supported.\n"); } - int texture_count = pProperty.GetSrcObjectCount(KFbxTexture::ClassId); + int texture_count = pProperty.GetSrcObjectCount(FbxTexture::ClassId); if(texture_count > 1) { printf("Error! Multiple diffuse textures not supported.\n"); } else if(texture_count == 1) { - KFbxTexture* pTexture = FbxCast (pProperty.GetSrcObject(KFbxTexture::ClassId,0)); + FbxTexture* pTexture = FbxCast (pProperty.GetSrcObject(FbxTexture::ClassId,0)); assert(!pTexture->GetSwapUV()); assert(pTexture->GetCroppingTop() == 0); assert(pTexture->GetCroppingLeft() == 0); assert(pTexture->GetCroppingRight() == 0); assert(pTexture->GetCroppingBottom() == 0); - assert(pTexture->GetWrapModeU() == KFbxTexture::eRepeat); - assert(pTexture->GetWrapModeV() == KFbxTexture::eRepeat); + assert(pTexture->GetWrapModeU() == FbxTexture::eRepeat); + assert(pTexture->GetWrapModeV() == FbxTexture::eRepeat); assert(pTexture->GetRotationU() == 0.0f); assert(pTexture->GetRotationV() == 0.0f); assert(pTexture->GetRotationW() == 0.0f); - KFbxFileTexture *pFileTexture = FbxCast(pTexture); + FbxFileTexture *pFileTexture = FbxCast(pTexture); if(pFileTexture) { new_material->setDiffuseMap(KRResource::GetFileBase(pFileTexture->GetFileName()), KRVector2(pTexture->GetScaleU(), pTexture->GetScaleV()), KRVector2(pTexture->GetTranslationU(), pTexture->GetTranslationV())); } @@ -1167,24 +1175,24 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { // Specular Map Texture - pProperty = pMaterial->FindProperty(KFbxSurfaceMaterial::sSpecular); - if(pProperty.GetSrcObjectCount(KFbxLayeredTexture::ClassId) > 0) { + pProperty = pMaterial->FindProperty(FbxSurfaceMaterial::sSpecular); + if(pProperty.GetSrcObjectCount(FbxLayeredTexture::ClassId) > 0) { printf("Warning! Layered textures not supported.\n"); } - texture_count = pProperty.GetSrcObjectCount(KFbxTexture::ClassId); + texture_count = pProperty.GetSrcObjectCount(FbxTexture::ClassId); if(texture_count > 1) { printf("Error! Multiple specular textures not supported.\n"); } else if(texture_count == 1) { - KFbxTexture* pTexture = FbxCast (pProperty.GetSrcObject(KFbxTexture::ClassId,0)); - KFbxFileTexture *pFileTexture = FbxCast(pTexture); + FbxTexture* pTexture = FbxCast (pProperty.GetSrcObject(FbxTexture::ClassId,0)); + FbxFileTexture *pFileTexture = FbxCast(pTexture); if(pFileTexture) { new_material->setSpecularMap(KRResource::GetFileBase(pFileTexture->GetFileName()), KRVector2(pTexture->GetScaleU(), pTexture->GetScaleV()), KRVector2(pTexture->GetTranslationU(), pTexture->GetTranslationV())); } } // Normal Map Texture - pProperty = pMaterial->FindProperty(KFbxSurfaceMaterial::sNormalMap); - if(pProperty.GetSrcObjectCount(KFbxLayeredTexture::ClassId) > 0) { + pProperty = pMaterial->FindProperty(FbxSurfaceMaterial::sNormalMap); + if(pProperty.GetSrcObjectCount(FbxLayeredTexture::ClassId) > 0) { printf("Warning! Layered textures not supported.\n"); } @@ -1193,8 +1201,8 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { if(texture_count > 1) { printf("Error! Multiple normal map textures not supported.\n"); } else if(texture_count == 1) { - KFbxTexture* pTexture = pProperty.GetSrcObject(0); - KFbxFileTexture *pFileTexture = FbxCast(pTexture); + FbxTexture* pTexture = pProperty.GetSrcObject(0); + FbxFileTexture *pFileTexture = FbxCast(pTexture); if(pFileTexture) { new_material->setNormalMap(KRResource::GetFileBase(pFileTexture->GetFileName()), KRVector2(pTexture->GetScaleU(), pTexture->GetScaleV()), KRVector2(pTexture->GetTranslationU(), pTexture->GetTranslationV())); } @@ -1211,8 +1219,8 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { -void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, KFbxMesh* pSourceMesh) { - KFbxMesh* pMesh = pGeometryConverter->TriangulateMesh(pSourceMesh); +void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, FbxMesh* pSourceMesh) { + FbxMesh* pMesh = pGeometryConverter->TriangulateMesh(pSourceMesh); KRMesh::mesh_info mi; mi.format = KRMesh::KRENGINE_MODEL_FORMAT_TRIANGLES; @@ -1223,7 +1231,7 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG } control_point_weight_info_t; int control_point_count = pMesh->GetControlPointsCount(); - KFbxVector4* control_points = pMesh->GetControlPoints(); + FbxVector4* control_points = pMesh->GetControlPoints(); control_point_weight_info_t *control_point_weights = new control_point_weight_info_t[control_point_count]; for(int control_point=0; control_point < control_point_count; control_point++) { @@ -1346,7 +1354,7 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG bool need_tangents = false; for(int iMaterial=0; iMaterial < material_count; iMaterial++) { - KFbxSurfaceMaterial *pMaterial = pSourceMesh->GetNode()->GetMaterial(iMaterial); + FbxSurfaceMaterial *pMaterial = pSourceMesh->GetNode()->GetMaterial(iMaterial); KRMaterial *material = context.getMaterialManager()->getMaterial(pMaterial->GetName()); if(material) { @@ -1384,7 +1392,7 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG for(int iVertex=0; iVertex<3; iVertex++) { // ----====---- Read Vertex Position ----====---- int lControlPointIndex = pMesh->GetPolygonVertex(iPolygon, iVertex); - KFbxVector4 v = control_points[lControlPointIndex]; + FbxVector4 v = control_points[lControlPointIndex]; mi.vertices.push_back(KRVector3(v[0], v[1], v[2])); if(mi.bone_names.size() > 0) { @@ -1405,12 +1413,14 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG // ----====---- Read UVs ----====---- - KStringList uvNames; + FbxStringList uvNames; pMesh->GetUVSetNames(uvNames); if(uv_count >= 1) { const char *setName = uvNames[0].Buffer(); - KFbxVector2 uv; - if(pMesh->GetPolygonVertexUV(iPolygon, iVertex, setName, uv)) { + FbxVector2 uv; + bool unmapped = false; + if(pMesh->GetPolygonVertexUV(iPolygon, iVertex, setName, uv, unmapped)) { + assert(!unmapped); new_uva = KRVector2(uv[0], uv[1]); } mi.uva.push_back(new_uva); @@ -1418,8 +1428,10 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG if(uv_count >= 2) { const char *setName = uvNames[1].Buffer(); - KFbxVector2 uv; - if(pMesh->GetPolygonVertexUV(iPolygon, iVertex, setName, uv)) { + FbxVector2 uv; + bool unmapped = false; + if(pMesh->GetPolygonVertexUV(iPolygon, iVertex, setName, uv, unmapped)) { + assert(!unmapped); new_uvb = KRVector2(uv[0], uv[1]); } mi.uvb.push_back(new_uvb); @@ -1427,7 +1439,7 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG // ----====---- Read Normals ----====---- - KFbxVector4 new_normal; + FbxVector4 new_normal; if(pMesh->GetPolygonVertexNormal(iPolygon, iVertex, new_normal)) { mi.normals.push_back(KRVector3(new_normal[0], new_normal[1], new_normal[2])); } @@ -1436,7 +1448,7 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG // ----====---- Read Tangents ----====---- for(int l = 0; l < tangent_count; ++l) { - KFbxVector4 new_tangent; + FbxVector4 new_tangent; FbxGeometryElementTangent* leTangent = pMesh->GetElementTangent(l); if(leTangent->GetMappingMode() == FbxGeometryElement::eByPolygonVertex) { @@ -1488,10 +1500,10 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG context.getModelManager()->addModel(new_mesh); } -KRNode *LoadMesh(KRNode *parent_node, KFbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode) { +KRNode *LoadMesh(KRNode *parent_node, FbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, FbxNode* pNode) { std::string name = GetFbxObjectName(pNode); - KFbxMesh* pSourceMesh = (KFbxMesh*) pNode->GetNodeAttribute(); + FbxMesh* pSourceMesh = (FbxMesh*) pNode->GetNodeAttribute(); if(KRMesh::GetLODCoverage(pNode->GetName()) == 100) { // If this is the full detail model, add an instance of it to the scene file @@ -1516,7 +1528,7 @@ KRNode *LoadMesh(KRNode *parent_node, KFbxScene* pFbxScene, FbxGeometryConverter } -KRNode *LoadSkeleton(KRNode *parent_node, FbxScene* pFbxScene, KFbxNode* pNode) { +KRNode *LoadSkeleton(KRNode *parent_node, FbxScene* pFbxScene, FbxNode* pNode) { std::string name = GetFbxObjectName(pNode); KRBone *new_bone = new KRBone(parent_node->getScene(), name.c_str()); @@ -1530,7 +1542,7 @@ KRNode *LoadSkeleton(KRNode *parent_node, FbxScene* pFbxScene, KFbxNode* pNode) return new_bone; } -KRNode *LoadLocator(KRNode *parent_node, FbxScene* pFbxScene, KFbxNode* pNode) { +KRNode *LoadLocator(KRNode *parent_node, FbxScene* pFbxScene, FbxNode* pNode) { std::string name = GetFbxObjectName(pNode); KRLocator *new_locator = new KRLocator(parent_node->getScene(), name.c_str()); @@ -1545,7 +1557,7 @@ KRNode *LoadLocator(KRNode *parent_node, FbxScene* pFbxScene, KFbxNode* pNode) { return new_locator; } -KRNode *LoadCamera(KRNode *parent_node, KFbxNode* pNode) { +KRNode *LoadCamera(KRNode *parent_node, FbxNode* pNode) { FbxCamera *camera = (FbxCamera *)pNode->GetNodeAttribute(); const char *szName = pNode->GetName(); @@ -1553,7 +1565,7 @@ KRNode *LoadCamera(KRNode *parent_node, KFbxNode* pNode) { return new_camera; } -KRNode *LoadLight(KRNode *parent_node, KFbxNode* pNode) { +KRNode *LoadLight(KRNode *parent_node, FbxNode* pNode) { const GLfloat PI = 3.14159265; const GLfloat d2r = PI * 2 / 360; @@ -1564,7 +1576,7 @@ KRNode *LoadLight(KRNode *parent_node, KFbxNode* pNode) { FbxDouble light_intensity = pLight->Intensity.Get(); FbxDouble light_hotspot = pLight->InnerAngle.Get(); // light inner cone angle (in degrees). Also know as the HotSpot FbxDouble light_coneangle = pLight->OuterAngle.Get(); // light outer cone angle (in degrees). Also known as the Falloff - KFbxLight::EDecayType light_decaytype = pLight->DecayType.Get(); // decay type + FbxLight::EDecayType light_decaytype = pLight->DecayType.Get(); // decay type FbxDouble light_decaystart = pLight->DecayStart.Get(); // decay start distance @@ -1576,20 +1588,20 @@ KRNode *LoadLight(KRNode *parent_node, KFbxNode* pNode) { KRLight *new_light = NULL; switch(pLight->LightType.Get()) { - case KFbxLight::ePoint: + case FbxLight::ePoint: { KRPointLight *l = new KRPointLight(parent_node->getScene(), szName); new_light = l; } break; - case KFbxLight::eDirectional: + case FbxLight::eDirectional: { KRDirectionalLight *l = new KRDirectionalLight(parent_node->getScene(), szName); new_light = l; } break; - case KFbxLight::eSpot: + case FbxLight::eSpot: { KRSpotLight *l = new KRSpotLight(parent_node->getScene(), szName); l->setInnerAngle(light_hotspot * d2r); @@ -1597,8 +1609,8 @@ KRNode *LoadLight(KRNode *parent_node, KFbxNode* pNode) { new_light = l; } break; - case KFbxLight::eVolume: - case KFbxLight::eArea: + case FbxLight::eVolume: + case FbxLight::eArea: // Not supported yet break; } diff --git a/KREngine/kraken/KRTextureStreamer.mm b/KREngine/kraken/KRTextureStreamer.mm index 5dc8682..46043cc 100644 --- a/KREngine/kraken/KRTextureStreamer.mm +++ b/KREngine/kraken/KRTextureStreamer.mm @@ -13,8 +13,21 @@ #include + +#if TARGET_OS_IPHONE + EAGLContext *gTextureStreamerContext = nil; +#elif TARGET_OS_MAC + +NSOpenGLContext *gTextureStreamerContext = nil; + +#else + +#error Unsupported Platform +#endif + + KRTextureStreamer::KRTextureStreamer(KRContext &context) : m_context(context) { m_running = false; @@ -25,7 +38,27 @@ void KRTextureStreamer::startStreamer() { if(!m_running) { m_running = true; + +#if TARGET_OS_IPHONE + gTextureStreamerContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup: [EAGLContext currentContext].sharegroup]; + + +#elif TARGET_OS_MAC + + NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = + { + NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, + 0 + }; + NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes] autorelease]; + gTextureStreamerContext = [[[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext: [NSOpenGLContext currentContext] ] autorelease]; + +#else + + #error Unsupported Platform +#endif + m_thread = std::thread(&KRTextureStreamer::run, this); } } @@ -43,7 +76,14 @@ void KRTextureStreamer::run() pthread_setname_np("Kraken - Texture Streamer"); std::chrono::microseconds sleep_duration( 100 ); + +#if TARGET_OS_IPHONE [EAGLContext setCurrentContext: gTextureStreamerContext]; +#elif TARGET_OS_MAC + [gTextureStreamerContext makeCurrentContext]; +#else +#error Unsupported Platform +#endif while(!m_stop) { From 61fde7700b91f53fc0279fa1aabce2182df4d372 Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Sat, 23 Nov 2013 17:02:17 -0800 Subject: [PATCH 12/12] Fixed crash in fbx import pipeline --- KREngine/kraken/KRMesh.cpp | 8 ++--- KREngine/kraken/KRMesh.h | 3 -- KREngine/kraken/KRMeshStreamer.h | 3 ++ KREngine/kraken/KRMeshStreamer.mm | 47 +++++++++++++++++----------- KREngine/kraken/KRTextureStreamer.h | 1 - KREngine/kraken/KRTextureStreamer.mm | 10 +++--- 6 files changed, 40 insertions(+), 32 deletions(-) diff --git a/KREngine/kraken/KRMesh.cpp b/KREngine/kraken/KRMesh.cpp index 5082a07..7e0e88c 100644 --- a/KREngine/kraken/KRMesh.cpp +++ b/KREngine/kraken/KRMesh.cpp @@ -110,6 +110,8 @@ KRMesh::~KRMesh() { } void KRMesh::releaseData() { + m_hasTransparency = false; + m_submeshes.clear(); if(m_pIndexBaseData) { m_pIndexBaseData->unlock(); delete m_pIndexBaseData; @@ -397,7 +399,7 @@ void KRMesh::renderSubmesh(int iSubmesh, KRNode::RenderPass renderPass, const st void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool calculate_tangents) { - clearBuffers(); + releaseData(); // TODO, FINDME - These values should be passed as a parameter and set by GUI flags bool use_short_vertexes = false; @@ -645,10 +647,6 @@ KRVector3 KRMesh::getMaxPoint() const { return m_maxPoint; } -void KRMesh::clearBuffers() { - m_submeshes.clear(); -} - int KRMesh::getLODCoverage() const { return m_lodCoverage; } diff --git a/KREngine/kraken/KRMesh.h b/KREngine/kraken/KRMesh.h index 602a5a6..eecacc2 100644 --- a/KREngine/kraken/KRMesh.h +++ b/KREngine/kraken/KRMesh.h @@ -250,9 +250,6 @@ private: int m_vertex_size; void updateAttributeOffsets(); - - void clearBuffers(); - void setName(const std::string name); diff --git a/KREngine/kraken/KRMeshStreamer.h b/KREngine/kraken/KRMeshStreamer.h index a0c36e9..beb3666 100644 --- a/KREngine/kraken/KRMeshStreamer.h +++ b/KREngine/kraken/KRMeshStreamer.h @@ -45,11 +45,14 @@ public: KRMeshStreamer(KRContext &context); ~KRMeshStreamer(); + void startStreamer(); + private: KRContext &m_context; std::thread m_thread; std::atomic m_stop; + std::atomic m_running; void run(); }; diff --git a/KREngine/kraken/KRMeshStreamer.mm b/KREngine/kraken/KRMeshStreamer.mm index 3067fe3..1fd6560 100644 --- a/KREngine/kraken/KRMeshStreamer.mm +++ b/KREngine/kraken/KRMeshStreamer.mm @@ -28,29 +28,40 @@ NSOpenGLContext *gMeshStreamerContext = nil; KRMeshStreamer::KRMeshStreamer(KRContext &context) : m_context(context) { - -#if TARGET_OS_IPHONE - gMeshStreamerContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup: [EAGLContext currentContext].sharegroup]; -#elif TARGET_OS_MAC - NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = - { - NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, - 0 - }; - NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes] autorelease]; - gMeshStreamerContext = [[[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext: [NSOpenGLContext currentContext] ] autorelease]; -#else - #error Unsupported Platform -#endif - + m_running = false; m_stop = false; - m_thread = std::thread(&KRMeshStreamer::run, this); +} + +void KRMeshStreamer::startStreamer() +{ + if(!m_running) { + m_running = true; + +#if TARGET_OS_IPHONE + gMeshStreamerContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup: [EAGLContext currentContext].sharegroup]; +#elif TARGET_OS_MAC + NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = + { + NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, + 0 + }; + NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes] autorelease]; + gMeshStreamerContext = [[[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext: [NSOpenGLContext currentContext] ] autorelease]; +#else + #error Unsupported Platform +#endif + + m_thread = std::thread(&KRMeshStreamer::run, this); + } } KRMeshStreamer::~KRMeshStreamer() { - m_stop = true; - m_thread.join(); + if(m_running) { + m_stop = true; + m_thread.join(); + m_running = false; + } [gMeshStreamerContext release]; } diff --git a/KREngine/kraken/KRTextureStreamer.h b/KREngine/kraken/KRTextureStreamer.h index 22dbdb0..39f3705 100644 --- a/KREngine/kraken/KRTextureStreamer.h +++ b/KREngine/kraken/KRTextureStreamer.h @@ -55,7 +55,6 @@ private: std::atomic m_running; void run(); - }; #endif /* defined(KRTEXTURESTREAMER_H) */ diff --git a/KREngine/kraken/KRTextureStreamer.mm b/KREngine/kraken/KRTextureStreamer.mm index 46043cc..5185c22 100644 --- a/KREngine/kraken/KRTextureStreamer.mm +++ b/KREngine/kraken/KRTextureStreamer.mm @@ -27,7 +27,6 @@ NSOpenGLContext *gTextureStreamerContext = nil; #error Unsupported Platform #endif - KRTextureStreamer::KRTextureStreamer(KRContext &context) : m_context(context) { m_running = false; @@ -65,8 +64,11 @@ void KRTextureStreamer::startStreamer() KRTextureStreamer::~KRTextureStreamer() { - m_stop = true; - m_thread.join(); + if(m_running) { + m_stop = true; + m_thread.join(); + m_running = false; + } [gTextureStreamerContext release]; } @@ -92,6 +94,4 @@ void KRTextureStreamer::run() } std::this_thread::sleep_for( sleep_duration ); } - - m_running = false; }