From 1712059f0a3d08359eb18f3ffa4f1e206d207b8e Mon Sep 17 00:00:00 2001 From: kearwood Date: Wed, 9 Jan 2013 22:37:23 +0000 Subject: [PATCH] Changed naming conventions: - KRModel renamed to KRMesh - KRModelManager renamed to KRMeshManager - KRInstance renamed to KRModel - "instance" in scene graph xml is now "model" Implemented layer masks for line and ray casting Implemented KRReverbZone object, to be later wired into audio engine to select reverb preset based on listener proximity --HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40211 --- KREngine/KREngine.xcodeproj/project.pbxproj | 174 ++-- KREngine/KREngine/Classes/KRAudioManager.cpp | 5 + KREngine/KREngine/Classes/KRAudioSource.cpp | 2 +- KREngine/KREngine/Classes/KRBone.cpp | 2 +- KREngine/KREngine/Classes/KRCamera.cpp | 4 +- KREngine/KREngine/Classes/KRCamera.h | 2 +- KREngine/KREngine/Classes/KRCollider.cpp | 90 +- KREngine/KREngine/Classes/KRCollider.h | 29 +- KREngine/KREngine/Classes/KRContext.cpp | 6 +- KREngine/KREngine/Classes/KRContext.h | 6 +- KREngine/KREngine/Classes/KREngine-common.h | 4 + KREngine/KREngine/Classes/KREngine.h | 2 +- KREngine/KREngine/Classes/KRInstance.cpp | 166 ---- KREngine/KREngine/Classes/KRInstance.h | 83 -- KREngine/KREngine/Classes/KRLight.cpp | 6 +- KREngine/KREngine/Classes/KRMesh.cpp | 855 +++++++++++++++++ KREngine/KREngine/Classes/KRMesh.h | 239 +++++ .../{KRModelCube.cpp => KRMeshCube.cpp} | 8 +- .../Classes/{KRModelCube.h => KRMeshCube.h} | 14 +- .../{KRModelManager.cpp => KRMeshManager.cpp} | 112 +-- .../{KRModelManager.h => KRMeshManager.h} | 24 +- .../{KRModelSphere.cpp => KRMeshSphere.cpp} | 8 +- .../{KRModelSphere.h => KRMeshSphere.h} | 14 +- KREngine/KREngine/Classes/KRModel.cpp | 897 ++---------------- KREngine/KREngine/Classes/KRModel.h | 220 +---- KREngine/KREngine/Classes/KRNode.cpp | 11 +- KREngine/KREngine/Classes/KRNode.h | 2 +- KREngine/KREngine/Classes/KROctree.cpp | 12 +- KREngine/KREngine/Classes/KROctree.h | 4 +- KREngine/KREngine/Classes/KROctreeNode.cpp | 16 +- KREngine/KREngine/Classes/KROctreeNode.h | 4 +- .../Classes/KRParticleSystemNewtonian.cpp | 4 +- KREngine/KREngine/Classes/KRPointLight.cpp | 2 +- KREngine/KREngine/Classes/KRPointLight.h | 4 +- KREngine/KREngine/Classes/KRQuaternion.h | 4 +- KREngine/KREngine/Classes/KRResource+blend.h | 4 +- KREngine/KREngine/Classes/KRResource+fbx.cpp | 26 +- KREngine/KREngine/Classes/KRResource+obj.cpp | 14 +- KREngine/KREngine/Classes/KRResource.h | 4 +- KREngine/KREngine/Classes/KRReverbZone.cpp | 134 +++ KREngine/KREngine/Classes/KRReverbZone.h | 42 + KREngine/KREngine/Classes/KRScene.cpp | 8 +- KREngine/KREngine/Classes/KRScene.h | 12 +- KREngine/KREngine/Classes/KRShader.cpp | 14 +- 44 files changed, 1781 insertions(+), 1512 deletions(-) delete mode 100644 KREngine/KREngine/Classes/KRInstance.cpp delete mode 100644 KREngine/KREngine/Classes/KRInstance.h create mode 100644 KREngine/KREngine/Classes/KRMesh.cpp create mode 100644 KREngine/KREngine/Classes/KRMesh.h rename KREngine/KREngine/Classes/{KRModelCube.cpp => KRMeshCube.cpp} (95%) rename KREngine/KREngine/Classes/{KRModelCube.h => KRMeshCube.h} (89%) rename KREngine/KREngine/Classes/{KRModelManager.cpp => KRMeshManager.cpp} (69%) rename KREngine/KREngine/Classes/{KRModelManager.h => KRMeshManager.h} (85%) rename KREngine/KREngine/Classes/{KRModelSphere.cpp => KRMeshSphere.cpp} (96%) rename KREngine/KREngine/Classes/{KRModelSphere.h => KRMeshSphere.h} (89%) create mode 100644 KREngine/KREngine/Classes/KRReverbZone.cpp create mode 100644 KREngine/KREngine/Classes/KRReverbZone.h diff --git a/KREngine/KREngine.xcodeproj/project.pbxproj b/KREngine/KREngine.xcodeproj/project.pbxproj index 7e5926c..1355ebd 100644 --- a/KREngine/KREngine.xcodeproj/project.pbxproj +++ b/KREngine/KREngine.xcodeproj/project.pbxproj @@ -17,8 +17,8 @@ E40BA45515EFF79500D7C3DD /* KRAABB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E40BA45215EFF79500D7C3DD /* KRAABB.cpp */; }; E40BA45615EFF79500D7C3DD /* KRAABB.h in Headers */ = {isa = PBXBuildFile; fileRef = E40BA45315EFF79500D7C3DD /* KRAABB.h */; }; E40BA45715EFF79500D7C3DD /* KRAABB.h in Headers */ = {isa = PBXBuildFile; fileRef = E40BA45315EFF79500D7C3DD /* KRAABB.h */; settings = {ATTRIBUTES = (Public, ); }; }; - E414BAE21435557300A668C4 /* KRInstance.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAE11435557300A668C4 /* KRInstance.h */; }; - E414BAE51435558900A668C4 /* KRInstance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E414BAE41435558800A668C4 /* KRInstance.cpp */; }; + E414BAE21435557300A668C4 /* KRModel.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAE11435557300A668C4 /* KRModel.h */; }; + E414BAE51435558900A668C4 /* KRModel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E414BAE41435558800A668C4 /* KRModel.cpp */; }; E414BAE7143557D200A668C4 /* KRScene.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAE6143557D200A668C4 /* KRScene.h */; }; E414BAE91435585A00A668C4 /* KRScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E414BAE81435585A00A668C4 /* KRScene.cpp */; }; E414F9A61694D977000B3D58 /* KRUnknownManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E414F9A41694D977000B3D58 /* KRUnknownManager.cpp */; }; @@ -132,7 +132,7 @@ E48B68151697794F00D99917 /* KRAudioSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E48B68131697794F00D99917 /* KRAudioSource.cpp */; }; E48B68161697794F00D99917 /* KRAudioSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E48B68131697794F00D99917 /* KRAudioSource.cpp */; }; E48B68171697794F00D99917 /* KRAudioSource.h in Headers */ = {isa = PBXBuildFile; fileRef = E48B68141697794F00D99917 /* KRAudioSource.h */; }; - E48B68181697794F00D99917 /* KRAudioSource.h in Headers */ = {isa = PBXBuildFile; fileRef = E48B68141697794F00D99917 /* KRAudioSource.h */; }; + E48B68181697794F00D99917 /* KRAudioSource.h in Headers */ = {isa = PBXBuildFile; fileRef = E48B68141697794F00D99917 /* KRAudioSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; E48C696F15374F5B00232E28 /* KRContext.h in Headers */ = {isa = PBXBuildFile; fileRef = E48C696E15374F5A00232E28 /* KRContext.h */; }; E48C697015374F5B00232E28 /* KRContext.h in Headers */ = {isa = PBXBuildFile; fileRef = E48C696E15374F5A00232E28 /* KRContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; E48C697215374F7E00232E28 /* KRContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E48C697115374F7E00232E28 /* KRContext.cpp */; }; @@ -141,8 +141,8 @@ E491018A13C99BDC0098455B /* KREngine.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017213C99BDC0098455B /* KREngine.h */; settings = {ATTRIBUTES = (); }; }; E491018E13C99BDC0098455B /* KRMat4.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017613C99BDC0098455B /* KRMat4.h */; settings = {ATTRIBUTES = (); }; }; E491018F13C99BDC0098455B /* KRMat4.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017713C99BDC0098455B /* KRMat4.cpp */; }; - E491019113C99BDC0098455B /* KRModel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017913C99BDC0098455B /* KRModel.cpp */; }; - E491019213C99BDC0098455B /* KRModel.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017A13C99BDC0098455B /* KRModel.h */; settings = {ATTRIBUTES = (); }; }; + E491019113C99BDC0098455B /* KRMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017913C99BDC0098455B /* KRMesh.cpp */; }; + E491019213C99BDC0098455B /* KRMesh.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017A13C99BDC0098455B /* KRMesh.h */; settings = {ATTRIBUTES = (); }; }; E491019313C99BDC0098455B /* KRMaterialManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017B13C99BDC0098455B /* KRMaterialManager.cpp */; }; E491019413C99BDC0098455B /* KRMaterial.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017C13C99BDC0098455B /* KRMaterial.cpp */; }; E491019513C99BDC0098455B /* KRMaterial.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017D13C99BDC0098455B /* KRMaterial.h */; settings = {ATTRIBUTES = (); }; }; @@ -150,8 +150,8 @@ E491019713C99BDC0098455B /* KRVector3.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017F13C99BDC0098455B /* KRVector3.cpp */; }; E491019813C99BDC0098455B /* KRTextureManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491018013C99BDC0098455B /* KRTextureManager.cpp */; }; E491019913C99BDC0098455B /* KRTexture2D.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491018113C99BDC0098455B /* KRTexture2D.cpp */; }; - E491019A13C99BDC0098455B /* KRModelManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491018213C99BDC0098455B /* KRModelManager.cpp */; }; - E491019B13C99BDC0098455B /* KRModelManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018313C99BDC0098455B /* KRModelManager.h */; settings = {ATTRIBUTES = (); }; }; + E491019A13C99BDC0098455B /* KRMeshManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491018213C99BDC0098455B /* KRMeshManager.cpp */; }; + E491019B13C99BDC0098455B /* KRMeshManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018313C99BDC0098455B /* KRMeshManager.h */; settings = {ATTRIBUTES = (); }; }; E491019C13C99BDC0098455B /* KRMaterialManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018413C99BDC0098455B /* KRMaterialManager.h */; settings = {ATTRIBUTES = (); }; }; E491019D13C99BDC0098455B /* KRTextureManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018513C99BDC0098455B /* KRTextureManager.h */; settings = {ATTRIBUTES = (); }; }; E491019E13C99BDC0098455B /* KRTexture2D.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018613C99BDC0098455B /* KRTexture2D.h */; settings = {ATTRIBUTES = (); }; }; @@ -160,6 +160,10 @@ E4924C2715EE95E800B965C6 /* KROctree.h in Headers */ = {isa = PBXBuildFile; fileRef = E4924C2515EE95E800B965C6 /* KROctree.h */; }; E4924C2B15EE96AB00B965C6 /* KROctreeNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4924C2915EE96AA00B965C6 /* KROctreeNode.cpp */; }; E4924C2C15EE96AB00B965C6 /* KROctreeNode.h in Headers */ = {isa = PBXBuildFile; fileRef = E4924C2A15EE96AA00B965C6 /* KROctreeNode.h */; }; + E4943231169E08D200BCB891 /* KRReverbZone.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E494322F169E08D200BCB891 /* KRReverbZone.cpp */; }; + E4943232169E08D200BCB891 /* KRReverbZone.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E494322F169E08D200BCB891 /* KRReverbZone.cpp */; }; + E4943233169E08D200BCB891 /* KRReverbZone.h in Headers */ = {isa = PBXBuildFile; fileRef = E4943230169E08D200BCB891 /* KRReverbZone.h */; }; + E4943234169E08D200BCB891 /* KRReverbZone.h in Headers */ = {isa = PBXBuildFile; fileRef = E4943230169E08D200BCB891 /* KRReverbZone.h */; settings = {ATTRIBUTES = (Public, ); }; }; E497B946151BA99500D3DC67 /* KRVector2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E497B945151BA99400D3DC67 /* KRVector2.cpp */; }; E497B947151BA99500D3DC67 /* KRVector2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E497B945151BA99400D3DC67 /* KRVector2.cpp */; }; E497B948151BB89D00D3DC67 /* KRVector2.h in Headers */ = {isa = PBXBuildFile; fileRef = E497B943151BA93400D3DC67 /* KRVector2.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -195,14 +199,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 */; settings = {ATTRIBUTES = (Public, ); }; }; - 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 */; settings = {ATTRIBUTES = (Public, ); }; }; - E4C454B5167BC05C003586CD /* KRModelSphere.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C454B4167BC05C003586CD /* KRModelSphere.cpp */; }; - E4C454B6167BC05C003586CD /* KRModelSphere.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C454B4167BC05C003586CD /* KRModelSphere.cpp */; }; + E4C454AC167BB8EC003586CD /* KRMeshCube.h in Headers */ = {isa = PBXBuildFile; fileRef = E4C454AB167BB8EC003586CD /* KRMeshCube.h */; }; + E4C454AD167BB8EC003586CD /* KRMeshCube.h in Headers */ = {isa = PBXBuildFile; fileRef = E4C454AB167BB8EC003586CD /* KRMeshCube.h */; settings = {ATTRIBUTES = (Public, ); }; }; + E4C454AF167BB8FC003586CD /* KRMeshCube.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C454AE167BB8FC003586CD /* KRMeshCube.cpp */; }; + E4C454B0167BB8FC003586CD /* KRMeshCube.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C454AE167BB8FC003586CD /* KRMeshCube.cpp */; }; + E4C454B2167BC04C003586CD /* KRMeshSphere.h in Headers */ = {isa = PBXBuildFile; fileRef = E4C454B1167BC04B003586CD /* KRMeshSphere.h */; }; + E4C454B3167BC04C003586CD /* KRMeshSphere.h in Headers */ = {isa = PBXBuildFile; fileRef = E4C454B1167BC04B003586CD /* KRMeshSphere.h */; settings = {ATTRIBUTES = (Public, ); }; }; + E4C454B5167BC05C003586CD /* KRMeshSphere.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C454B4167BC05C003586CD /* KRMeshSphere.cpp */; }; + E4C454B6167BC05C003586CD /* KRMeshSphere.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C454B4167BC05C003586CD /* KRMeshSphere.cpp */; }; E4C454B8167BD236003586CD /* KRHitInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = E4C454B7167BD235003586CD /* KRHitInfo.h */; }; E4C454B9167BD236003586CD /* KRHitInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = E4C454B7167BD235003586CD /* KRHitInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; E4C454BB167BD248003586CD /* KRHitInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C454BA167BD248003586CD /* KRHitInfo.cpp */; }; @@ -229,33 +233,35 @@ E4F027C716979CCD00D4427D /* KRAudioManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4F027C516979CCD00D4427D /* KRAudioManager.cpp */; }; E4F027C816979CCD00D4427D /* KRAudioManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4F027C516979CCD00D4427D /* KRAudioManager.cpp */; }; E4F027C916979CCD00D4427D /* KRAudioManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F027C616979CCD00D4427D /* KRAudioManager.h */; }; - E4F027CA16979CCD00D4427D /* KRAudioManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F027C616979CCD00D4427D /* KRAudioManager.h */; }; + E4F027CA16979CCD00D4427D /* KRAudioManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F027C616979CCD00D4427D /* KRAudioManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; E4F027CE16979CE200D4427D /* KRAudioSample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4F027CC16979CE200D4427D /* KRAudioSample.cpp */; }; E4F027CF16979CE200D4427D /* KRAudioSample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4F027CC16979CE200D4427D /* KRAudioSample.cpp */; }; E4F027D016979CE200D4427D /* KRAudioSample.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F027CD16979CE200D4427D /* KRAudioSample.h */; }; - E4F027D116979CE200D4427D /* KRAudioSample.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F027CD16979CE200D4427D /* KRAudioSample.h */; }; + E4F027D116979CE200D4427D /* KRAudioSample.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F027CD16979CE200D4427D /* KRAudioSample.h */; settings = {ATTRIBUTES = (Public, ); }; }; E4F027D31697A01300D4427D /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4F027D21697A01300D4427D /* OpenAL.framework */; }; E4F027D51697A02D00D4427D /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4F027D41697A02D00D4427D /* OpenAL.framework */; }; E4F027DE1697BFFF00D4427D /* KRAudioBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4F027DC1697BFFF00D4427D /* KRAudioBuffer.cpp */; }; E4F027DF1697BFFF00D4427D /* KRAudioBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4F027DC1697BFFF00D4427D /* KRAudioBuffer.cpp */; }; E4F027E01697BFFF00D4427D /* KRAudioBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F027DD1697BFFF00D4427D /* KRAudioBuffer.h */; }; - E4F027E11697BFFF00D4427D /* KRAudioBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F027DD1697BFFF00D4427D /* KRAudioBuffer.h */; }; + E4F027E11697BFFF00D4427D /* KRAudioBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F027DD1697BFFF00D4427D /* KRAudioBuffer.h */; settings = {ATTRIBUTES = (Public, ); }; }; + E4F027F71698115600D4427D /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4F027F61698115600D4427D /* AudioToolbox.framework */; }; + E4F027FA1698116000D4427D /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4F027F91698116000D4427D /* AudioToolbox.framework */; }; E4F975321536220900FD60B2 /* KRNode.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F975311536220900FD60B2 /* KRNode.h */; }; E4F975331536220900FD60B2 /* KRNode.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F975311536220900FD60B2 /* KRNode.h */; settings = {ATTRIBUTES = (Public, ); }; }; E4F975361536221C00FD60B2 /* KRNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4F975351536221C00FD60B2 /* KRNode.cpp */; }; E4F975371536221C00FD60B2 /* KRNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4F975351536221C00FD60B2 /* KRNode.cpp */; }; E4F9754015362CD400FD60B2 /* KRScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E414BAE81435585A00A668C4 /* KRScene.cpp */; }; E4F9754115362CD900FD60B2 /* KRScene.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAE6143557D200A668C4 /* KRScene.h */; settings = {ATTRIBUTES = (Public, ); }; }; - E4F9754215362D0D00FD60B2 /* KRInstance.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAE11435557300A668C4 /* KRInstance.h */; settings = {ATTRIBUTES = (Public, ); }; }; - E4F9754315362D0F00FD60B2 /* KRInstance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E414BAE41435558800A668C4 /* KRInstance.cpp */; }; - E4F975461536327C00FD60B2 /* KRModelManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018313C99BDC0098455B /* KRModelManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; + E4F9754215362D0D00FD60B2 /* KRModel.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAE11435557300A668C4 /* KRModel.h */; settings = {ATTRIBUTES = (Public, ); }; }; + E4F9754315362D0F00FD60B2 /* KRModel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E414BAE41435558800A668C4 /* KRModel.cpp */; }; + E4F975461536327C00FD60B2 /* KRMeshManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018313C99BDC0098455B /* KRMeshManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; E4F975491536329E00FD60B2 /* KRTextureManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018513C99BDC0098455B /* KRTextureManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; - E4F9754A153632AA00FD60B2 /* KRModelManager.cpp in Headers */ = {isa = PBXBuildFile; fileRef = E491018213C99BDC0098455B /* KRModelManager.cpp */; settings = {ATTRIBUTES = (Public, ); }; }; - E4F9754B153632D800FD60B2 /* KRModelManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491018213C99BDC0098455B /* KRModelManager.cpp */; }; + E4F9754A153632AA00FD60B2 /* KRMeshManager.cpp in Headers */ = {isa = PBXBuildFile; fileRef = E491018213C99BDC0098455B /* KRMeshManager.cpp */; settings = {ATTRIBUTES = (Public, ); }; }; + E4F9754B153632D800FD60B2 /* KRMeshManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491018213C99BDC0098455B /* KRMeshManager.cpp */; }; E4F9754C153632F000FD60B2 /* KRCamera.h in Headers */ = {isa = PBXBuildFile; fileRef = E48B3CBC14393DF5000C50E2 /* KRCamera.h */; settings = {ATTRIBUTES = (Public, ); }; }; E4F9754E1536331D00FD60B2 /* KRTextureManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491018013C99BDC0098455B /* KRTextureManager.cpp */; settings = {ATTRIBUTES = (Public, ); }; }; - E4F9754F1536333200FD60B2 /* KRModel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017913C99BDC0098455B /* KRModel.cpp */; }; - E4F975501536333500FD60B2 /* KRModel.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017A13C99BDC0098455B /* KRModel.h */; settings = {ATTRIBUTES = (Public, ); }; }; + E4F9754F1536333200FD60B2 /* KRMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017913C99BDC0098455B /* KRMesh.cpp */; }; + E4F975501536333500FD60B2 /* KRMesh.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017A13C99BDC0098455B /* KRMesh.h */; settings = {ATTRIBUTES = (Public, ); }; }; E4F97551153633E200FD60B2 /* KRMaterialManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017B13C99BDC0098455B /* KRMaterialManager.cpp */; }; E4F97552153633EF00FD60B2 /* KRMaterialManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018413C99BDC0098455B /* KRMaterialManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; E4F975531536340000FD60B2 /* KRTexture2D.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491018113C99BDC0098455B /* KRTexture2D.cpp */; }; @@ -275,14 +281,14 @@ /* End PBXBuildRule section */ /* Begin PBXFileReference section */ - 104A335C1672D31B001C8BA6 /* KRCollider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRCollider.cpp; path = Classes/KRCollider.cpp; sourceTree = ""; }; - 104A335D1672D31C001C8BA6 /* KRCollider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRCollider.h; path = Classes/KRCollider.h; sourceTree = ""; }; + 104A335C1672D31B001C8BA6 /* KRCollider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRCollider.cpp; path = Classes/KRCollider.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; + 104A335D1672D31C001C8BA6 /* KRCollider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRCollider.h; path = Classes/KRCollider.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; 10CC33A3168530A300BB9846 /* libPVRTexLib.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libPVRTexLib.a; path = PVRTexTool/Library/OSX_x86/Static/libPVRTexLib.a; sourceTree = PVRTexLib; }; E4030E4B160A3CF000592648 /* KRStockGeometry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRStockGeometry.h; path = Classes/KRStockGeometry.h; sourceTree = ""; }; E40BA45215EFF79500D7C3DD /* KRAABB.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRAABB.cpp; path = Classes/KRAABB.cpp; sourceTree = ""; }; E40BA45315EFF79500D7C3DD /* KRAABB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRAABB.h; path = Classes/KRAABB.h; sourceTree = ""; }; - E414BAE11435557300A668C4 /* KRInstance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRInstance.h; path = Classes/KRInstance.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; - E414BAE41435558800A668C4 /* KRInstance.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRInstance.cpp; path = Classes/KRInstance.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; + E414BAE11435557300A668C4 /* KRModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRModel.h; path = Classes/KRModel.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; + E414BAE41435558800A668C4 /* KRModel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRModel.cpp; path = Classes/KRModel.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E414BAE6143557D200A668C4 /* KRScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRScene.h; path = Classes/KRScene.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; E414BAE81435585A00A668C4 /* KRScene.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRScene.cpp; path = Classes/KRScene.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E414F9A41694D977000B3D58 /* KRUnknownManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRUnknownManager.cpp; path = Classes/KRUnknownManager.cpp; sourceTree = ""; }; @@ -312,7 +318,7 @@ E4324BA316444C0D0043185B /* KRParticleSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRParticleSystem.h; path = Classes/KRParticleSystem.h; sourceTree = ""; }; E4324BA716444C230043185B /* KRParticleSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRParticleSystem.cpp; path = Classes/KRParticleSystem.cpp; sourceTree = ""; }; E4324BAA16444DEF0043185B /* KRParticleSystemNewtonian.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRParticleSystemNewtonian.h; path = Classes/KRParticleSystemNewtonian.h; sourceTree = ""; }; - E4324BAD16444E120043185B /* KRParticleSystemNewtonian.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRParticleSystemNewtonian.cpp; path = Classes/KRParticleSystemNewtonian.cpp; sourceTree = ""; }; + E4324BAD16444E120043185B /* KRParticleSystemNewtonian.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRParticleSystemNewtonian.cpp; path = Classes/KRParticleSystemNewtonian.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E43B0AD415DDCA0C00A5CB9F /* KRContextObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRContextObject.cpp; path = Classes/KRContextObject.cpp; sourceTree = ""; }; E43B0AD515DDCA0D00A5CB9F /* KRContextObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRContextObject.h; path = Classes/KRContextObject.h; sourceTree = ""; }; E443C612164B5BE500FC4FD8 /* volumetric_fog.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = volumetric_fog.fsh; path = Shaders/volumetric_fog.fsh; sourceTree = ""; }; @@ -360,7 +366,7 @@ E47C25A613F4F6AB00FF4370 /* KRShaderManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRShaderManager.cpp; path = Classes/KRShaderManager.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E47C25A813F4F6DD00FF4370 /* KRShader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRShader.cpp; path = Classes/KRShader.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E480BE671671C641004EC8AD /* KRBone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRBone.h; path = Classes/KRBone.h; sourceTree = ""; }; - E480BE6B1671C653004EC8AD /* KRBone.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRBone.cpp; path = Classes/KRBone.cpp; sourceTree = ""; }; + E480BE6B1671C653004EC8AD /* KRBone.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRBone.cpp; path = Classes/KRBone.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E48278AE15F03010001C9431 /* visualize_overlay.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = visualize_overlay.vsh; path = Shaders/visualize_overlay.vsh; sourceTree = ""; }; E488399215F928CA00BD66D5 /* KRBundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRBundle.cpp; path = Classes/KRBundle.cpp; sourceTree = ""; }; E488399315F928CA00BD66D5 /* KRBundle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRBundle.h; path = Classes/KRBundle.h; sourceTree = ""; }; @@ -369,10 +375,10 @@ E48839A015F92C2800BD66D5 /* visualize_overlay.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = visualize_overlay.fsh; path = Shaders/visualize_overlay.fsh; sourceTree = ""; }; E48B3CBC14393DF5000C50E2 /* KRCamera.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRCamera.h; path = Classes/KRCamera.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; E48B3CBF14393E2F000C50E2 /* KRCamera.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRCamera.cpp; path = Classes/KRCamera.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; - E48B68131697794F00D99917 /* KRAudioSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRAudioSource.cpp; path = Classes/KRAudioSource.cpp; sourceTree = ""; }; + E48B68131697794F00D99917 /* KRAudioSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRAudioSource.cpp; path = Classes/KRAudioSource.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E48B68141697794F00D99917 /* KRAudioSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRAudioSource.h; path = Classes/KRAudioSource.h; sourceTree = ""; }; - E48C696E15374F5A00232E28 /* KRContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRContext.h; path = Classes/KRContext.h; sourceTree = ""; }; - E48C697115374F7E00232E28 /* KRContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRContext.cpp; path = Classes/KRContext.cpp; sourceTree = ""; }; + E48C696E15374F5A00232E28 /* KRContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRContext.h; path = Classes/KRContext.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; + E48C697115374F7E00232E28 /* KRContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRContext.cpp; path = Classes/KRContext.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E491016113C99B9E0098455B /* libKREngine.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libKREngine.a; sourceTree = BUILT_PRODUCTS_DIR; }; E491016413C99B9E0098455B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; E491016813C99B9E0098455B /* KREngine-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "KREngine-Prefix.pch"; sourceTree = ""; }; @@ -380,8 +386,8 @@ E491017213C99BDC0098455B /* KREngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KREngine.h; path = Classes/KREngine.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; E491017613C99BDC0098455B /* KRMat4.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRMat4.h; path = Classes/KRMat4.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; E491017713C99BDC0098455B /* KRMat4.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRMat4.cpp; path = Classes/KRMat4.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; - E491017913C99BDC0098455B /* KRModel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRModel.cpp; path = Classes/KRModel.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; - E491017A13C99BDC0098455B /* KRModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRModel.h; path = Classes/KRModel.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; + E491017913C99BDC0098455B /* KRMesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRMesh.cpp; path = Classes/KRMesh.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; + E491017A13C99BDC0098455B /* KRMesh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRMesh.h; path = Classes/KRMesh.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; E491017B13C99BDC0098455B /* KRMaterialManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRMaterialManager.cpp; path = Classes/KRMaterialManager.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E491017C13C99BDC0098455B /* KRMaterial.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRMaterial.cpp; path = Classes/KRMaterial.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E491017D13C99BDC0098455B /* KRMaterial.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRMaterial.h; path = Classes/KRMaterial.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; @@ -389,8 +395,8 @@ E491017F13C99BDC0098455B /* KRVector3.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRVector3.cpp; path = Classes/KRVector3.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E491018013C99BDC0098455B /* KRTextureManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRTextureManager.cpp; path = Classes/KRTextureManager.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E491018113C99BDC0098455B /* KRTexture2D.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRTexture2D.cpp; path = Classes/KRTexture2D.cpp; sourceTree = ""; }; - E491018213C99BDC0098455B /* KRModelManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRModelManager.cpp; path = Classes/KRModelManager.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; - E491018313C99BDC0098455B /* KRModelManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRModelManager.h; path = Classes/KRModelManager.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; + E491018213C99BDC0098455B /* KRMeshManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRMeshManager.cpp; path = Classes/KRMeshManager.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; + E491018313C99BDC0098455B /* KRMeshManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRMeshManager.h; path = Classes/KRMeshManager.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; E491018413C99BDC0098455B /* KRMaterialManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRMaterialManager.h; path = Classes/KRMaterialManager.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; E491018513C99BDC0098455B /* KRTextureManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRTextureManager.h; path = Classes/KRTextureManager.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; E491018613C99BDC0098455B /* KRTexture2D.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRTexture2D.h; path = Classes/KRTexture2D.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; @@ -399,12 +405,14 @@ E4924C2515EE95E800B965C6 /* KROctree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KROctree.h; path = Classes/KROctree.h; sourceTree = ""; }; E4924C2915EE96AA00B965C6 /* KROctreeNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KROctreeNode.cpp; path = Classes/KROctreeNode.cpp; sourceTree = ""; }; E4924C2A15EE96AA00B965C6 /* KROctreeNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KROctreeNode.h; path = Classes/KROctreeNode.h; sourceTree = ""; }; + E494322F169E08D200BCB891 /* KRReverbZone.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRReverbZone.cpp; path = Classes/KRReverbZone.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; + E4943230169E08D200BCB891 /* KRReverbZone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRReverbZone.h; path = Classes/KRReverbZone.h; sourceTree = ""; }; E497B943151BA93400D3DC67 /* KRVector2.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = KRVector2.h; path = Classes/KRVector2.h; sourceTree = ""; }; E497B945151BA99400D3DC67 /* KRVector2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRVector2.cpp; path = Classes/KRVector2.cpp; sourceTree = ""; }; E497B949151BCEE900D3DC67 /* KRResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRResource.h; path = Classes/KRResource.h; sourceTree = ""; }; E497B94C151BCF2500D3DC67 /* KRResource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRResource.cpp; path = Classes/KRResource.cpp; sourceTree = ""; }; - E497B94F151BD2CE00D3DC67 /* KRResource+obj.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "KRResource+obj.cpp"; path = "Classes/KRResource+obj.cpp"; sourceTree = ""; }; - E497B952151BEDA600D3DC67 /* KRResource+fbx.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "KRResource+fbx.cpp"; path = "Classes/KRResource+fbx.cpp"; sourceTree = ""; }; + E497B94F151BD2CE00D3DC67 /* KRResource+obj.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = "KRResource+obj.cpp"; path = "Classes/KRResource+obj.cpp"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; + E497B952151BEDA600D3DC67 /* KRResource+fbx.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = "KRResource+fbx.cpp"; path = "Classes/KRResource+fbx.cpp"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E497B95C151BF05F00D3DC67 /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = ../../../../MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; }; E497B95E151BF09600D3DC67 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = ../../../../MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; E4A9DEBD154120C4009DF363 /* light_point.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; lineEnding = 0; name = light_point.fsh; path = Shaders/light_point.fsh; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.glsl; }; @@ -423,10 +431,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 = ""; }; - E4C454AE167BB8FC003586CD /* KRModelCube.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRModelCube.cpp; path = Classes/KRModelCube.cpp; sourceTree = ""; }; - E4C454B1167BC04B003586CD /* KRModelSphere.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRModelSphere.h; path = Classes/KRModelSphere.h; sourceTree = ""; }; - E4C454B4167BC05C003586CD /* KRModelSphere.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRModelSphere.cpp; path = Classes/KRModelSphere.cpp; sourceTree = ""; }; + E4C454AB167BB8EC003586CD /* KRMeshCube.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRMeshCube.h; path = Classes/KRMeshCube.h; sourceTree = ""; }; + E4C454AE167BB8FC003586CD /* KRMeshCube.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRMeshCube.cpp; path = Classes/KRMeshCube.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; + E4C454B1167BC04B003586CD /* KRMeshSphere.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRMeshSphere.h; path = Classes/KRMeshSphere.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; + E4C454B4167BC05C003586CD /* KRMeshSphere.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRMeshSphere.cpp; path = Classes/KRMeshSphere.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E4C454B7167BD235003586CD /* KRHitInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRHitInfo.h; path = Classes/KRHitInfo.h; sourceTree = ""; }; E4C454BA167BD248003586CD /* KRHitInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRHitInfo.cpp; path = Classes/KRHitInfo.cpp; sourceTree = ""; }; E4CA10E41637BD0A005D9400 /* KRTexturePVR.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRTexturePVR.h; path = Classes/KRTexturePVR.h; sourceTree = ""; }; @@ -450,6 +458,8 @@ E4F027D41697A02D00D4427D /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = ../../../../MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/OpenAL.framework; sourceTree = SDKROOT; }; E4F027DC1697BFFF00D4427D /* KRAudioBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRAudioBuffer.cpp; path = Classes/KRAudioBuffer.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E4F027DD1697BFFF00D4427D /* KRAudioBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRAudioBuffer.h; path = Classes/KRAudioBuffer.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; + E4F027F61698115600D4427D /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/AudioToolbox.framework; sourceTree = DEVELOPER_DIR; }; + E4F027F91698116000D4427D /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; E4F975311536220900FD60B2 /* KRNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRNode.h; path = Classes/KRNode.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; E4F975351536221C00FD60B2 /* KRNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRNode.cpp; path = Classes/KRNode.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; /* End PBXFileReference section */ @@ -459,6 +469,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + E4F027FA1698116000D4427D /* AudioToolbox.framework in Frameworks */, E4F027D31697A01300D4427D /* OpenAL.framework in Frameworks */, E4CA10F61638BCAF005D9400 /* Accelerate.framework in Frameworks */, E49101A013C99BF50098455B /* OpenGLES.framework in Frameworks */, @@ -470,6 +481,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + E4F027F71698115600D4427D /* AudioToolbox.framework in Frameworks */, E4F027D51697A02D00D4427D /* OpenAL.framework in Frameworks */, E4CA10F81638BCBB005D9400 /* Accelerate.framework in Frameworks */, E4BBBB9C1512A4A900F43B5B /* Foundation.framework in Frameworks */, @@ -699,14 +711,14 @@ E48839A915F9307E00BD66D5 /* Model */ = { isa = PBXGroup; children = ( - E491018313C99BDC0098455B /* KRModelManager.h */, - E491018213C99BDC0098455B /* KRModelManager.cpp */, - E491017A13C99BDC0098455B /* KRModel.h */, - E491017913C99BDC0098455B /* KRModel.cpp */, - E4C454AB167BB8EC003586CD /* KRModelCube.h */, - E4C454AE167BB8FC003586CD /* KRModelCube.cpp */, - E4C454B1167BC04B003586CD /* KRModelSphere.h */, - E4C454B4167BC05C003586CD /* KRModelSphere.cpp */, + E491018313C99BDC0098455B /* KRMeshManager.h */, + E491018213C99BDC0098455B /* KRMeshManager.cpp */, + E491017A13C99BDC0098455B /* KRMesh.h */, + E491017913C99BDC0098455B /* KRMesh.cpp */, + E4C454AB167BB8EC003586CD /* KRMeshCube.h */, + E4C454AE167BB8FC003586CD /* KRMeshCube.cpp */, + E4C454B1167BC04B003586CD /* KRMeshSphere.h */, + E4C454B4167BC05C003586CD /* KRMeshSphere.cpp */, ); name = Model; sourceTree = ""; @@ -738,6 +750,8 @@ children = ( E48B68131697794F00D99917 /* KRAudioSource.cpp */, E48B68141697794F00D99917 /* KRAudioSource.h */, + E494322F169E08D200BCB891 /* KRReverbZone.cpp */, + E4943230169E08D200BCB891 /* KRReverbZone.h */, ); name = Audio; sourceTree = ""; @@ -772,8 +786,8 @@ E48B3CBF14393E2F000C50E2 /* KRCamera.cpp */, E48B3CBC14393DF5000C50E2 /* KRCamera.h */, E4324BA916444DCB0043185B /* Particle Systems */, - E414BAE11435557300A668C4 /* KRInstance.h */, - E414BAE41435558800A668C4 /* KRInstance.cpp */, + E414BAE11435557300A668C4 /* KRModel.h */, + E414BAE41435558800A668C4 /* KRModel.cpp */, E461A171152E599E00F2044A /* Lights */, E4F975311536220900FD60B2 /* KRNode.h */, E4F975351536221C00FD60B2 /* KRNode.cpp */, @@ -808,6 +822,7 @@ children = ( E491016413C99B9E0098455B /* Foundation.framework */, E4F027D21697A01300D4427D /* OpenAL.framework */, + E4F027F91698116000D4427D /* AudioToolbox.framework */, E491019F13C99BF50098455B /* OpenGLES.framework */, E4CA10F51638BCAE005D9400 /* Accelerate.framework */, ); @@ -889,6 +904,7 @@ E4BBBB9A1512A48200F43B5B /* Foundation.framework */, E46DBE7D1512AD4900D59F86 /* OpenGL.framework */, E4F027D41697A02D00D4427D /* OpenAL.framework */, + E4F027F61698115600D4427D /* AudioToolbox.framework */, E44F37FF1682731700399B5D /* PVRTexLib */, E460292916682BD900261BB9 /* libfbxsdk-2013.3-static.a */, E4CA10F71638BCBB005D9400 /* Accelerate.framework */, @@ -932,12 +948,12 @@ E491019E13C99BDC0098455B /* KRTexture2D.h in Headers */, E491018A13C99BDC0098455B /* KREngine.h in Headers */, E491018E13C99BDC0098455B /* KRMat4.h in Headers */, - E491019B13C99BDC0098455B /* KRModelManager.h in Headers */, - E491019213C99BDC0098455B /* KRModel.h in Headers */, + E491019B13C99BDC0098455B /* KRMeshManager.h in Headers */, + E491019213C99BDC0098455B /* KRMesh.h in Headers */, E491019613C99BDC0098455B /* KRVector3.h in Headers */, E47C25A213F4F65A00FF4370 /* KRShaderManager.h in Headers */, E47C25A513F4F66F00FF4370 /* KRShader.h in Headers */, - E414BAE21435557300A668C4 /* KRInstance.h in Headers */, + E414BAE21435557300A668C4 /* KRModel.h in Headers */, E414BAE7143557D200A668C4 /* KRScene.h in Headers */, E48B3CBD14393DF5000C50E2 /* KRCamera.h in Headers */, E497B94A151BCEE900D3DC67 /* KRResource.h in Headers */, @@ -972,8 +988,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 */, + E4C454AC167BB8EC003586CD /* KRMeshCube.h in Headers */, + E4C454B2167BC04C003586CD /* KRMeshSphere.h in Headers */, E4C454B8167BD236003586CD /* KRHitInfo.h in Headers */, E44F38241683B23000399B5D /* KRRenderSettings.h in Headers */, E414F9A81694D977000B3D58 /* KRUnknownManager.h in Headers */, @@ -982,6 +998,7 @@ E4F027C916979CCD00D4427D /* KRAudioManager.h in Headers */, E4F027D016979CE200D4427D /* KRAudioSample.h in Headers */, E4F027E01697BFFF00D4427D /* KRAudioBuffer.h in Headers */, + E4943233169E08D200BCB891 /* KRReverbZone.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -992,20 +1009,20 @@ E497B948151BB89D00D3DC67 /* KRVector2.h in Headers */, E4D0683F1512A790005FFBEB /* KRVector3.h in Headers */, E461A177152E5C6600F2044A /* KRMat4.h in Headers */, - E4F975461536327C00FD60B2 /* KRModelManager.h in Headers */, + E4F975461536327C00FD60B2 /* KRMeshManager.h in Headers */, E497B94B151BCEE900D3DC67 /* KRResource.h in Headers */, E43B0AD915DDCA0F00A5CB9F /* KRContextObject.h in Headers */, E4F975331536220900FD60B2 /* KRNode.h in Headers */, E4B2A4391523B027004CB0EC /* KRMaterial.h in Headers */, E46F4A0C155E002100CCF8B8 /* KRDataBlock.h in Headers */, E4F9754115362CD900FD60B2 /* KRScene.h in Headers */, - E4F9754A153632AA00FD60B2 /* KRModelManager.cpp in Headers */, - E4F9754215362D0D00FD60B2 /* KRInstance.h in Headers */, + E4F9754A153632AA00FD60B2 /* KRMeshManager.cpp in Headers */, + E4F9754215362D0D00FD60B2 /* KRModel.h in Headers */, E4F975491536329E00FD60B2 /* KRTextureManager.h in Headers */, E46DBE851512B9FA00D59F86 /* KREngine-common.h in Headers */, E488399715F928CA00BD66D5 /* KRBundle.h in Headers */, E4F9754C153632F000FD60B2 /* KRCamera.h in Headers */, - E4F975501536333500FD60B2 /* KRModel.h in Headers */, + E4F975501536333500FD60B2 /* KRMesh.h in Headers */, E488399F15F92BE000BD66D5 /* KRBundleManager.h in Headers */, E4AFC6BC15F7C95D00DDB4C8 /* KRSceneManager.h in Headers */, E428C2F31669610500A16EDF /* KRAnimationManager.h in Headers */, @@ -1041,15 +1058,16 @@ E4C454B9167BD236003586CD /* KRHitInfo.h in Headers */, E4324BA516444C0D0043185B /* KRParticleSystem.h in Headers */, E4324BAC16444DEF0043185B /* KRParticleSystemNewtonian.h in Headers */, - E4C454AD167BB8EC003586CD /* KRModelCube.h in Headers */, + E4C454AD167BB8EC003586CD /* KRMeshCube.h in Headers */, E414F9A91694D977000B3D58 /* KRUnknownManager.h in Headers */, - E414F9AF1694DA37000B3D58 /* KRUnknown.h in Headers */, - E4C454B3167BC04C003586CD /* KRModelSphere.h in Headers */, - E44F38251683B23000399B5D /* KRRenderSettings.h in Headers */, E48B68181697794F00D99917 /* KRAudioSource.h in Headers */, E4F027CA16979CCD00D4427D /* KRAudioManager.h in Headers */, E4F027D116979CE200D4427D /* KRAudioSample.h in Headers */, E4F027E11697BFFF00D4427D /* KRAudioBuffer.h in Headers */, + E4943234169E08D200BCB891 /* KRReverbZone.h in Headers */, + E414F9AF1694DA37000B3D58 /* KRUnknown.h in Headers */, + E4C454B3167BC04C003586CD /* KRMeshSphere.h in Headers */, + E44F38251683B23000399B5D /* KRRenderSettings.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1137,16 +1155,16 @@ files = ( E491018713C99BDC0098455B /* KREngine.mm in Sources */, E491018F13C99BDC0098455B /* KRMat4.cpp in Sources */, - E491019113C99BDC0098455B /* KRModel.cpp in Sources */, + E491019113C99BDC0098455B /* KRMesh.cpp in Sources */, E491019313C99BDC0098455B /* KRMaterialManager.cpp in Sources */, E491019413C99BDC0098455B /* KRMaterial.cpp in Sources */, E491019713C99BDC0098455B /* KRVector3.cpp in Sources */, E491019813C99BDC0098455B /* KRTextureManager.cpp in Sources */, E491019913C99BDC0098455B /* KRTexture2D.cpp in Sources */, - E491019A13C99BDC0098455B /* KRModelManager.cpp in Sources */, + E491019A13C99BDC0098455B /* KRMeshManager.cpp in Sources */, E47C25A713F4F6AB00FF4370 /* KRShaderManager.cpp in Sources */, E47C25A913F4F6DD00FF4370 /* KRShader.cpp in Sources */, - E414BAE51435558900A668C4 /* KRInstance.cpp in Sources */, + E414BAE51435558900A668C4 /* KRModel.cpp in Sources */, E414BAE91435585A00A668C4 /* KRScene.cpp in Sources */, E48B3CC014393E30000C50E2 /* KRCamera.cpp in Sources */, E497B946151BA99500D3DC67 /* KRVector2.cpp in Sources */, @@ -1184,8 +1202,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 */, + E4C454AF167BB8FC003586CD /* KRMeshCube.cpp in Sources */, + E4C454B5167BC05C003586CD /* KRMeshSphere.cpp in Sources */, E4C454BB167BD248003586CD /* KRHitInfo.cpp in Sources */, E44F38281683B24800399B5D /* KRRenderSettings.cpp in Sources */, E414F9A61694D977000B3D58 /* KRUnknownManager.cpp in Sources */, @@ -1194,6 +1212,7 @@ E4F027C716979CCD00D4427D /* KRAudioManager.cpp in Sources */, E4F027CE16979CE200D4427D /* KRAudioSample.cpp in Sources */, E4F027DE1697BFFF00D4427D /* KRAudioBuffer.cpp in Sources */, + E4943231169E08D200BCB891 /* KRReverbZone.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1214,13 +1233,13 @@ E497B954151BEDA600D3DC67 /* KRResource+fbx.cpp in Sources */, E4F97551153633E200FD60B2 /* KRMaterialManager.cpp in Sources */, E461A15A152E557E00F2044A /* KRPointLight.cpp in Sources */, - E4F9754F1536333200FD60B2 /* KRModel.cpp in Sources */, - E4F9754B153632D800FD60B2 /* KRModelManager.cpp in Sources */, + E4F9754F1536333200FD60B2 /* KRMesh.cpp in Sources */, + E4F9754B153632D800FD60B2 /* KRMeshManager.cpp in Sources */, E461A160152E565700F2044A /* KRDirectionalLight.cpp in Sources */, E4F975531536340000FD60B2 /* KRTexture2D.cpp in Sources */, E4F9754015362CD400FD60B2 /* KRScene.cpp in Sources */, E461A166152E56C000F2044A /* KRSpotLight.cpp in Sources */, - E4F9754315362D0F00FD60B2 /* KRInstance.cpp in Sources */, + E4F9754315362D0F00FD60B2 /* KRModel.cpp in Sources */, E4F975371536221C00FD60B2 /* KRNode.cpp in Sources */, E4F9754E1536331D00FD60B2 /* KRTextureManager.cpp in Sources */, E4D13367153768610070068C /* KRShader.cpp in Sources */, @@ -1252,8 +1271,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 */, + E4C454B0167BB8FC003586CD /* KRMeshCube.cpp in Sources */, + E4C454B6167BC05C003586CD /* KRMeshSphere.cpp in Sources */, E4C454BC167BD248003586CD /* KRHitInfo.cpp in Sources */, E44F38291683B24800399B5D /* KRRenderSettings.cpp in Sources */, E414F9A71694D977000B3D58 /* KRUnknownManager.cpp in Sources */, @@ -1262,6 +1281,7 @@ E4F027C816979CCD00D4427D /* KRAudioManager.cpp in Sources */, E4F027CF16979CE200D4427D /* KRAudioSample.cpp in Sources */, E4F027DF1697BFFF00D4427D /* KRAudioBuffer.cpp in Sources */, + E4943232169E08D200BCB891 /* KRReverbZone.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/KREngine/KREngine/Classes/KRAudioManager.cpp b/KREngine/KREngine/Classes/KRAudioManager.cpp index 6d2dfa6..bc2145a 100644 --- a/KREngine/KREngine/Classes/KRAudioManager.cpp +++ b/KREngine/KREngine/Classes/KRAudioManager.cpp @@ -45,7 +45,12 @@ KRAudioManager::KRAudioManager(KRContext &context) : KRContextObject(context) // ----- Configure listener ----- alDistanceModel(AL_EXPONENT_DISTANCE); + +#if TARGET_OS_IPHONE alcMacOSXRenderingQualityProc(ALC_IPHONE_SPATIAL_RENDERING_QUALITY_HEADPHONES); +#else + alcMacOSXRenderingQualityProc(ALC_MAC_OSX_SPATIAL_RENDERING_QUALITY_HIGH); +#endif UInt32 setting = 1; alcASASetListenerProc(ALC_ASA_REVERB_ON, &setting, sizeof(setting)); ALfloat global_reverb_level = -5.0f; diff --git a/KREngine/KREngine/Classes/KRAudioSource.cpp b/KREngine/KREngine/Classes/KRAudioSource.cpp index 44d44be..c0569ea 100644 --- a/KREngine/KREngine/Classes/KRAudioSource.cpp +++ b/KREngine/KREngine/Classes/KRAudioSource.cpp @@ -213,7 +213,7 @@ void KRAudioSource::render(KRCamera *pCamera, std::vector &lights, co GLDEBUG(glEnable(GL_DEPTH_TEST)); GLDEBUG(glDepthFunc(GL_LEQUAL)); GLDEBUG(glDepthRangef(0.0, 1.0)); - std::vector sphereModels = getContext().getModelManager()->getModel("__sphere"); + std::vector sphereModels = getContext().getModelManager()->getModel("__sphere"); if(sphereModels.size()) { for(int i=0; i < sphereModels[0]->getSubmeshCount(); i++) { sphereModels[0]->renderSubmesh(i); diff --git a/KREngine/KREngine/Classes/KRBone.cpp b/KREngine/KREngine/Classes/KRBone.cpp index 7a5b56c..fda3ccd 100644 --- a/KREngine/KREngine/Classes/KRBone.cpp +++ b/KREngine/KREngine/Classes/KRBone.cpp @@ -61,7 +61,7 @@ void KRBone::render(KRCamera *pCamera, std::vector &lights, const KRV GLDEBUG(glEnable(GL_DEPTH_TEST)); GLDEBUG(glDepthFunc(GL_LEQUAL)); GLDEBUG(glDepthRangef(0.0, 1.0)); - std::vector sphereModels = getContext().getModelManager()->getModel("__sphere"); + std::vector sphereModels = getContext().getModelManager()->getModel("__sphere"); if(sphereModels.size()) { for(int i=0; i < sphereModels[0]->getSubmeshCount(); i++) { sphereModels[0]->renderSubmesh(i); diff --git a/KREngine/KREngine/Classes/KRCamera.cpp b/KREngine/KREngine/Classes/KRCamera.cpp index 4174218..a1b37c2 100644 --- a/KREngine/KREngine/Classes/KRCamera.cpp +++ b/KREngine/KREngine/Classes/KRCamera.cpp @@ -651,8 +651,8 @@ void KRCamera::renderPost() #elif GL_vertex_array_object #endif m_pContext->getModelManager()->configureAttribs(true, false, false, true, false, false, false); - GLDEBUG(glVertexAttribPointer(KRModel::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, 0, charTexCoords)); - GLDEBUG(glVertexAttribPointer(KRModel::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, charVertices)); + GLDEBUG(glVertexAttribPointer(KRMesh::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, 0, charTexCoords)); + GLDEBUG(glVertexAttribPointer(KRMesh::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, charVertices)); GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); iPos++; diff --git a/KREngine/KREngine/Classes/KRCamera.h b/KREngine/KREngine/Classes/KRCamera.h index e63768c..ba05ffa 100644 --- a/KREngine/KREngine/Classes/KRCamera.h +++ b/KREngine/KREngine/Classes/KRCamera.h @@ -44,7 +44,7 @@ #import "KRViewport.h" #import "KRRenderSettings.h" -class KRInstance; +class KRModel; class KRScene; class KRViewport; diff --git a/KREngine/KREngine/Classes/KRCollider.cpp b/KREngine/KREngine/Classes/KRCollider.cpp index 7746116..2116d41 100644 --- a/KREngine/KREngine/Classes/KRCollider.cpp +++ b/KREngine/KREngine/Classes/KRCollider.cpp @@ -32,12 +32,14 @@ #include #include "KRCollider.h" #import "KRContext.h" -#import "KRModel.h" +#import "KRMesh.h" #import "KRQuaternion.h" #include -KRCollider::KRCollider(KRScene &scene, std::string collider_name, std::string model_name) : KRNode(scene, collider_name) { +KRCollider::KRCollider(KRScene &scene, std::string collider_name, std::string model_name, unsigned int layer_mask, float audio_occlusion) : KRNode(scene, collider_name) { m_model_name = model_name; + m_layer_mask = layer_mask; + m_audio_occlusion = audio_occlusion; } KRCollider::~KRCollider() { @@ -51,10 +53,28 @@ std::string KRCollider::getElementName() { tinyxml2::XMLElement *KRCollider::saveXML( tinyxml2::XMLNode *parent) { tinyxml2::XMLElement *e = KRNode::saveXML(parent); - e->SetAttribute("collider_name", m_model_name.c_str()); + e->SetAttribute("mesh", m_model_name.c_str()); + e->SetAttribute("layer_mask", m_layer_mask); + e->SetAttribute("audio_occlusion", m_audio_occlusion); return e; } +void KRCollider::loadXML(tinyxml2::XMLElement *e) { + KRNode::loadXML(e); + + m_model_name = e->Attribute("mesh"); + + m_layer_mask = 65535; + if(e->QueryUnsignedAttribute("layer_mask", &m_layer_mask) != tinyxml2::XML_SUCCESS) { + m_layer_mask = 65535; + } + + m_audio_occlusion = 1.0f; + if(e->QueryFloatAttribute("audio_occlusion", &m_audio_occlusion) != tinyxml2::XML_SUCCESS) { + m_audio_occlusion = 1.0f; + } +} + void KRCollider::loadModel() { if(m_models.size() == 0) { m_models = m_pContext->getModelManager()->getModel(m_model_name.c_str()); // The model manager returns the LOD levels in sorted order, with the highest detail first @@ -73,36 +93,60 @@ KRAABB KRCollider::getBounds() { } } -bool KRCollider::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo) +bool KRCollider::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask) { - loadModel(); - if(m_models.size()) { - if(getBounds().intersectsLine(v0, v1)) { - KRHitInfo hitinfo_model_space = KRHitInfo(KRMat4::Dot(getInverseModelMatrix(), hitinfo.getPosition()), KRMat4::DotNoTranslate(getInverseModelMatrix(), hitinfo.getNormal()), hitinfo.getNode()); - KRVector3 v0_model_space = KRMat4::Dot(getInverseModelMatrix(), v0); - KRVector3 v1_model_space = KRMat4::Dot(getInverseModelMatrix(), v1); - if(m_models[0]->lineCast(v0_model_space, v1_model_space, hitinfo_model_space)) { - hitinfo = KRHitInfo(KRMat4::Dot(getModelMatrix(), hitinfo_model_space.getPosition()), KRVector3::Normalize(KRMat4::DotNoTranslate(getModelMatrix(), hitinfo_model_space.getNormal())), this); - return true; + if(layer_mask & m_layer_mask ) { // Only test if layer masks have a common bit set + loadModel(); + if(m_models.size()) { + if(getBounds().intersectsLine(v0, v1)) { + KRHitInfo hitinfo_model_space = KRHitInfo(KRMat4::Dot(getInverseModelMatrix(), hitinfo.getPosition()), KRMat4::DotNoTranslate(getInverseModelMatrix(), hitinfo.getNormal()), hitinfo.getNode()); + KRVector3 v0_model_space = KRMat4::Dot(getInverseModelMatrix(), v0); + KRVector3 v1_model_space = KRMat4::Dot(getInverseModelMatrix(), v1); + if(m_models[0]->lineCast(v0_model_space, v1_model_space, hitinfo_model_space)) { + hitinfo = KRHitInfo(KRMat4::Dot(getModelMatrix(), hitinfo_model_space.getPosition()), KRVector3::Normalize(KRMat4::DotNoTranslate(getModelMatrix(), hitinfo_model_space.getNormal())), this); + return true; + } } } } return false; } -bool KRCollider::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo) +bool KRCollider::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask) { - loadModel(); - if(m_models.size()) { - if(getBounds().intersectsRay(v0, dir)) { - KRHitInfo hitinfo_model_space = KRHitInfo(KRMat4::Dot(getInverseModelMatrix(), hitinfo.getPosition()), KRVector3::Normalize(KRMat4::DotNoTranslate(getInverseModelMatrix(), hitinfo.getNormal())), hitinfo.getNode()); - KRVector3 v0_model_space = KRMat4::Dot(getInverseModelMatrix(), v0); - KRVector3 dir_model_space = KRMat4::DotNoTranslate(getInverseModelMatrix(), dir); - if(m_models[0]->rayCast(v0_model_space, dir, hitinfo_model_space)) { - hitinfo = KRHitInfo(KRMat4::Dot(getModelMatrix(), hitinfo_model_space.getPosition()), KRVector3::Normalize(KRMat4::DotNoTranslate(getModelMatrix(), hitinfo_model_space.getNormal())), this); - return true; + if(layer_mask & m_layer_mask) { // Only test if layer masks have a common bit set + loadModel(); + if(m_models.size()) { + if(getBounds().intersectsRay(v0, dir)) { + KRHitInfo hitinfo_model_space = KRHitInfo(KRMat4::Dot(getInverseModelMatrix(), hitinfo.getPosition()), KRVector3::Normalize(KRMat4::DotNoTranslate(getInverseModelMatrix(), hitinfo.getNormal())), hitinfo.getNode()); + KRVector3 v0_model_space = KRMat4::Dot(getInverseModelMatrix(), v0); + KRVector3 dir_model_space = KRMat4::DotNoTranslate(getInverseModelMatrix(), dir); + if(m_models[0]->rayCast(v0_model_space, dir, hitinfo_model_space)) { + hitinfo = KRHitInfo(KRMat4::Dot(getModelMatrix(), hitinfo_model_space.getPosition()), KRVector3::Normalize(KRMat4::DotNoTranslate(getModelMatrix(), hitinfo_model_space.getNormal())), this); + return true; + } } } } return false; } + +unsigned int KRCollider::getLayerMask() +{ + return m_layer_mask; +} + +void KRCollider::setLayerMask(unsigned int layer_mask) +{ + m_layer_mask = layer_mask; +} + +float KRCollider::getAudioOcclusion() +{ + return m_audio_occlusion; +} + +void KRCollider::setAudioOcclusion(float audio_occlusion) +{ + m_audio_occlusion = audio_occlusion; +} diff --git a/KREngine/KREngine/Classes/KRCollider.h b/KREngine/KREngine/Classes/KRCollider.h index ec17505..f5f8fa9 100644 --- a/KREngine/KREngine/Classes/KRCollider.h +++ b/KREngine/KREngine/Classes/KRCollider.h @@ -34,34 +34,47 @@ #ifndef KRCOLLIDER_H #define KRCOLLIDER_H -#import "KRModel.h" +#define KRAKEN_COLLIDER_PHYSICS 1 +#define KRAKEN_COLLIDER_AUDIO 2 + +#import "KRMesh.h" #import "KRMat4.h" #import "KRVector3.h" -#import "KRInstance.h" +#import "KRModel.h" #import "KRCamera.h" -#import "KRModelManager.h" +#import "KRMeshManager.h" #import "KRNode.h" #import "KRContext.h" -#import "KRModel.h" +#import "KRMesh.h" #import "KRTexture.h" class KRCollider : public KRNode { public: - KRCollider(KRScene &scene, std::string collider_name, std::string model_name); + KRCollider(KRScene &scene, std::string collider_name, std::string model_name, unsigned int layer_mask, float audio_occlusion); virtual ~KRCollider(); virtual std::string getElementName(); virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent); + virtual void loadXML(tinyxml2::XMLElement *e); virtual KRAABB getBounds(); - bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo); - bool rayCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo); + bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); + bool rayCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); + + unsigned int getLayerMask(); + void setLayerMask(unsigned int layer_mask); + + float getAudioOcclusion(); + void setAudioOcclusion(float audio_occlusion); private: - std::vector m_models; + std::vector m_models; std::string m_model_name; + unsigned int m_layer_mask; + float m_audio_occlusion; + void loadModel(); }; diff --git a/KREngine/KREngine/Classes/KRContext.cpp b/KREngine/KREngine/Classes/KRContext.cpp index 3f87bb6..9b0b48c 100644 --- a/KREngine/KREngine/Classes/KRContext.cpp +++ b/KREngine/KREngine/Classes/KRContext.cpp @@ -31,7 +31,7 @@ KRContext::KRContext() { m_pShaderManager = new KRShaderManager(*this); m_pTextureManager = new KRTextureManager(*this); m_pMaterialManager = new KRMaterialManager(*this, m_pTextureManager, m_pShaderManager); - m_pModelManager = new KRModelManager(*this); + m_pModelManager = new KRMeshManager(*this); m_pSceneManager = new KRSceneManager(*this); m_pAnimationManager = new KRAnimationManager(*this); m_pAnimationCurveManager = new KRAnimationCurveManager(*this); @@ -111,7 +111,7 @@ KRMaterialManager *KRContext::getMaterialManager() { KRShaderManager *KRContext::getShaderManager() { return m_pShaderManager; } -KRModelManager *KRContext::getModelManager() { +KRMeshManager *KRContext::getModelManager() { return m_pModelManager; } KRAnimationManager *KRContext::getAnimationManager() { @@ -135,7 +135,7 @@ void KRContext::loadResource(const std::string &file_name, KRDataBlock *data) { if(extension.compare("krbundle") == 0) { m_pBundleManager->loadBundle(name.c_str(), data); - } else if(extension.compare("krobject") == 0) { + } else if(extension.compare("krmesh") == 0) { m_pModelManager->loadModel(name.c_str(), data); } else if(extension.compare("krscene") == 0) { m_pSceneManager->loadScene(name.c_str(), data); diff --git a/KREngine/KREngine/Classes/KRContext.h b/KREngine/KREngine/Classes/KRContext.h index 63e4cd7..3480df4 100644 --- a/KREngine/KREngine/Classes/KRContext.h +++ b/KREngine/KREngine/Classes/KRContext.h @@ -15,7 +15,7 @@ #import "KRTextureManager.h" #import "KRMaterialManager.h" #import "KRShaderManager.h" -#import "KRModelManager.h" +#import "KRMeshManager.h" #import "KRAnimationManager.h" #import "KRAnimationCurveManager.h" #import "KRAudioManager.h" @@ -46,7 +46,7 @@ public: KRTextureManager *getTextureManager(); KRMaterialManager *getMaterialManager(); KRShaderManager *getShaderManager(); - KRModelManager *getModelManager(); + KRMeshManager *getModelManager(); KRAnimationManager *getAnimationManager(); KRAnimationCurveManager *getAnimationCurveManager(); KRAudioManager *getAudioManager(); @@ -75,7 +75,7 @@ private: KRTextureManager *m_pTextureManager; KRMaterialManager *m_pMaterialManager; KRShaderManager *m_pShaderManager; - KRModelManager *m_pModelManager; + KRMeshManager *m_pModelManager; KRAnimationManager *m_pAnimationManager; KRAnimationCurveManager *m_pAnimationCurveManager; KRAudioManager *m_pSoundManager; diff --git a/KREngine/KREngine/Classes/KREngine-common.h b/KREngine/KREngine/Classes/KREngine-common.h index 2344796..ef38744 100644 --- a/KREngine/KREngine/Classes/KREngine-common.h +++ b/KREngine/KREngine/Classes/KREngine-common.h @@ -56,7 +56,11 @@ float const D2R = PI * 2 / 360; #import #import #import +#if TARGET_OS_IPHONE #import +#else +#import +#endif #endif diff --git a/KREngine/KREngine/Classes/KREngine.h b/KREngine/KREngine/Classes/KREngine.h index 3ccdb68..5a8887b 100644 --- a/KREngine/KREngine/Classes/KREngine.h +++ b/KREngine/KREngine/Classes/KREngine.h @@ -33,7 +33,7 @@ #import #import "KRMat4.h" #import "KRVector3.h" -#import "KRModel.h" +#import "KRMesh.h" #import "KRScene.h" #import "KRContext.h" #import "KRCamera.h" diff --git a/KREngine/KREngine/Classes/KRInstance.cpp b/KREngine/KREngine/Classes/KRInstance.cpp deleted file mode 100644 index afdcd88..0000000 --- a/KREngine/KREngine/Classes/KRInstance.cpp +++ /dev/null @@ -1,166 +0,0 @@ -// -// KRInstance.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 -#import "KRInstance.h" -#import "KRContext.h" -#import "KRModel.h" -#import "KRQuaternion.h" -#include - -KRInstance::KRInstance(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map, float lod_min_coverage, bool receives_shadow, bool faces_camera) : KRNode(scene, instance_name) { - m_lightMap = light_map; - m_pLightMap = NULL; - m_model_name = model_name; - m_min_lod_coverage = lod_min_coverage; - m_receivesShadow = receives_shadow; - m_faces_camera = faces_camera; -} - -KRInstance::~KRInstance() { - -} - -std::string KRInstance::getElementName() { - return "mesh"; -} - -tinyxml2::XMLElement *KRInstance::saveXML( tinyxml2::XMLNode *parent) -{ - tinyxml2::XMLElement *e = KRNode::saveXML(parent); - e->SetAttribute("mesh_name", m_model_name.c_str()); - e->SetAttribute("light_map", m_lightMap.c_str()); - e->SetAttribute("lod_min_coverage", m_min_lod_coverage); - e->SetAttribute("receives_shadow", m_receivesShadow ? "true" : "false"); - e->SetAttribute("faces_camera", m_faces_camera ? "true" : "false"); - return e; -} - -void KRInstance::loadModel() { - if(m_models.size() == 0) { - std::vector models = m_pContext->getModelManager()->getModel(m_model_name.c_str()); // The model manager returns the LOD levels in sorted order, with the highest detail first - std::map > bones; - if(models.size() > 0) { - bool all_bones_found = true; - for(std::vector::iterator model_itr = models.begin(); model_itr != models.end(); model_itr++) { - KRModel *model = *model_itr; - std::vector model_bones; - int bone_count = model->getBoneCount(); - for(int bone_index=0; bone_index < bone_count; bone_index++) { - KRBone *matching_bone = dynamic_cast(getScene().getRootNode()->find(model->getBoneName(bone_index))); - if(matching_bone) { - model_bones.push_back(matching_bone); - } else { - all_bones_found = false; // Reject when there are any missing bones or multiple matches - } - } - bones[model] = model_bones; - } - if(all_bones_found) { - m_models = models; - m_bones = bones; - getScene().notify_sceneGraphModify(this); - } - } - } -} - -void KRInstance::render(KRCamera *pCamera, std::vector &lights, const KRViewport &viewport, KRNode::RenderPass renderPass) { - - - KRNode::render(pCamera, lights, viewport, renderPass); - - if(renderPass != KRNode::RENDER_PASS_DEFERRED_LIGHTS && (renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT || this->hasTransparency()) && renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) { - // Don't render meshes on second pass of the deferred lighting renderer, as only lights will be applied - - loadModel(); - - if(m_models.size() > 0) { - float lod_coverage = getBounds().coverage(viewport.getViewProjectionMatrix(), viewport.getSize()); // This also checks the view frustrum culling - if(lod_coverage > m_min_lod_coverage) { - - // ---===--- Select the best LOD model based on screen coverage ---===--- - std::vector::iterator itr=m_models.begin(); - KRModel *pModel = *itr++; - - while(itr != m_models.end()) { - KRModel *pLODModel = *itr++; - if((float)pLODModel->getLODCoverage() / 100.0f > lod_coverage && pLODModel->getLODCoverage() < pModel->getLODCoverage()) { - pModel = pLODModel; - } else { - break; - } - } - - if(m_pLightMap == NULL && m_lightMap.size()) { - m_pLightMap = getContext().getTextureManager()->getTexture(m_lightMap.c_str()); - } - - if(m_pLightMap && pCamera->settings.bEnableLightMap && renderPass != RENDER_PASS_SHADOWMAP && renderPass != RENDER_PASS_GENERATE_SHADOWMAPS) { - m_pContext->getTextureManager()->selectTexture(5, m_pLightMap); - } - - KRMat4 matModel = getModelMatrix(); - if(m_faces_camera) { - KRVector3 model_center = KRMat4::Dot(matModel, KRVector3::Zero()); - KRVector3 camera_pos = viewport.getCameraPosition(); - matModel = KRQuaternion(KRVector3::Forward(), KRVector3::Normalize(camera_pos - model_center)).rotationMatrix() * matModel; - } - - pModel->render(pCamera, lights, viewport, matModel, m_pLightMap, renderPass, m_bones[pModel]); - } - } - } -} - -bool KRInstance::hasTransparency() { - if(m_models.size() > 0) { - return m_models[0]->hasTransparency(); - } else { - return false; - } -} - -KRAABB KRInstance::getBounds() { - loadModel(); - if(m_models.size() > 0) { - if(m_faces_camera) { - KRAABB normal_bounds = KRAABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix()); - float max_dimension = normal_bounds.longest_radius(); - return KRAABB(normal_bounds.center()-KRVector3(max_dimension), normal_bounds.center() + KRVector3(max_dimension)); - } else { - return KRAABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix()); - } - } else { - return KRAABB::Infinite(); - } -} - diff --git a/KREngine/KREngine/Classes/KRInstance.h b/KREngine/KREngine/Classes/KRInstance.h deleted file mode 100644 index 0b7b8e6..0000000 --- a/KREngine/KREngine/Classes/KRInstance.h +++ /dev/null @@ -1,83 +0,0 @@ -// -// KRInstance.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. -// - - - -#import "KREngine-common.h" - -#ifndef KRINSTANCE_H -#define KRINSTANCE_H - -#import "KRModel.h" -#import "KRMat4.h" -#import "KRVector3.h" -#import "KRInstance.h" -#import "KRCamera.h" -#import "KRModelManager.h" -#import "KRNode.h" -#import "KRContext.h" -#import "KRModel.h" -#import "KRTexture.h" -#import "KRBone.h" - -class KRInstance : public KRNode { - -public: - KRInstance(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map, float lod_min_coverage, bool receives_shadow, bool faces_camera); - virtual ~KRInstance(); - - virtual std::string getElementName(); - virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent); - - virtual void render(KRCamera *pCamera, std::vector &lights, const KRViewport &viewport, KRNode::RenderPass renderPass); - - bool hasTransparency(); - - - virtual KRAABB getBounds(); - -private: - std::vector m_models; - std::map > m_bones; // Outer std::map connects model to set of bones - KRTexture *m_pLightMap; - std::string m_lightMap; - std::string m_model_name; - - - float m_min_lod_coverage; - void loadModel(); - - bool m_receivesShadow; - bool m_faces_camera; -}; - - -#endif diff --git a/KREngine/KREngine/Classes/KRLight.cpp b/KREngine/KREngine/Classes/KRLight.cpp index 04d3b29..55e8f66 100644 --- a/KREngine/KREngine/Classes/KRLight.cpp +++ b/KREngine/KREngine/Classes/KRLight.cpp @@ -176,7 +176,7 @@ void KRLight::render(KRCamera *pCamera, std::vector &lights, const KR float particle_range = 600.0f; int particle_count = m_dust_particle_density * pow(particle_range, 3); - if(particle_count > KRModelManager::KRENGINE_MAX_RANDOM_PARTICLES) particle_count = KRModelManager::KRENGINE_MAX_RANDOM_PARTICLES; + if(particle_count > KRMeshManager::KRENGINE_MAX_RANDOM_PARTICLES) particle_count = KRMeshManager::KRENGINE_MAX_RANDOM_PARTICLES; // Enable z-buffer test GLDEBUG(glEnable(GL_DEPTH_TEST)); @@ -199,7 +199,7 @@ void KRLight::render(KRCamera *pCamera, std::vector &lights, const KR GLDEBUG(glUniform1f(pParticleShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE], m_dust_particle_size)); - m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getRandomParticles(), KRModelManager::KRENGINE_MAX_RANDOM_PARTICLES * 3 * sizeof(KRModelManager::RandomParticleVertexData), true, false, false, true, false, false, false); + m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getRandomParticles(), KRMeshManager::KRENGINE_MAX_RANDOM_PARTICLES * 3 * sizeof(KRMeshManager::RandomParticleVertexData), true, false, false, true, false, false, false); GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, particle_count*3)); } } @@ -226,7 +226,7 @@ void KRLight::render(KRCamera *pCamera, std::vector &lights, const KR KRVector2(slice_near, slice_spacing).setUniform(pFogShader->m_uniforms[KRShader::KRENGINE_UNIFORM_SLICE_DEPTH_SCALE]); (m_color * pCamera->settings.volumetric_environment_intensity * m_intensity * -slice_spacing / 1000.0f).setUniform(pFogShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR]); - m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getVolumetricLightingVertexes(), KRModelManager::KRENGINE_MAX_VOLUMETRIC_PLANES * 6 * sizeof(KRModelManager::VolumetricLightingVertexData), true, false, false, false, false, false, false); + m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getVolumetricLightingVertexes(), KRMeshManager::KRENGINE_MAX_VOLUMETRIC_PLANES * 6 * sizeof(KRMeshManager::VolumetricLightingVertexData), true, false, false, false, false, false, false); GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, slice_count*6)); } diff --git a/KREngine/KREngine/Classes/KRMesh.cpp b/KREngine/KREngine/Classes/KRMesh.cpp new file mode 100644 index 0000000..2ead845 --- /dev/null +++ b/KREngine/KREngine/Classes/KRMesh.cpp @@ -0,0 +1,855 @@ +// +// KRMesh.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. +// + +#import +#include +#include +#include +#include +#include +#include +#include + + +#include "KRMesh.h" + +#include "KRVector3.h" +#import "KRShader.h" +#import "KRShaderManager.h" +#import "KRContext.h" + + +KRMesh::KRMesh(KRContext &context, std::string name) : KRResource(context, name) { + m_hasTransparency = false; + m_materials.clear(); + m_uniqueMaterials.clear(); + m_pData = new KRDataBlock(); + setName(name); +} + +KRMesh::KRMesh(KRContext &context, std::string name, KRDataBlock *data) : KRResource(context, name) { + m_hasTransparency = false; + m_materials.clear(); + m_uniqueMaterials.clear(); + m_pData = new KRDataBlock(); + setName(name); + + loadPack(data); +} + +void KRMesh::setName(const std::string name) { + m_lodCoverage = 100; + m_lodBaseName = name; + + size_t last_underscore_pos = name.find_last_of('_'); + if(last_underscore_pos != std::string::npos) { + // Found an underscore + std::string suffix = name.substr(last_underscore_pos + 1); + if(suffix.find_first_of("lod") == 0) { + std::string lod_level_string = suffix.substr(3); + char *end = NULL; + int c = (int)strtol(lod_level_string.c_str(), &end, 10); + if(c >= 0 && c <= 100 && *end == '\0') { + m_lodCoverage = c; + m_lodBaseName = name.substr(0, last_underscore_pos); + } + } + } + +} + +int KRMesh::GetLODCoverage(const std::string &name) +{ + int lod_coverage = 100; + size_t last_underscore_pos = name.find_last_of('_'); + if(last_underscore_pos != std::string::npos) { + // Found an underscore + std::string suffix = name.substr(last_underscore_pos + 1); + if(suffix.find_first_of("lod") == 0) { + std::string lod_level_string = suffix.substr(3); + char *end = NULL; + int c = (int)strtol(lod_level_string.c_str(), &end, 10); + if(c >= 0 && c <= 100 && *end == '\0') { + lod_coverage = c; + //m_lodBaseName = name.substr(0, last_underscore_pos); + } + } + } + return lod_coverage; +} + + + +KRMesh::~KRMesh() { + clearData(); + if(m_pData) delete m_pData; +} + +std::string KRMesh::getExtension() { + return "krmesh"; +} + +bool KRMesh::save(const std::string& path) { + clearBuffers(); + return m_pData->save(path); +} + +bool KRMesh::save(KRDataBlock &data) { + clearBuffers(); + data.append(*m_pData); + return true; +} + +void KRMesh::loadPack(KRDataBlock *data) { + clearData(); + delete m_pData; + m_pData = data; + updateAttributeOffsets(); + pack_header *pHeader = getHeader(); + m_minPoint = KRVector3(pHeader->minx, pHeader->miny, pHeader->minz); + m_maxPoint = KRVector3(pHeader->maxx, pHeader->maxy, pHeader->maxz); +} + +void KRMesh::render(KRCamera *pCamera, std::vector &lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector &bones) { + + //fprintf(stderr, "Rendering model: %s\n", m_name.c_str()); + if(renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) { + + if(m_materials.size() == 0) { + vector submeshes = getSubmeshes(); + + for(std::vector::iterator itr = submeshes.begin(); itr != submeshes.end(); itr++) { + const char *szMaterialName = (*itr)->szMaterialName; + KRMaterial *pMaterial = getContext().getMaterialManager()->getMaterial(szMaterialName); + m_materials.push_back(pMaterial); + if(pMaterial) { + m_uniqueMaterials.insert(pMaterial); + } else { + fprintf(stderr, "Missing material: %s\n", szMaterialName); + } + } + + m_hasTransparency = false; + for(std::set::iterator mat_itr = m_uniqueMaterials.begin(); mat_itr != m_uniqueMaterials.end(); mat_itr++) { + if((*mat_itr)->isTransparent()) { + m_hasTransparency = true; + break; + } + } + } + + KRMaterial *pPrevBoundMaterial = NULL; + char szPrevShaderKey[256]; + szPrevShaderKey[0] = '\0'; + int cSubmeshes = getSubmeshes().size(); + if(renderPass == KRNode::RENDER_PASS_SHADOWMAP) { + for(int iSubmesh=0; iSubmeshisTransparent()) { + // Exclude transparent and semi-transparent meshes from shadow maps + renderSubmesh(iSubmesh); + } + } + + } + } else { + // Apply submeshes in per-material batches to reduce number of state changes + for(std::set::iterator mat_itr = m_uniqueMaterials.begin(); mat_itr != m_uniqueMaterials.end(); mat_itr++) { + for(int iSubmesh=0; iSubmeshisTransparent() && renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT) || (pMaterial->isTransparent() && renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) { + if(pMaterial->bind(&pPrevBoundMaterial, szPrevShaderKey, pCamera, lights, bones, viewport, matModel, pLightMap, renderPass)) { + + switch(pMaterial->getAlphaMode()) { + case KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE: // Non-transparent materials + case KRMaterial::KRMATERIAL_ALPHA_MODE_TEST: // Alpha in diffuse texture is interpreted as punch-through when < 0.5 + renderSubmesh(iSubmesh); + break; + case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE: // Blended alpha with backface culling + renderSubmesh(iSubmesh); + break; + case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE: // Blended alpha rendered in two passes. First pass renders backfaces; second pass renders frontfaces. + // Render back faces first + GLDEBUG(glCullFace(GL_BACK)); + renderSubmesh(iSubmesh); + + // Render front faces second + GLDEBUG(glCullFace(GL_BACK)); + renderSubmesh(iSubmesh); + break; + } + } + + + } + } + } + } + } + } +} + +GLfloat KRMesh::getMaxDimension() { + GLfloat m = 0.0; + if(m_maxPoint.x - m_minPoint.x > m) m = m_maxPoint.x - m_minPoint.x; + if(m_maxPoint.y - m_minPoint.y > m) m = m_maxPoint.y - m_minPoint.y; + if(m_maxPoint.z - m_minPoint.z > m) m = m_maxPoint.z - m_minPoint.z; + return m; +} + +bool KRMesh::hasTransparency() { + return m_hasTransparency; +} + + +vector KRMesh::getSubmeshes() { + if(m_submeshes.size() == 0) { + pack_header *pHeader = getHeader(); + pack_material *pPackMaterials = (pack_material *)(pHeader+1); + m_submeshes.clear(); + for(int iMaterial=0; iMaterial < pHeader->submesh_count; iMaterial++) { + pack_material *pPackMaterial = pPackMaterials + iMaterial; + + Submesh *pSubmesh = new Submesh(); + pSubmesh->start_vertex = pPackMaterial->start_vertex; + pSubmesh->vertex_count = pPackMaterial->vertex_count; + + strncpy(pSubmesh->szMaterialName, pPackMaterial->szName, KRENGINE_MAX_NAME_LENGTH); + pSubmesh->szMaterialName[KRENGINE_MAX_NAME_LENGTH-1] = '\0'; + //fprintf(stderr, "Submesh material: \"%s\"\n", pSubmesh->szMaterialName); + m_submeshes.push_back(pSubmesh); + } + } + return m_submeshes; +} + +void KRMesh::renderSubmesh(int iSubmesh) { + unsigned char *pVertexData = getVertexData(); + + pack_header *pHeader = getHeader(); + int cBuffers = (pHeader->vertex_count + MAX_VBO_SIZE - 1) / MAX_VBO_SIZE; + + vector submeshes = getSubmeshes(); + Submesh *pSubmesh = submeshes[iSubmesh]; + + int iVertex = pSubmesh->start_vertex; + int iBuffer = iVertex / MAX_VBO_SIZE; + iVertex = iVertex % MAX_VBO_SIZE; + int cVertexes = pSubmesh->vertex_count; + while(cVertexes > 0) { + GLsizei cBufferVertexes = iBuffer < cBuffers - 1 ? MAX_VBO_SIZE : pHeader->vertex_count % MAX_VBO_SIZE; + int vertex_size = m_vertex_size; + + void *vbo_end = (unsigned char *)pVertexData + iBuffer * MAX_VBO_SIZE * vertex_size + vertex_size * cBufferVertexes; + void *buffer_end = m_pData->getEnd(); + assert(vbo_end <= buffer_end); + assert(cBufferVertexes <= 65535); + + + m_pContext->getModelManager()->bindVBO((unsigned char *)pVertexData + iBuffer * MAX_VBO_SIZE * vertex_size, vertex_size * cBufferVertexes, has_vertex_attribute(KRENGINE_ATTRIB_VERTEX), has_vertex_attribute(KRENGINE_ATTRIB_NORMAL), has_vertex_attribute(KRENGINE_ATTRIB_TANGENT), has_vertex_attribute(KRENGINE_ATTRIB_TEXUVA), has_vertex_attribute(KRENGINE_ATTRIB_TEXUVB), has_vertex_attribute(KRENGINE_ATTRIB_BONEINDEXES), + has_vertex_attribute(KRENGINE_ATTRIB_BONEWEIGHTS)); + + + 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; + iBuffer++; + } 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 KRMesh::LoadData(std::vector vertices, std::vector uva, std::vector uvb, std::vector normals, std::vector tangents, std::vector submesh_starts, std::vector submesh_lengths, std::vector material_names, std::vector bone_names, std::vector > bone_indexes, std::vector > bone_weights, KRMesh::model_format_t model_format) { + + clearData(); + + bool calculate_normals = true; + bool calculate_tangents = true; + + + __int32_t vertex_attrib_flags = 0; + if(vertices.size()) { + vertex_attrib_flags |= (1 << KRENGINE_ATTRIB_VERTEX); + } + if(normals.size() || calculate_normals) { + vertex_attrib_flags += (1 << KRENGINE_ATTRIB_NORMAL); + } + if(tangents.size() || calculate_tangents) { + vertex_attrib_flags += (1 << KRENGINE_ATTRIB_TANGENT); + } + if(uva.size()) { + vertex_attrib_flags += (1 << KRENGINE_ATTRIB_TEXUVA); + } + if(uvb.size()) { + vertex_attrib_flags += (1 << KRENGINE_ATTRIB_TEXUVB); + } + if(bone_names.size()) { + vertex_attrib_flags += (1 << KRENGINE_ATTRIB_BONEINDEXES) + (1 << KRENGINE_ATTRIB_BONEWEIGHTS); + } + size_t vertex_size = VertexSizeForAttributes(vertex_attrib_flags); + + size_t submesh_count = submesh_lengths.size(); + size_t vertex_count = vertices.size(); + size_t bone_count = bone_names.size(); + size_t new_file_size = sizeof(pack_header) + sizeof(pack_material) * submesh_count + sizeof(pack_bone) * bone_count + vertex_size * vertex_count; + m_pData->expand(new_file_size); + + pack_header *pHeader = getHeader(); + memset(pHeader, 0, sizeof(pack_header)); + pHeader->vertex_attrib_flags = vertex_attrib_flags; + 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(); + + pack_material *pPackMaterials = (pack_material *)(pHeader+1); + + for(int iMaterial=0; iMaterial < pHeader->submesh_count; iMaterial++) { + pack_material *pPackMaterial = pPackMaterials + iMaterial; + pPackMaterial->start_vertex = submesh_starts[iMaterial]; + pPackMaterial->vertex_count = submesh_lengths[iMaterial]; + memset(pPackMaterial->szName, 0, KRENGINE_MAX_NAME_LENGTH); + strncpy(pPackMaterial->szName, material_names[iMaterial].c_str(), KRENGINE_MAX_NAME_LENGTH); + } + + for(int bone_index=0; bone_index < bone_count; bone_index++) { + pack_bone *bone = getBone(bone_index); + memset(bone->szName, 0, KRENGINE_MAX_NAME_LENGTH); + strncpy(bone->szName, bone_names[bone_index].c_str(), KRENGINE_MAX_NAME_LENGTH); + } + + bool bFirstVertex = true; + +// VertexData *pVertexData = (VertexData *)(pPackMaterials + pHeader->submesh_count); +// VertexData *pVertex = pVertexData; + memset(getVertexData(), 0, m_vertex_size * vertices.size()); + for(int iVertex=0; iVertex < vertices.size(); iVertex++) { + KRVector3 source_vertex = vertices[iVertex]; + setVertexPosition(iVertex, source_vertex); + if(bone_names.size()) { + for(int bone_weight_index=0; bone_weight_index m_maxPoint.x) m_maxPoint.x = source_vertex.x; + if(source_vertex.y > m_maxPoint.y) m_maxPoint.y = source_vertex.y; + if(source_vertex.z > m_maxPoint.z) m_maxPoint.z = source_vertex.z; + } + if(uva.size() > iVertex) { + setVertexUVA(iVertex, uva[iVertex]); + } + if(uvb.size() > iVertex) { + setVertexUVB(iVertex, uvb[iVertex]); + } + if(normals.size() > iVertex) { + setVertexNormal(iVertex, normals[iVertex]); + } + if(tangents.size() > iVertex) { + setVertexTangent(iVertex, tangents[iVertex]); + } + } + + pHeader->minx = m_minPoint.x; + pHeader->miny = m_minPoint.y; + pHeader->minz = m_minPoint.z; + pHeader->maxx = m_maxPoint.x; + pHeader->maxy = m_maxPoint.y; + pHeader->maxz = m_maxPoint.z; + + + // Calculate missing surface normals and tangents + //cout << " Calculate surface normals and tangents\n"; + + for(int iVertex=0; iVertex < vertices.size(); iVertex+= 3) { + KRVector3 p1 = getVertexPosition(iVertex); + KRVector3 p2 = getVertexPosition(iVertex+1); + KRVector3 p3 = getVertexPosition(iVertex+2); + KRVector3 v1 = p2 - p1; + KRVector3 v2 = p3 - p1; + + + // -- Calculate normal if missing -- + if(calculate_normals) { + KRVector3 first_normal = getVertexNormal(iVertex); + if(first_normal.x == 0.0f && first_normal.y == 0.0f && first_normal.z == 0.0f) { + // Note - We don't take into consideration smoothing groups or smoothing angles when generating normals; all generated normals represent flat shaded polygons + KRVector3 normal = KRVector3::Cross(v1, v2); + + normal.normalize(); + setVertexNormal(iVertex, normal); + setVertexNormal(iVertex+1, normal); + setVertexNormal(iVertex+2, normal); + } + } + + // -- Calculate tangent vector for normal mapping -- + if(calculate_tangents) { + KRVector3 first_tangent = getVertexTangent(iVertex); + if(first_tangent.x == 0.0f && first_tangent.y == 0.0f && first_tangent.z == 0.0f) { + + KRVector2 uv0 = getVertexUVA(iVertex); + KRVector2 uv1 = getVertexUVA(iVertex + 1); + KRVector2 uv2 = getVertexUVA(iVertex + 2); + + KRVector2 st1 = KRVector2(uv1.x - uv0.x, uv1.y - uv0.y); + KRVector2 st2 = KRVector2(uv2.x - uv0.x, uv2.y - uv0.y); + double coef = 1/ (st1.x * st2.y - st2.x * st1.y); + + KRVector3 tangent( + coef * ((v1.x * st2.y) + (v2.x * -st1.y)), + coef * ((v1.y * st2.y) + (v2.y * -st1.y)), + coef * ((v1.z * st2.y) + (v2.z * -st1.y)) + ); + + tangent.normalize(); + setVertexTangent(iVertex, tangent); + setVertexTangent(iVertex+1, tangent); + setVertexTangent(iVertex+2, tangent); + } + } + } + + optimize(); +} + +KRVector3 KRMesh::getMinPoint() const { + return m_minPoint; +} + +KRVector3 KRMesh::getMaxPoint() const { + return m_maxPoint; +} + +void KRMesh::clearData() { + m_pData->unload(); +} + +void KRMesh::clearBuffers() { + m_submeshes.clear(); +} + +int KRMesh::getLODCoverage() const { + return m_lodCoverage; +} + +std::string KRMesh::getLODBaseName() const { + return m_lodBaseName; +} + +// Predicate used with std::sort to sort by highest detail model first, decending to lowest detail LOD model +bool KRMesh::lod_sort_predicate(const KRMesh *m1, const KRMesh *m2) +{ + return m1->m_lodCoverage > m2->m_lodCoverage; +} + +bool KRMesh::has_vertex_attribute(vertex_attrib_t attribute_type) const +{ + return (getHeader()->vertex_attrib_flags & (1 << attribute_type)) != 0; +} + +KRMesh::pack_header *KRMesh::getHeader() const +{ + return (pack_header *)m_pData->getStart(); +} + +KRMesh::pack_bone *KRMesh::getBone(int index) +{ + pack_header *header = getHeader(); + return (pack_bone *)((unsigned char *)m_pData->getStart() + sizeof(pack_header) + sizeof(pack_material) * header->submesh_count + sizeof(pack_bone) * index); +} + +unsigned char *KRMesh::getVertexData() const { + pack_header *pHeader = getHeader(); + return ((unsigned char *)m_pData->getStart()) + sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count; +} + +KRMesh::pack_material *KRMesh::getSubmesh(int mesh_index) const +{ + return (pack_material *)((unsigned char *)m_pData->getStart() + sizeof(pack_header)) + mesh_index; +} + +unsigned char *KRMesh::getVertexData(int index) const +{ + return getVertexData() + m_vertex_size * index; +} + +int KRMesh::getSubmeshCount() const +{ + pack_header *header = getHeader(); + return header->submesh_count; +} + +int KRMesh::getVertexCount(int submesh) const +{ + return getSubmesh(submesh)->vertex_count; +} + +KRVector3 KRMesh::getVertexPosition(int index) const +{ + if(has_vertex_attribute(KRENGINE_ATTRIB_VERTEX)) { + return KRVector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX])); + } else { + return KRVector3::Zero(); + } +} + +KRVector3 KRMesh::getVertexNormal(int index) const +{ + if(has_vertex_attribute(KRENGINE_ATTRIB_NORMAL)) { + return KRVector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_NORMAL])); + } else { + return KRVector3::Zero(); + } +} + +KRVector3 KRMesh::getVertexTangent(int index) const +{ + if(has_vertex_attribute(KRENGINE_ATTRIB_TANGENT)) { + return KRVector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TANGENT])); + } else { + return KRVector3::Zero(); + } +} + +KRVector2 KRMesh::getVertexUVA(int index) const +{ + if(has_vertex_attribute(KRENGINE_ATTRIB_TEXUVA)) { + return KRVector2((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TEXUVA])); + } else { + return KRVector2::Zero(); + } +} + +KRVector2 KRMesh::getVertexUVB(int index) const +{ + if(has_vertex_attribute(KRENGINE_ATTRIB_TEXUVB)) { + return KRVector2((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TEXUVB])); + } else { + return KRVector2::Zero(); + } +} + +void KRMesh::setVertexPosition(int index, const KRVector3 &v) +{ + float *vert = (float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX]); + vert[0] = v.x; + vert[1] = v.y; + vert[2] = v.z; +} + +void KRMesh::setVertexNormal(int index, const KRVector3 &v) +{ + float *vert = (float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_NORMAL]); + vert[0] = v.x; + vert[1] = v.y; + vert[2] = v.z; +} + +void KRMesh::setVertexTangent(int index, const KRVector3 & v) +{ + float *vert = (float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TANGENT]); + vert[0] = v.x; + vert[1] = v.y; + vert[2] = v.z; +} + +void KRMesh::setVertexUVA(int index, const KRVector2 &v) +{ + float *vert = (float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TEXUVA]); + vert[0] = v.x; + vert[1] = v.y; +} + +void KRMesh::setVertexUVB(int index, const KRVector2 &v) +{ + float *vert = (float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TEXUVB]); + vert[0] = v.x; + vert[1] = v.y; +} + + +int KRMesh::getBoneIndex(int index, int weight_index) const +{ + unsigned char *vert = (unsigned char *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_BONEINDEXES]); + return vert[weight_index]; +} + +void KRMesh::setBoneIndex(int index, int weight_index, int bone_index) +{ + unsigned char *vert = (unsigned char *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_BONEINDEXES]); + vert[weight_index] = bone_index; +} + +float KRMesh::getBoneWeight(int index, int weight_index) const +{ + float *vert = (float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_BONEWEIGHTS]); + return vert[weight_index]; +} + +void KRMesh::setBoneWeight(int index, int weight_index, float bone_weight) +{ + float *vert = (float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_BONEWEIGHTS]); + vert[weight_index] = bone_weight; +} + +size_t KRMesh::VertexSizeForAttributes(__int32_t vertex_attrib_flags) +{ + size_t data_size = 0; + if(vertex_attrib_flags & (1 << KRENGINE_ATTRIB_VERTEX)) { + data_size += sizeof(float) * 3; + } + if(vertex_attrib_flags & (1 << KRENGINE_ATTRIB_NORMAL)) { + data_size += sizeof(float) * 3; + } + if(vertex_attrib_flags & (1 << KRENGINE_ATTRIB_TANGENT)) { + data_size += sizeof(float) * 3; + } + if(vertex_attrib_flags & (1 << KRENGINE_ATTRIB_TEXUVA)) { + data_size += sizeof(float) * 2; + } + if(vertex_attrib_flags & (1 << KRENGINE_ATTRIB_TEXUVB)) { + data_size += sizeof(float) * 2; + } + if(vertex_attrib_flags & (1 << KRENGINE_ATTRIB_BONEINDEXES)) { + data_size += 4; // 4 bytes + } + if(vertex_attrib_flags & (1 << KRENGINE_ATTRIB_BONEWEIGHTS)) { + data_size += sizeof(float) * 4; + } + return data_size; +} + +void KRMesh::updateAttributeOffsets() +{ + pack_header *header = getHeader(); + int mask = 0; + for(int i=0; i < KRENGINE_NUM_ATTRIBUTES; i++) { + if(has_vertex_attribute((vertex_attrib_t)i)) { + m_vertex_attribute_offset[i] = VertexSizeForAttributes(header->vertex_attrib_flags & mask); + } else { + m_vertex_attribute_offset[i] = -1; + } + mask = (mask << 1) | 1; + } + m_vertex_size = VertexSizeForAttributes(header->vertex_attrib_flags); +} + +size_t KRMesh::AttributeOffset(__int32_t vertex_attrib, __int32_t vertex_attrib_flags) +{ + int mask = 0; + for(int i=0; i < vertex_attrib; i++) { + if(vertex_attrib_flags & (1 << i)) { + mask |= (1 << i); + } + } + return VertexSizeForAttributes(mask); +} + +int KRMesh::getBoneCount() +{ + pack_header *header = getHeader(); + return header->bone_count; +} + +char *KRMesh::getBoneName(int bone_index) +{ + return getBone(bone_index)->szName; +} + +void KRMesh::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 +} + +KRMesh::model_format_t KRMesh::getModelFormat() const +{ + return (model_format_t)getHeader()->model_format; +} + +bool KRMesh::rayCast(const KRVector3 &line_v0, const KRVector3 &dir, const KRVector3 &tri_v0, const KRVector3 &tri_v1, const KRVector3 &tri_v2, const KRVector3 &tri_n0, const KRVector3 &tri_n1, const KRVector3 &tri_n2, KRHitInfo &hitinfo) +{ + // algorithm based on Dan Sunday's implementation at http://geomalgorithms.com/a06-_intersect-2.html + const float SMALL_NUM = 0.00000001; // anything that avoids division overflow + KRVector3 u, v, n; // triangle vectors + KRVector3 w0, w; // ray vectors + float r, a, b; // params to calc ray-plane intersect + + // get triangle edge vectors and plane normal + u = tri_v1 - tri_v0; + v = tri_v2 - tri_v0; + n = KRVector3::Cross(u, v); // cross product + if (n == KRVector3::Zero()) // triangle is degenerate + return false; // do not deal with this case + + w0 = line_v0 - tri_v0; + a = -KRVector3::Dot(n, w0); + b = KRVector3::Dot(n,dir); + if (fabs(b) < SMALL_NUM) { // ray is parallel to triangle plane + if (a == 0) + return false; // ray lies in triangle plane + else { + return false; // ray disjoint from plane + } + } + + // get intersect point of ray with triangle plane + r = a / b; + if (r < 0.0) // ray goes away from triangle + return false; // => no intersect + // for a segment, also test if (r > 1.0) => no intersect + + + KRVector3 hit_point = line_v0 + dir * r; // intersect point of ray and plane + + // is hit_point inside triangle? + float uu, uv, vv, wu, wv, D; + uu = KRVector3::Dot(u,u); + uv = KRVector3::Dot(u,v); + vv = KRVector3::Dot(v,v); + w = hit_point - tri_v0; + wu = KRVector3::Dot(w,u); + wv = KRVector3::Dot(w,v); + D = uv * uv - uu * vv; + + // get and test parametric coords + float s, t; + s = (uv * wv - vv * wu) / D; + if (s < 0.0 || s > 1.0) // hit_point is outside triangle + return false; + t = (uv * wu - uu * wv) / D; + if (t < 0.0 || (s + t) > 1.0) // hit_point is outside triangle + return false; + + float new_hit_distance_sqr = (hit_point - line_v0).sqrMagnitude(); + float prev_hit_distance_sqr = (hitinfo.getPosition() - line_v0).sqrMagnitude(); + if(new_hit_distance_sqr < prev_hit_distance_sqr) { + // Update the hitinfo object if this hit is closer than the prior hit + + // Interpolate between the three vertex normals, performing a 3-way lerp of tri_n0, tri_n1, and tri_n2 + float distance_v0 = (tri_v0 - hit_point).magnitude(); + float distance_v1 = (tri_v1 - hit_point).magnitude(); + float distance_v2 = (tri_v2 - hit_point).magnitude(); + float distance_total = distance_v0 + distance_v1 + distance_v2; + distance_v0 /= distance_total; + distance_v1 /= distance_total; + distance_v2 /= distance_total; + KRVector3 normal = KRVector3::Normalize(tri_n0 * (1.0 - distance_v0) + tri_n1 * (1.0 - distance_v1) + tri_n2 * (1.0 - distance_v2)); + + hitinfo = KRHitInfo(hit_point, normal); + } + + return true; // hit_point is in triangle +} + +bool KRMesh::rayCast(const KRVector3 &line_v0, const KRVector3 &dir, int tri_index0, int tri_index1, int tri_index2, KRHitInfo &hitinfo) const +{ + return rayCast(line_v0, dir, getVertexPosition(tri_index0), getVertexPosition(tri_index1), getVertexPosition(tri_index2), getVertexNormal(tri_index0), getVertexNormal(tri_index1), getVertexNormal(tri_index2), hitinfo); +} + +bool KRMesh::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo) const +{ + bool hit_found = false; + for(int submesh_index=0; submesh_index < getSubmeshCount(); submesh_index++) { + int vertex_count = getVertexCount(submesh_index); + switch(getModelFormat()) { + case KRENGINE_MODEL_FORMAT_TRIANGLES: + for(int triangle_index=0; triangle_index < vertex_count / 3; triangle_index++) { + if(rayCast(v0, dir, getVertexPosition(triangle_index*3), getVertexPosition(triangle_index*3+1), getVertexPosition(triangle_index*3+2), getVertexNormal(triangle_index*3), getVertexNormal(triangle_index*3+1), getVertexNormal(triangle_index*3+2), hitinfo)) hit_found = true; + } + break; + case KRENGINE_MODEL_FORMAT_STRIP: + for(int triangle_index=0; triangle_index < vertex_count - 2; triangle_index++) { + if(rayCast(v0, dir, getVertexPosition(triangle_index), getVertexPosition(triangle_index+1), getVertexPosition(triangle_index+2), getVertexNormal(triangle_index), getVertexNormal(triangle_index+1), getVertexNormal(triangle_index+2), hitinfo)) hit_found = true; + } + break; + default: + break; + } + } + return hit_found; +} + +bool KRMesh::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo) const +{ + KRHitInfo new_hitinfo; + KRVector3 dir = KRVector3::Normalize(v1 - v0); + if(rayCast(v0, dir, new_hitinfo)) { + if((new_hitinfo.getPosition() - v0).sqrMagnitude() <= (v1 - v0).sqrMagnitude()) { + // The hit was between v1 and v2 + hitinfo = new_hitinfo; + return true; + } + } + return false; // Either no hit, or the hit was beyond v1 +} diff --git a/KREngine/KREngine/Classes/KRMesh.h b/KREngine/KREngine/Classes/KRMesh.h new file mode 100644 index 0000000..f080069 --- /dev/null +++ b/KREngine/KREngine/Classes/KRMesh.h @@ -0,0 +1,239 @@ +// +// KRMesh.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. +// +#import +#import +#import +#import +#import "KRVector2.h" +#import "KRContext.h" +#import "KRBone.h" + +#import "KREngine-common.h" + +using std::vector; +using std::set; +using std::list; + + +#define MAX_VBO_SIZE 65535 +#define KRENGINE_MAX_BONE_WEIGHTS_PER_VERTEX 4 +#define KRENGINE_MAX_NAME_LENGTH 256 +// MAX_VBO_SIZE must be divisible by 3 so triangles aren't split across VBO objects... + +#define BUFFER_OFFSET(i) ((char *)NULL + (i)) + +#ifndef KRMesh_I +#define KRMesh_I + +#import "KRMaterialManager.h" +#import "KRCamera.h" +#import "KRViewport.h" +#import "KRHitInfo.h" + +class KRMaterial; +class KRNode; + + +class KRMesh : public KRResource { + +public: + KRMesh(KRContext &context, std::string name, KRDataBlock *data); + KRMesh(KRContext &context, std::string name); + virtual ~KRMesh(); + + bool hasTransparency(); + + typedef enum { + KRENGINE_ATTRIB_VERTEX = 0, + KRENGINE_ATTRIB_NORMAL, + KRENGINE_ATTRIB_TANGENT, + KRENGINE_ATTRIB_TEXUVA, + KRENGINE_ATTRIB_TEXUVB, + KRENGINE_ATTRIB_BONEINDEXES, + KRENGINE_ATTRIB_BONEWEIGHTS, + KRENGINE_NUM_ATTRIBUTES + } vertex_attrib_t; + + typedef enum { + KRENGINE_MODEL_FORMAT_TRIANGLES = 0, + KRENGINE_MODEL_FORMAT_STRIP, + KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES, + KRENGINE_MODEL_FORMAT_INDEXED_STRIP + } model_format_t; + + + void render(KRCamera *pCamera, std::vector &lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector &bones); + + std::string m_lodBaseName; + + virtual std::string getExtension(); + virtual bool save(const std::string& path); + virtual bool save(KRDataBlock &data); + + void LoadData(std::vector vertices, std::vector uva, std::vector uvb, std::vector normals, std::vector tangents, std::vector submesh_starts, std::vector submesh_lengths, std::vector material_names, std::vector bone_names, std::vector > bone_indexes, std::vector > 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; + char szMaterialName[KRENGINE_MAX_NAME_LENGTH]; + } Submesh; + + typedef struct { + GLfloat x; + GLfloat y; + GLfloat z; + } KRVector3D; + + typedef struct { + GLfloat u; + GLfloat v; + } TexCoord; + + typedef struct { + KRVector3D vertex; + KRVector3D normal; + KRVector3D tangent; + TexCoord uva; + TexCoord uvb; + } VertexData; + + vector getSubmeshes(); + + typedef struct { + int32_t start_vertex; + int32_t vertex_count; + char szName[KRENGINE_MAX_NAME_LENGTH]; + } pack_material; + + typedef struct { + char szName[KRENGINE_MAX_NAME_LENGTH]; + } pack_bone; + + int getLODCoverage() const; + std::string getLODBaseName() const; + + + static bool lod_sort_predicate(const KRMesh *m1, const KRMesh *m2); + bool has_vertex_attribute(vertex_attrib_t attribute_type) const; + + int getSubmeshCount() const; + int getVertexCount(int submesh) const; + KRVector3 getVertexPosition(int index) const; + KRVector3 getVertexNormal(int index) const; + KRVector3 getVertexTangent(int index) const; + KRVector2 getVertexUVA(int index) const; + KRVector2 getVertexUVB(int index) const; + int getBoneIndex(int index, int weight_index) const; + float getBoneWeight(int index, int weight_index) const; + + void setVertexPosition(int index, const KRVector3 &v); + void setVertexNormal(int index, const KRVector3 &v); + void setVertexTangent(int index, const KRVector3 & v); + void setVertexUVA(int index, const KRVector2 &v); + void setVertexUVB(int index, const KRVector2 &v); + void setBoneIndex(int index, int weight_index, int bone_index); + void setBoneWeight(int index, int weight_index, float bone_weight); + + static size_t VertexSizeForAttributes(__int32_t vertex_attrib_flags); + static size_t AttributeOffset(__int32_t vertex_attrib, __int32_t vertex_attrib_flags); + + int getBoneCount(); + char *getBoneName(int bone_index); + + + model_format_t getModelFormat() const; + + bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo) const; + bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo) const; + + static int GetLODCoverage(const std::string &name); +private: + bool rayCast(const KRVector3 &line_v0, const KRVector3 &dir, int tri_index0, int tri_index1, int tri_index2, KRHitInfo &hitinfo) const; + static bool rayCast(const KRVector3 &line_v0, const KRVector3 &dir, const KRVector3 &tri_v0, const KRVector3 &tri_v1, const KRVector3 &tri_v2, const KRVector3 &tri_n0, const KRVector3 &tri_n1, const KRVector3 &tri_n2, KRHitInfo &hitinfo); + + 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 m_materials; + set m_uniqueMaterials; + + bool m_hasTransparency; + + + KRVector3 m_minPoint, m_maxPoint; + + KRDataBlock *m_pData; + + + + typedef struct { + char szTag[16]; + 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; + int32_t bone_count; + float minx, miny, minz, maxx, maxy, maxz; // Axis aligned bounding box, in model's coordinate space + unsigned char reserved[452]; // Pad out to 512 bytes + } pack_header; + + vector m_submeshes; + int m_vertex_attribute_offset[KRENGINE_NUM_ATTRIBUTES]; + int m_vertex_size; + void updateAttributeOffsets(); + + + void clearData(); + void clearBuffers(); + + void setName(const std::string name); + void optimize(); + + + + pack_material *getSubmesh(int mesh_index) const; + unsigned char *getVertexData() const; + unsigned char *getVertexData(int index) const; + pack_header *getHeader() const; + pack_bone *getBone(int index); +}; + + +#endif // KRMesh_I \ No newline at end of file diff --git a/KREngine/KREngine/Classes/KRModelCube.cpp b/KREngine/KREngine/Classes/KRMeshCube.cpp similarity index 95% rename from KREngine/KREngine/Classes/KRModelCube.cpp rename to KREngine/KREngine/Classes/KRMeshCube.cpp index d4ba8b8..6d9bf49 100644 --- a/KREngine/KREngine/Classes/KRModelCube.cpp +++ b/KREngine/KREngine/Classes/KRMeshCube.cpp @@ -1,5 +1,5 @@ // -// KRModelCube.cpp +// KRMeshCube.cpp // KREngine // // Copyright 2012 Kearwood Gilbert. All rights reserved. @@ -29,10 +29,10 @@ // or implied, of Kearwood Gilbert. // -#include "KRModelCube.h" +#include "KRMeshCube.h" -KRModelCube::KRModelCube(KRContext &context) : KRModel(context, "__cube") +KRMeshCube::KRMeshCube(KRContext &context) : KRMesh(context, "__cube") { std::vector vertices; std::vector uva; @@ -70,7 +70,7 @@ KRModelCube::KRModelCube(KRContext &context) : KRModel(context, "__cube") LoadData(vertices, uva, uvb, normals, tangents, submesh_starts, submesh_lengths, material_names, bone_names, bone_indexes, bone_weights, KRENGINE_MODEL_FORMAT_STRIP); } -KRModelCube::~KRModelCube() +KRMeshCube::~KRMeshCube() { } diff --git a/KREngine/KREngine/Classes/KRModelCube.h b/KREngine/KREngine/Classes/KRMeshCube.h similarity index 89% rename from KREngine/KREngine/Classes/KRModelCube.h rename to KREngine/KREngine/Classes/KRMeshCube.h index 4d6ea11..3cd7b7c 100644 --- a/KREngine/KREngine/Classes/KRModelCube.h +++ b/KREngine/KREngine/Classes/KRMeshCube.h @@ -1,5 +1,5 @@ // -// KRModelCube.h +// KRMeshCube.h // KREngine // // Copyright 2012 Kearwood Gilbert. All rights reserved. @@ -29,15 +29,15 @@ // or implied, of Kearwood Gilbert. // -#ifndef KRMODELCUBE_H -#define KRMODELCUBE_H +#ifndef KRMESHCUBE_H +#define KRMESHCUBE_H -#include "KRModel.h" +#include "KRMesh.h" -class KRModelCube : public KRModel { +class KRMeshCube : public KRMesh { public: - KRModelCube(KRContext &context); - virtual ~KRModelCube(); + KRMeshCube(KRContext &context); + virtual ~KRMeshCube(); private: }; diff --git a/KREngine/KREngine/Classes/KRModelManager.cpp b/KREngine/KREngine/Classes/KRMeshManager.cpp similarity index 69% rename from KREngine/KREngine/Classes/KRModelManager.cpp rename to KREngine/KREngine/Classes/KRMeshManager.cpp index 146c6a3..637ddc0 100644 --- a/KREngine/KREngine/Classes/KRModelManager.cpp +++ b/KREngine/KREngine/Classes/KRMeshManager.cpp @@ -1,5 +1,5 @@ // -// KRModelManager.cpp +// KRMeshManager.cpp // KREngine // // Copyright 2012 Kearwood Gilbert. All rights reserved. @@ -29,14 +29,14 @@ // or implied, of Kearwood Gilbert. // -#include "KRModelManager.h" +#include "KRMeshManager.h" #include -#import "KRModel.h" -#import "KRModelCube.h" -#import "KRModelSphere.h" +#import "KRMesh.h" +#import "KRMeshCube.h" +#import "KRMeshSphere.h" -KRModelManager::KRModelManager(KRContext &context) : KRContextObject(context) { +KRMeshManager::KRMeshManager(KRContext &context) : KRContextObject(context) { m_currentVBO.vbo_handle = 0; m_currentVBO.vao_handle = 0; m_currentVBO.data = NULL; @@ -44,12 +44,12 @@ KRModelManager::KRModelManager(KRContext &context) : KRContextObject(context) { m_randomParticleVertexData = NULL; m_volumetricLightingVertexData = NULL; - addModel(new KRModelCube(context)); - addModel(new KRModelSphere(context)); + addModel(new KRMeshCube(context)); + addModel(new KRMeshSphere(context)); } -KRModelManager::~KRModelManager() { - for(std::multimap::iterator itr = m_models.begin(); itr != m_models.end(); ++itr){ +KRMeshManager::~KRMeshManager() { + for(std::multimap::iterator itr = m_models.begin(); itr != m_models.end(); ++itr){ delete (*itr).second; } m_models.empty(); @@ -57,36 +57,36 @@ KRModelManager::~KRModelManager() { if(m_volumetricLightingVertexData != NULL) delete m_volumetricLightingVertexData; } -KRModel *KRModelManager::loadModel(const char *szName, KRDataBlock *pData) { +KRMesh *KRMeshManager::loadModel(const char *szName, KRDataBlock *pData) { std::string lowerName = szName; std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower); - KRModel *pModel = new KRModel(*m_pContext, lowerName, pData); + KRMesh *pModel = new KRMesh(*m_pContext, lowerName, pData); addModel(pModel); return pModel; } -void KRModelManager::addModel(KRModel *model) { - m_models.insert(std::pair(model->getLODBaseName(), model)); +void KRMeshManager::addModel(KRMesh *model) { + m_models.insert(std::pair(model->getLODBaseName(), model)); } -std::vector KRModelManager::getModel(const char *szName) { +std::vector KRMeshManager::getModel(const char *szName) { std::string lowerName = szName; std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower); - std::vector matching_models; + std::vector matching_models; - std::pair::iterator, std::multimap::iterator> range = m_models.equal_range(lowerName); - for(std::multimap::iterator itr_match = range.first; itr_match != range.second; itr_match++) { + std::pair::iterator, std::multimap::iterator> range = m_models.equal_range(lowerName); + for(std::multimap::iterator itr_match = range.first; itr_match != range.second; itr_match++) { matching_models.push_back(itr_match->second); } - std::sort(matching_models.begin(), matching_models.end(), KRModel::lod_sort_predicate); + std::sort(matching_models.begin(), matching_models.end(), KRMesh::lod_sort_predicate); if(matching_models.size() == 0) { fprintf(stderr, "ERROR: Model not found: %s\n", lowerName.c_str()); @@ -95,11 +95,11 @@ std::vector KRModelManager::getModel(const char *szName) { return matching_models; } -std::multimap KRModelManager::getModels() { +std::multimap KRMeshManager::getModels() { return m_models; } -void KRModelManager::unbindVBO() { +void KRMeshManager::unbindVBO() { if(m_currentVBO.data != NULL) { GLDEBUG(glBindBuffer(GL_ARRAY_BUFFER, 0)); m_currentVBO.size = 0; @@ -109,7 +109,7 @@ void KRModelManager::unbindVBO() { } } -void KRModelManager::bindVBO(GLvoid *data, GLsizeiptr size, bool enable_vertex, bool enable_normal, bool enable_tangent, bool enable_uva, bool enable_uvb, bool enable_bone_indexes, bool enable_bone_weights) { +void KRMeshManager::bindVBO(GLvoid *data, GLsizeiptr size, bool enable_vertex, bool enable_normal, bool enable_tangent, bool enable_uva, bool enable_uvb, bool enable_bone_indexes, bool enable_bone_weights) { if(m_currentVBO.data != data || m_currentVBO.size != size) { @@ -171,90 +171,90 @@ void KRModelManager::bindVBO(GLvoid *data, GLsizeiptr size, bool enable_vertex, } } -void KRModelManager::configureAttribs(bool enable_vertex, bool enable_normal, bool enable_tangent, bool enable_uva, bool enable_uvb, bool enable_bone_indexes, bool enable_bone_weights) +void KRMeshManager::configureAttribs(bool enable_vertex, bool enable_normal, bool enable_tangent, bool enable_uva, bool enable_uvb, bool enable_bone_indexes, bool enable_bone_weights) { __int32_t attributes = 0; if(enable_vertex) { - attributes |= (1 << KRModel::KRENGINE_ATTRIB_VERTEX); - GLDEBUG(glEnableVertexAttribArray(KRModel::KRENGINE_ATTRIB_VERTEX)); + attributes |= (1 << KRMesh::KRENGINE_ATTRIB_VERTEX); + GLDEBUG(glEnableVertexAttribArray(KRMesh::KRENGINE_ATTRIB_VERTEX)); } else { - GLDEBUG(glDisableVertexAttribArray(KRModel::KRENGINE_ATTRIB_VERTEX)); + GLDEBUG(glDisableVertexAttribArray(KRMesh::KRENGINE_ATTRIB_VERTEX)); } if(enable_normal) { - attributes |= (1 << KRModel::KRENGINE_ATTRIB_NORMAL); - GLDEBUG(glEnableVertexAttribArray(KRModel::KRENGINE_ATTRIB_NORMAL)); + attributes |= (1 << KRMesh::KRENGINE_ATTRIB_NORMAL); + GLDEBUG(glEnableVertexAttribArray(KRMesh::KRENGINE_ATTRIB_NORMAL)); } else { - GLDEBUG(glDisableVertexAttribArray(KRModel::KRENGINE_ATTRIB_NORMAL)); + GLDEBUG(glDisableVertexAttribArray(KRMesh::KRENGINE_ATTRIB_NORMAL)); } if(enable_tangent) { - attributes |= (1 << KRModel::KRENGINE_ATTRIB_TANGENT); - GLDEBUG(glEnableVertexAttribArray(KRModel::KRENGINE_ATTRIB_TANGENT)); + attributes |= (1 << KRMesh::KRENGINE_ATTRIB_TANGENT); + GLDEBUG(glEnableVertexAttribArray(KRMesh::KRENGINE_ATTRIB_TANGENT)); } else { - GLDEBUG(glDisableVertexAttribArray(KRModel::KRENGINE_ATTRIB_TANGENT)); + GLDEBUG(glDisableVertexAttribArray(KRMesh::KRENGINE_ATTRIB_TANGENT)); } if(enable_uva) { - attributes |= (1 << KRModel::KRENGINE_ATTRIB_TEXUVA); - GLDEBUG(glEnableVertexAttribArray(KRModel::KRENGINE_ATTRIB_TEXUVA)); + attributes |= (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA); + GLDEBUG(glEnableVertexAttribArray(KRMesh::KRENGINE_ATTRIB_TEXUVA)); } else { - GLDEBUG(glDisableVertexAttribArray(KRModel::KRENGINE_ATTRIB_TEXUVA)); + GLDEBUG(glDisableVertexAttribArray(KRMesh::KRENGINE_ATTRIB_TEXUVA)); } if(enable_uvb) { - attributes |= (1 << KRModel::KRENGINE_ATTRIB_TEXUVB); - GLDEBUG(glEnableVertexAttribArray(KRModel::KRENGINE_ATTRIB_TEXUVB)); + attributes |= (1 << KRMesh::KRENGINE_ATTRIB_TEXUVB); + GLDEBUG(glEnableVertexAttribArray(KRMesh::KRENGINE_ATTRIB_TEXUVB)); } else { - GLDEBUG(glDisableVertexAttribArray(KRModel::KRENGINE_ATTRIB_TEXUVB)); + GLDEBUG(glDisableVertexAttribArray(KRMesh::KRENGINE_ATTRIB_TEXUVB)); } if(enable_bone_indexes) { - attributes |= (1 << KRModel::KRENGINE_ATTRIB_BONEINDEXES); - GLDEBUG(glEnableVertexAttribArray(KRModel::KRENGINE_ATTRIB_BONEINDEXES)); + attributes |= (1 << KRMesh::KRENGINE_ATTRIB_BONEINDEXES); + GLDEBUG(glEnableVertexAttribArray(KRMesh::KRENGINE_ATTRIB_BONEINDEXES)); } else { - GLDEBUG(glDisableVertexAttribArray(KRModel::KRENGINE_ATTRIB_BONEINDEXES)); + GLDEBUG(glDisableVertexAttribArray(KRMesh::KRENGINE_ATTRIB_BONEINDEXES)); } if(enable_bone_weights) { - attributes |= (1 << KRModel::KRENGINE_ATTRIB_BONEWEIGHTS); - GLDEBUG(glEnableVertexAttribArray(KRModel::KRENGINE_ATTRIB_BONEWEIGHTS)); + attributes |= (1 << KRMesh::KRENGINE_ATTRIB_BONEWEIGHTS); + GLDEBUG(glEnableVertexAttribArray(KRMesh::KRENGINE_ATTRIB_BONEWEIGHTS)); } else { - GLDEBUG(glDisableVertexAttribArray(KRModel::KRENGINE_ATTRIB_BONEWEIGHTS)); + GLDEBUG(glDisableVertexAttribArray(KRMesh::KRENGINE_ATTRIB_BONEWEIGHTS)); } - GLsizei data_size = (GLsizei)KRModel::VertexSizeForAttributes(attributes); + GLsizei data_size = (GLsizei)KRMesh::VertexSizeForAttributes(attributes); if(enable_vertex) { - GLDEBUG(glVertexAttribPointer(KRModel::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, GL_FALSE, data_size, BUFFER_OFFSET(KRModel::AttributeOffset(KRModel::KRENGINE_ATTRIB_VERTEX, attributes)))); + GLDEBUG(glVertexAttribPointer(KRMesh::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, GL_FALSE, data_size, BUFFER_OFFSET(KRMesh::AttributeOffset(KRMesh::KRENGINE_ATTRIB_VERTEX, attributes)))); } if(enable_normal) { - GLDEBUG(glVertexAttribPointer(KRModel::KRENGINE_ATTRIB_NORMAL, 3, GL_FLOAT, GL_FALSE, data_size, BUFFER_OFFSET(KRModel::AttributeOffset(KRModel::KRENGINE_ATTRIB_NORMAL, attributes)))); + GLDEBUG(glVertexAttribPointer(KRMesh::KRENGINE_ATTRIB_NORMAL, 3, GL_FLOAT, GL_FALSE, data_size, BUFFER_OFFSET(KRMesh::AttributeOffset(KRMesh::KRENGINE_ATTRIB_NORMAL, attributes)))); } if(enable_tangent) { - GLDEBUG(glVertexAttribPointer(KRModel::KRENGINE_ATTRIB_TANGENT, 3, GL_FLOAT, GL_FALSE, data_size, BUFFER_OFFSET(KRModel::AttributeOffset(KRModel::KRENGINE_ATTRIB_TANGENT, attributes)))); + GLDEBUG(glVertexAttribPointer(KRMesh::KRENGINE_ATTRIB_TANGENT, 3, GL_FLOAT, GL_FALSE, data_size, BUFFER_OFFSET(KRMesh::AttributeOffset(KRMesh::KRENGINE_ATTRIB_TANGENT, attributes)))); } if(enable_uva) { - GLDEBUG(glVertexAttribPointer(KRModel::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, GL_FALSE, data_size, BUFFER_OFFSET(KRModel::AttributeOffset(KRModel::KRENGINE_ATTRIB_TEXUVA, attributes)))); + GLDEBUG(glVertexAttribPointer(KRMesh::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, GL_FALSE, data_size, BUFFER_OFFSET(KRMesh::AttributeOffset(KRMesh::KRENGINE_ATTRIB_TEXUVA, attributes)))); } if(enable_uvb) { - GLDEBUG(glVertexAttribPointer(KRModel::KRENGINE_ATTRIB_TEXUVB, 2, GL_FLOAT, GL_FALSE, data_size, BUFFER_OFFSET(KRModel::AttributeOffset(KRModel::KRENGINE_ATTRIB_TEXUVB, attributes)))); + GLDEBUG(glVertexAttribPointer(KRMesh::KRENGINE_ATTRIB_TEXUVB, 2, GL_FLOAT, GL_FALSE, data_size, BUFFER_OFFSET(KRMesh::AttributeOffset(KRMesh::KRENGINE_ATTRIB_TEXUVB, attributes)))); } if(enable_bone_indexes ) { - GLDEBUG(glVertexAttribPointer(KRModel::KRENGINE_ATTRIB_BONEINDEXES, 4, GL_UNSIGNED_BYTE, GL_FALSE, data_size, BUFFER_OFFSET(KRModel::AttributeOffset(KRModel::KRENGINE_ATTRIB_BONEINDEXES, attributes)))); + GLDEBUG(glVertexAttribPointer(KRMesh::KRENGINE_ATTRIB_BONEINDEXES, 4, GL_UNSIGNED_BYTE, GL_FALSE, data_size, BUFFER_OFFSET(KRMesh::AttributeOffset(KRMesh::KRENGINE_ATTRIB_BONEINDEXES, attributes)))); } if(enable_bone_weights) { - GLDEBUG(glVertexAttribPointer(KRModel::KRENGINE_ATTRIB_BONEWEIGHTS, 4, GL_FLOAT, GL_FALSE, data_size, BUFFER_OFFSET(KRModel::AttributeOffset(KRModel::KRENGINE_ATTRIB_BONEWEIGHTS, attributes)))); + GLDEBUG(glVertexAttribPointer(KRMesh::KRENGINE_ATTRIB_BONEWEIGHTS, 4, GL_FLOAT, GL_FALSE, data_size, BUFFER_OFFSET(KRMesh::AttributeOffset(KRMesh::KRENGINE_ATTRIB_BONEWEIGHTS, attributes)))); } } -long KRModelManager::getMemUsed() +long KRMeshManager::getMemUsed() { return m_vboMemUsed; } -void KRModelManager::rotateBuffers(bool new_frame) +void KRMeshManager::rotateBuffers(bool new_frame) { m_vbosPool.insert(m_vbosActive.begin(), m_vbosActive.end()); m_vbosActive.clear(); @@ -266,7 +266,7 @@ void KRModelManager::rotateBuffers(bool new_frame) } -KRModelManager::VolumetricLightingVertexData *KRModelManager::getVolumetricLightingVertexes() +KRMeshManager::VolumetricLightingVertexData *KRMeshManager::getVolumetricLightingVertexes() { if(m_volumetricLightingVertexData == NULL) { m_volumetricLightingVertexData = (VolumetricLightingVertexData *)malloc(sizeof(VolumetricLightingVertexData) * KRENGINE_MAX_VOLUMETRIC_PLANES * 6); @@ -312,7 +312,7 @@ KRModelManager::VolumetricLightingVertexData *KRModelManager::getVolumetricLight return m_volumetricLightingVertexData; } -KRModelManager::RandomParticleVertexData *KRModelManager::getRandomParticles() +KRMeshManager::RandomParticleVertexData *KRMeshManager::getRandomParticles() { if(m_randomParticleVertexData == NULL) { m_randomParticleVertexData = (RandomParticleVertexData *)malloc(sizeof(RandomParticleVertexData) * KRENGINE_MAX_RANDOM_PARTICLES * 3); diff --git a/KREngine/KREngine/Classes/KRModelManager.h b/KREngine/KREngine/Classes/KRMeshManager.h similarity index 85% rename from KREngine/KREngine/Classes/KRModelManager.h rename to KREngine/KREngine/Classes/KRMeshManager.h index 0a4da21..d5aac50 100644 --- a/KREngine/KREngine/Classes/KRModelManager.h +++ b/KREngine/KREngine/Classes/KRMeshManager.h @@ -1,5 +1,5 @@ // -// KRModelManager.h +// KRMeshManager.h // KREngine // // Copyright 2012 Kearwood Gilbert. All rights reserved. @@ -29,36 +29,36 @@ // or implied, of Kearwood Gilbert. // -#ifndef KRMODELMANAGER_H -#define KRMODELMANAGER_H +#ifndef KRMESHMANAGER_H +#define KRMESHMANAGER_H #import "KREngine-common.h" #import "KRContextObject.h" #import "KRDataBlock.h" class KRContext; -class KRModel; +class KRMesh; #include #import using std::map; -class KRModelManager : public KRContextObject { +class KRMeshManager : public KRContextObject { public: static const int KRENGINE_MAX_VOLUMETRIC_PLANES=500; static const int KRENGINE_MAX_RANDOM_PARTICLES=150000; - KRModelManager(KRContext &context); - virtual ~KRModelManager(); + KRMeshManager(KRContext &context); + virtual ~KRMeshManager(); void rotateBuffers(bool new_frame); - KRModel *loadModel(const char *szName, KRDataBlock *pData); - std::vector getModel(const char *szName); - void addModel(KRModel *model); + KRMesh *loadModel(const char *szName, KRDataBlock *pData); + std::vector getModel(const char *szName); + void addModel(KRMesh *model); std::vector getModelNames(); - std::multimap getModels(); + std::multimap getModels(); void bindVBO(GLvoid *data, GLsizeiptr size, bool enable_vertex, bool enable_normal, bool enable_tangent, bool enable_uva, bool enable_uvb, bool enable_bone_indexes, bool enable_bone_weights); @@ -92,7 +92,7 @@ public: VolumetricLightingVertexData *getVolumetricLightingVertexes(); private: - std::multimap m_models; // Multiple models with the same name/key may be inserted, representing multiple LOD levels of the model + std::multimap m_models; // Multiple models with the same name/key may be inserted, representing multiple LOD levels of the model typedef struct vbo_info { GLuint vbo_handle; diff --git a/KREngine/KREngine/Classes/KRModelSphere.cpp b/KREngine/KREngine/Classes/KRMeshSphere.cpp similarity index 96% rename from KREngine/KREngine/Classes/KRModelSphere.cpp rename to KREngine/KREngine/Classes/KRMeshSphere.cpp index ff3178d..ff73ea4 100644 --- a/KREngine/KREngine/Classes/KRModelSphere.cpp +++ b/KREngine/KREngine/Classes/KRMeshSphere.cpp @@ -1,5 +1,5 @@ // -// KRModelSphere.cpp +// KRMeshSphere.cpp // KREngine // // Copyright 2012 Kearwood Gilbert. All rights reserved. @@ -29,10 +29,10 @@ // or implied, of Kearwood Gilbert. // -#include "KRModelSphere.h" +#include "KRMeshSphere.h" -KRModelSphere::KRModelSphere(KRContext &context) : KRModel(context, "__sphere") +KRMeshSphere::KRMeshSphere(KRContext &context) : KRMesh(context, "__sphere") { std::vector vertices; std::vector uva; @@ -137,7 +137,7 @@ KRModelSphere::KRModelSphere(KRContext &context) : KRModel(context, "__sphere") LoadData(vertices, uva, uvb, normals, tangents, submesh_starts, submesh_lengths, material_names, bone_names, bone_indexes, bone_weights, KRENGINE_MODEL_FORMAT_TRIANGLES); } -KRModelSphere::~KRModelSphere() +KRMeshSphere::~KRMeshSphere() { } diff --git a/KREngine/KREngine/Classes/KRModelSphere.h b/KREngine/KREngine/Classes/KRMeshSphere.h similarity index 89% rename from KREngine/KREngine/Classes/KRModelSphere.h rename to KREngine/KREngine/Classes/KRMeshSphere.h index aef5912..bfa1de2 100644 --- a/KREngine/KREngine/Classes/KRModelSphere.h +++ b/KREngine/KREngine/Classes/KRMeshSphere.h @@ -1,5 +1,5 @@ // -// KRModelSphere.h +// KRMeshSphere.h // KREngine // // Copyright 2012 Kearwood Gilbert. All rights reserved. @@ -29,15 +29,15 @@ // or implied, of Kearwood Gilbert. // -#ifndef KRMODELSPHERE_H -#define KRMODELSPHERE_H +#ifndef KRMESHSPHERE_H +#define KRMESHSPHERE_H -#include "KRModel.h" +#include "KRMesh.h" -class KRModelSphere : public KRModel { +class KRMeshSphere : public KRMesh { public: - KRModelSphere(KRContext &context); - virtual ~KRModelSphere(); + KRMeshSphere(KRContext &context); + virtual ~KRMeshSphere(); private: }; diff --git a/KREngine/KREngine/Classes/KRModel.cpp b/KREngine/KREngine/Classes/KRModel.cpp index 1cae06c..e307a82 100644 --- a/KREngine/KREngine/Classes/KRModel.cpp +++ b/KREngine/KREngine/Classes/KRModel.cpp @@ -29,827 +29,138 @@ // or implied, of Kearwood Gilbert. // -#import -#include -#include -#include -#include -#include -#include +#include +#import "KRModel.h" +#import "KRContext.h" +#import "KRMesh.h" +#import "KRQuaternion.h" #include - -#include "KRModel.h" - -#include "KRVector3.h" -#import "KRShader.h" -#import "KRShaderManager.h" -#import "KRContext.h" - - -KRModel::KRModel(KRContext &context, std::string name) : KRResource(context, name) { - m_hasTransparency = false; - m_materials.clear(); - m_uniqueMaterials.clear(); - m_pData = new KRDataBlock(); - setName(name); +KRModel::KRModel(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map, float lod_min_coverage, bool receives_shadow, bool faces_camera) : KRNode(scene, instance_name) { + m_lightMap = light_map; + m_pLightMap = NULL; + m_model_name = model_name; + m_min_lod_coverage = lod_min_coverage; + m_receivesShadow = receives_shadow; + m_faces_camera = faces_camera; } -KRModel::KRModel(KRContext &context, std::string name, KRDataBlock *data) : KRResource(context, name) { - m_hasTransparency = false; - m_materials.clear(); - m_uniqueMaterials.clear(); - m_pData = new KRDataBlock(); - setName(name); - - loadPack(data); -} - -void KRModel::setName(const std::string name) { - m_lodCoverage = 100; - m_lodBaseName = name; - - size_t last_underscore_pos = name.find_last_of('_'); - if(last_underscore_pos != std::string::npos) { - // Found an underscore - std::string suffix = name.substr(last_underscore_pos + 1); - if(suffix.find_first_of("lod") == 0) { - std::string lod_level_string = suffix.substr(3); - char *end = NULL; - int c = (int)strtol(lod_level_string.c_str(), &end, 10); - if(c >= 0 && c <= 100 && *end == '\0') { - m_lodCoverage = c; - m_lodBaseName = name.substr(0, last_underscore_pos); - } - } - } - -} - -int KRModel::GetLODCoverage(const std::string &name) -{ - int lod_coverage = 100; - size_t last_underscore_pos = name.find_last_of('_'); - if(last_underscore_pos != std::string::npos) { - // Found an underscore - std::string suffix = name.substr(last_underscore_pos + 1); - if(suffix.find_first_of("lod") == 0) { - std::string lod_level_string = suffix.substr(3); - char *end = NULL; - int c = (int)strtol(lod_level_string.c_str(), &end, 10); - if(c >= 0 && c <= 100 && *end == '\0') { - lod_coverage = c; - //m_lodBaseName = name.substr(0, last_underscore_pos); - } - } - } - return lod_coverage; -} - - - KRModel::~KRModel() { - clearData(); - if(m_pData) delete m_pData; + } -std::string KRModel::getExtension() { - return "krobject"; +std::string KRModel::getElementName() { + return "model"; } -bool KRModel::save(const std::string& path) { - clearBuffers(); - return m_pData->save(path); +tinyxml2::XMLElement *KRModel::saveXML( tinyxml2::XMLNode *parent) +{ + tinyxml2::XMLElement *e = KRNode::saveXML(parent); + e->SetAttribute("mesh", m_model_name.c_str()); + e->SetAttribute("light_map", m_lightMap.c_str()); + e->SetAttribute("lod_min_coverage", m_min_lod_coverage); + e->SetAttribute("receives_shadow", m_receivesShadow ? "true" : "false"); + e->SetAttribute("faces_camera", m_faces_camera ? "true" : "false"); + return e; } -bool KRModel::save(KRDataBlock &data) { - clearBuffers(); - data.append(*m_pData); - return true; -} - -void KRModel::loadPack(KRDataBlock *data) { - clearData(); - delete m_pData; - m_pData = data; - updateAttributeOffsets(); - pack_header *pHeader = getHeader(); - m_minPoint = KRVector3(pHeader->minx, pHeader->miny, pHeader->minz); - m_maxPoint = KRVector3(pHeader->maxx, pHeader->maxy, pHeader->maxz); -} - -void KRModel::render(KRCamera *pCamera, std::vector &lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector &bones) { - - //fprintf(stderr, "Rendering model: %s\n", m_name.c_str()); - if(renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) { - - if(m_materials.size() == 0) { - vector submeshes = getSubmeshes(); - - for(std::vector::iterator itr = submeshes.begin(); itr != submeshes.end(); itr++) { - const char *szMaterialName = (*itr)->szMaterialName; - KRMaterial *pMaterial = getContext().getMaterialManager()->getMaterial(szMaterialName); - m_materials.push_back(pMaterial); - if(pMaterial) { - m_uniqueMaterials.insert(pMaterial); - } else { - fprintf(stderr, "Missing material: %s\n", szMaterialName); - } - } - - m_hasTransparency = false; - for(std::set::iterator mat_itr = m_uniqueMaterials.begin(); mat_itr != m_uniqueMaterials.end(); mat_itr++) { - if((*mat_itr)->isTransparent()) { - m_hasTransparency = true; - break; - } - } - } - - KRMaterial *pPrevBoundMaterial = NULL; - char szPrevShaderKey[256]; - szPrevShaderKey[0] = '\0'; - int cSubmeshes = getSubmeshes().size(); - if(renderPass == KRNode::RENDER_PASS_SHADOWMAP) { - for(int iSubmesh=0; iSubmeshisTransparent()) { - // Exclude transparent and semi-transparent meshes from shadow maps - renderSubmesh(iSubmesh); +void KRModel::loadModel() { + if(m_models.size() == 0) { + std::vector models = m_pContext->getModelManager()->getModel(m_model_name.c_str()); // The model manager returns the LOD levels in sorted order, with the highest detail first + std::map > bones; + if(models.size() > 0) { + bool all_bones_found = true; + for(std::vector::iterator model_itr = models.begin(); model_itr != models.end(); model_itr++) { + KRMesh *model = *model_itr; + std::vector model_bones; + int bone_count = model->getBoneCount(); + for(int bone_index=0; bone_index < bone_count; bone_index++) { + KRBone *matching_bone = dynamic_cast(getScene().getRootNode()->find(model->getBoneName(bone_index))); + if(matching_bone) { + model_bones.push_back(matching_bone); + } else { + all_bones_found = false; // Reject when there are any missing bones or multiple matches } } - + bones[model] = model_bones; } - } else { - // Apply submeshes in per-material batches to reduce number of state changes - for(std::set::iterator mat_itr = m_uniqueMaterials.begin(); mat_itr != m_uniqueMaterials.end(); mat_itr++) { - for(int iSubmesh=0; iSubmeshisTransparent() && renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT) || (pMaterial->isTransparent() && renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) { - if(pMaterial->bind(&pPrevBoundMaterial, szPrevShaderKey, pCamera, lights, bones, viewport, matModel, pLightMap, renderPass)) { - - switch(pMaterial->getAlphaMode()) { - case KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE: // Non-transparent materials - case KRMaterial::KRMATERIAL_ALPHA_MODE_TEST: // Alpha in diffuse texture is interpreted as punch-through when < 0.5 - renderSubmesh(iSubmesh); - break; - case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE: // Blended alpha with backface culling - renderSubmesh(iSubmesh); - break; - case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE: // Blended alpha rendered in two passes. First pass renders backfaces; second pass renders frontfaces. - // Render back faces first - GLDEBUG(glCullFace(GL_BACK)); - renderSubmesh(iSubmesh); - - // Render front faces second - GLDEBUG(glCullFace(GL_BACK)); - renderSubmesh(iSubmesh); - break; - } - } - - - } - } - } + if(all_bones_found) { + m_models = models; + m_bones = bones; + getScene().notify_sceneGraphModify(this); } } } } -GLfloat KRModel::getMaxDimension() { - GLfloat m = 0.0; - if(m_maxPoint.x - m_minPoint.x > m) m = m_maxPoint.x - m_minPoint.x; - if(m_maxPoint.y - m_minPoint.y > m) m = m_maxPoint.y - m_minPoint.y; - if(m_maxPoint.z - m_minPoint.z > m) m = m_maxPoint.z - m_minPoint.z; - return m; +void KRModel::render(KRCamera *pCamera, std::vector &lights, const KRViewport &viewport, KRNode::RenderPass renderPass) { + + + KRNode::render(pCamera, lights, viewport, renderPass); + + if(renderPass != KRNode::RENDER_PASS_DEFERRED_LIGHTS && (renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT || this->hasTransparency()) && renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) { + // Don't render meshes on second pass of the deferred lighting renderer, as only lights will be applied + + loadModel(); + + if(m_models.size() > 0) { + float lod_coverage = getBounds().coverage(viewport.getViewProjectionMatrix(), viewport.getSize()); // This also checks the view frustrum culling + if(lod_coverage > m_min_lod_coverage) { + + // ---===--- Select the best LOD model based on screen coverage ---===--- + std::vector::iterator itr=m_models.begin(); + KRMesh *pModel = *itr++; + + while(itr != m_models.end()) { + KRMesh *pLODModel = *itr++; + if((float)pLODModel->getLODCoverage() / 100.0f > lod_coverage && pLODModel->getLODCoverage() < pModel->getLODCoverage()) { + pModel = pLODModel; + } else { + break; + } + } + + if(m_pLightMap == NULL && m_lightMap.size()) { + m_pLightMap = getContext().getTextureManager()->getTexture(m_lightMap.c_str()); + } + + if(m_pLightMap && pCamera->settings.bEnableLightMap && renderPass != RENDER_PASS_SHADOWMAP && renderPass != RENDER_PASS_GENERATE_SHADOWMAPS) { + m_pContext->getTextureManager()->selectTexture(5, m_pLightMap); + } + + KRMat4 matModel = getModelMatrix(); + if(m_faces_camera) { + KRVector3 model_center = KRMat4::Dot(matModel, KRVector3::Zero()); + KRVector3 camera_pos = viewport.getCameraPosition(); + matModel = KRQuaternion(KRVector3::Forward(), KRVector3::Normalize(camera_pos - model_center)).rotationMatrix() * matModel; + } + + pModel->render(pCamera, lights, viewport, matModel, m_pLightMap, renderPass, m_bones[pModel]); + } + } + } } bool KRModel::hasTransparency() { - return m_hasTransparency; -} - - -vector KRModel::getSubmeshes() { - if(m_submeshes.size() == 0) { - pack_header *pHeader = getHeader(); - pack_material *pPackMaterials = (pack_material *)(pHeader+1); - m_submeshes.clear(); - for(int iMaterial=0; iMaterial < pHeader->submesh_count; iMaterial++) { - pack_material *pPackMaterial = pPackMaterials + iMaterial; - - Submesh *pSubmesh = new Submesh(); - pSubmesh->start_vertex = pPackMaterial->start_vertex; - pSubmesh->vertex_count = pPackMaterial->vertex_count; - - strncpy(pSubmesh->szMaterialName, pPackMaterial->szName, KRENGINE_MAX_NAME_LENGTH); - pSubmesh->szMaterialName[KRENGINE_MAX_NAME_LENGTH-1] = '\0'; - //fprintf(stderr, "Submesh material: \"%s\"\n", pSubmesh->szMaterialName); - m_submeshes.push_back(pSubmesh); - } - } - return m_submeshes; -} - -void KRModel::renderSubmesh(int iSubmesh) { - unsigned char *pVertexData = getVertexData(); - - pack_header *pHeader = getHeader(); - int cBuffers = (pHeader->vertex_count + MAX_VBO_SIZE - 1) / MAX_VBO_SIZE; - - vector submeshes = getSubmeshes(); - Submesh *pSubmesh = submeshes[iSubmesh]; - - int iVertex = pSubmesh->start_vertex; - int iBuffer = iVertex / MAX_VBO_SIZE; - iVertex = iVertex % MAX_VBO_SIZE; - int cVertexes = pSubmesh->vertex_count; - while(cVertexes > 0) { - GLsizei cBufferVertexes = iBuffer < cBuffers - 1 ? MAX_VBO_SIZE : pHeader->vertex_count % MAX_VBO_SIZE; - int vertex_size = m_vertex_size; - - void *vbo_end = (unsigned char *)pVertexData + iBuffer * MAX_VBO_SIZE * vertex_size + vertex_size * cBufferVertexes; - void *buffer_end = m_pData->getEnd(); - assert(vbo_end <= buffer_end); - assert(cBufferVertexes <= 65535); - - - m_pContext->getModelManager()->bindVBO((unsigned char *)pVertexData + iBuffer * MAX_VBO_SIZE * vertex_size, vertex_size * cBufferVertexes, has_vertex_attribute(KRENGINE_ATTRIB_VERTEX), has_vertex_attribute(KRENGINE_ATTRIB_NORMAL), has_vertex_attribute(KRENGINE_ATTRIB_TANGENT), has_vertex_attribute(KRENGINE_ATTRIB_TEXUVA), has_vertex_attribute(KRENGINE_ATTRIB_TEXUVB), has_vertex_attribute(KRENGINE_ATTRIB_BONEINDEXES), - has_vertex_attribute(KRENGINE_ATTRIB_BONEWEIGHTS)); - - - 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; - iBuffer++; - } 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 vertices, std::vector uva, std::vector uvb, std::vector normals, std::vector tangents, std::vector submesh_starts, std::vector submesh_lengths, std::vector material_names, std::vector bone_names, std::vector > bone_indexes, std::vector > bone_weights, KRModel::model_format_t model_format) { - - clearData(); - - bool calculate_normals = true; - bool calculate_tangents = true; - - - __int32_t vertex_attrib_flags = 0; - if(vertices.size()) { - vertex_attrib_flags |= (1 << KRENGINE_ATTRIB_VERTEX); - } - if(normals.size() || calculate_normals) { - vertex_attrib_flags += (1 << KRENGINE_ATTRIB_NORMAL); - } - if(tangents.size() || calculate_tangents) { - vertex_attrib_flags += (1 << KRENGINE_ATTRIB_TANGENT); - } - if(uva.size()) { - vertex_attrib_flags += (1 << KRENGINE_ATTRIB_TEXUVA); - } - if(uvb.size()) { - vertex_attrib_flags += (1 << KRENGINE_ATTRIB_TEXUVB); - } - if(bone_names.size()) { - vertex_attrib_flags += (1 << KRENGINE_ATTRIB_BONEINDEXES) + (1 << KRENGINE_ATTRIB_BONEWEIGHTS); - } - size_t vertex_size = VertexSizeForAttributes(vertex_attrib_flags); - - size_t submesh_count = submesh_lengths.size(); - size_t vertex_count = vertices.size(); - size_t bone_count = bone_names.size(); - size_t new_file_size = sizeof(pack_header) + sizeof(pack_material) * submesh_count + sizeof(pack_bone) * bone_count + vertex_size * vertex_count; - m_pData->expand(new_file_size); - - pack_header *pHeader = getHeader(); - memset(pHeader, 0, sizeof(pack_header)); - pHeader->vertex_attrib_flags = vertex_attrib_flags; - 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(); - - pack_material *pPackMaterials = (pack_material *)(pHeader+1); - - for(int iMaterial=0; iMaterial < pHeader->submesh_count; iMaterial++) { - pack_material *pPackMaterial = pPackMaterials + iMaterial; - pPackMaterial->start_vertex = submesh_starts[iMaterial]; - pPackMaterial->vertex_count = submesh_lengths[iMaterial]; - memset(pPackMaterial->szName, 0, KRENGINE_MAX_NAME_LENGTH); - strncpy(pPackMaterial->szName, material_names[iMaterial].c_str(), KRENGINE_MAX_NAME_LENGTH); - } - - for(int bone_index=0; bone_index < bone_count; bone_index++) { - pack_bone *bone = getBone(bone_index); - memset(bone->szName, 0, KRENGINE_MAX_NAME_LENGTH); - strncpy(bone->szName, bone_names[bone_index].c_str(), KRENGINE_MAX_NAME_LENGTH); - } - - bool bFirstVertex = true; - -// VertexData *pVertexData = (VertexData *)(pPackMaterials + pHeader->submesh_count); -// VertexData *pVertex = pVertexData; - memset(getVertexData(), 0, m_vertex_size * vertices.size()); - for(int iVertex=0; iVertex < vertices.size(); iVertex++) { - KRVector3 source_vertex = vertices[iVertex]; - setVertexPosition(iVertex, source_vertex); - if(bone_names.size()) { - for(int bone_weight_index=0; bone_weight_index m_maxPoint.x) m_maxPoint.x = source_vertex.x; - if(source_vertex.y > m_maxPoint.y) m_maxPoint.y = source_vertex.y; - if(source_vertex.z > m_maxPoint.z) m_maxPoint.z = source_vertex.z; - } - if(uva.size() > iVertex) { - setVertexUVA(iVertex, uva[iVertex]); - } - if(uvb.size() > iVertex) { - setVertexUVB(iVertex, uvb[iVertex]); - } - if(normals.size() > iVertex) { - setVertexNormal(iVertex, normals[iVertex]); - } - if(tangents.size() > iVertex) { - setVertexTangent(iVertex, tangents[iVertex]); - } - } - - pHeader->minx = m_minPoint.x; - pHeader->miny = m_minPoint.y; - pHeader->minz = m_minPoint.z; - pHeader->maxx = m_maxPoint.x; - pHeader->maxy = m_maxPoint.y; - pHeader->maxz = m_maxPoint.z; - - - // Calculate missing surface normals and tangents - //cout << " Calculate surface normals and tangents\n"; - - for(int iVertex=0; iVertex < vertices.size(); iVertex+= 3) { - KRVector3 p1 = getVertexPosition(iVertex); - KRVector3 p2 = getVertexPosition(iVertex+1); - KRVector3 p3 = getVertexPosition(iVertex+2); - KRVector3 v1 = p2 - p1; - KRVector3 v2 = p3 - p1; - - - // -- Calculate normal if missing -- - if(calculate_normals) { - KRVector3 first_normal = getVertexNormal(iVertex); - if(first_normal.x == 0.0f && first_normal.y == 0.0f && first_normal.z == 0.0f) { - // Note - We don't take into consideration smoothing groups or smoothing angles when generating normals; all generated normals represent flat shaded polygons - KRVector3 normal = KRVector3::Cross(v1, v2); - - normal.normalize(); - setVertexNormal(iVertex, normal); - setVertexNormal(iVertex+1, normal); - setVertexNormal(iVertex+2, normal); - } - } - - // -- Calculate tangent vector for normal mapping -- - if(calculate_tangents) { - KRVector3 first_tangent = getVertexTangent(iVertex); - if(first_tangent.x == 0.0f && first_tangent.y == 0.0f && first_tangent.z == 0.0f) { - - KRVector2 uv0 = getVertexUVA(iVertex); - KRVector2 uv1 = getVertexUVA(iVertex + 1); - KRVector2 uv2 = getVertexUVA(iVertex + 2); - - KRVector2 st1 = KRVector2(uv1.x - uv0.x, uv1.y - uv0.y); - KRVector2 st2 = KRVector2(uv2.x - uv0.x, uv2.y - uv0.y); - double coef = 1/ (st1.x * st2.y - st2.x * st1.y); - - KRVector3 tangent( - coef * ((v1.x * st2.y) + (v2.x * -st1.y)), - coef * ((v1.y * st2.y) + (v2.y * -st1.y)), - coef * ((v1.z * st2.y) + (v2.z * -st1.y)) - ); - - tangent.normalize(); - setVertexTangent(iVertex, tangent); - setVertexTangent(iVertex+1, tangent); - setVertexTangent(iVertex+2, tangent); - } - } - } - - optimize(); -} - -KRVector3 KRModel::getMinPoint() const { - return m_minPoint; -} - -KRVector3 KRModel::getMaxPoint() const { - return m_maxPoint; -} - -void KRModel::clearData() { - m_pData->unload(); -} - -void KRModel::clearBuffers() { - m_submeshes.clear(); -} - -int KRModel::getLODCoverage() const { - return m_lodCoverage; -} - -std::string KRModel::getLODBaseName() const { - return m_lodBaseName; -} - -// Predicate used with std::sort to sort by highest detail model first, decending to lowest detail LOD model -bool KRModel::lod_sort_predicate(const KRModel *m1, const KRModel *m2) -{ - return m1->m_lodCoverage > m2->m_lodCoverage; -} - -bool KRModel::has_vertex_attribute(vertex_attrib_t attribute_type) const -{ - return (getHeader()->vertex_attrib_flags & (1 << attribute_type)) != 0; -} - -KRModel::pack_header *KRModel::getHeader() const -{ - return (pack_header *)m_pData->getStart(); -} - -KRModel::pack_bone *KRModel::getBone(int index) -{ - pack_header *header = getHeader(); - return (pack_bone *)((unsigned char *)m_pData->getStart() + sizeof(pack_header) + sizeof(pack_material) * header->submesh_count + sizeof(pack_bone) * index); -} - -unsigned char *KRModel::getVertexData() const { - pack_header *pHeader = getHeader(); - return ((unsigned char *)m_pData->getStart()) + sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count; -} - -KRModel::pack_material *KRModel::getSubmesh(int mesh_index) const -{ - return (pack_material *)((unsigned char *)m_pData->getStart() + sizeof(pack_header)) + mesh_index; -} - -unsigned char *KRModel::getVertexData(int index) const -{ - return getVertexData() + m_vertex_size * index; -} - -int KRModel::getSubmeshCount() const -{ - pack_header *header = getHeader(); - return header->submesh_count; -} - -int KRModel::getVertexCount(int submesh) const -{ - return getSubmesh(submesh)->vertex_count; -} - -KRVector3 KRModel::getVertexPosition(int index) const -{ - if(has_vertex_attribute(KRENGINE_ATTRIB_VERTEX)) { - return KRVector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX])); + if(m_models.size() > 0) { + return m_models[0]->hasTransparency(); } else { - return KRVector3::Zero(); - } -} - -KRVector3 KRModel::getVertexNormal(int index) const -{ - if(has_vertex_attribute(KRENGINE_ATTRIB_NORMAL)) { - return KRVector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_NORMAL])); - } else { - return KRVector3::Zero(); - } -} - -KRVector3 KRModel::getVertexTangent(int index) const -{ - if(has_vertex_attribute(KRENGINE_ATTRIB_TANGENT)) { - return KRVector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TANGENT])); - } else { - return KRVector3::Zero(); - } -} - -KRVector2 KRModel::getVertexUVA(int index) const -{ - if(has_vertex_attribute(KRENGINE_ATTRIB_TEXUVA)) { - return KRVector2((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TEXUVA])); - } else { - return KRVector2::Zero(); - } -} - -KRVector2 KRModel::getVertexUVB(int index) const -{ - if(has_vertex_attribute(KRENGINE_ATTRIB_TEXUVB)) { - return KRVector2((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TEXUVB])); - } else { - return KRVector2::Zero(); - } -} - -void KRModel::setVertexPosition(int index, const KRVector3 &v) -{ - float *vert = (float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX]); - vert[0] = v.x; - vert[1] = v.y; - vert[2] = v.z; -} - -void KRModel::setVertexNormal(int index, const KRVector3 &v) -{ - float *vert = (float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_NORMAL]); - vert[0] = v.x; - vert[1] = v.y; - vert[2] = v.z; -} - -void KRModel::setVertexTangent(int index, const KRVector3 & v) -{ - float *vert = (float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TANGENT]); - vert[0] = v.x; - vert[1] = v.y; - vert[2] = v.z; -} - -void KRModel::setVertexUVA(int index, const KRVector2 &v) -{ - float *vert = (float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TEXUVA]); - vert[0] = v.x; - vert[1] = v.y; -} - -void KRModel::setVertexUVB(int index, const KRVector2 &v) -{ - float *vert = (float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TEXUVB]); - vert[0] = v.x; - vert[1] = v.y; -} - - -int KRModel::getBoneIndex(int index, int weight_index) const -{ - unsigned char *vert = (unsigned char *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_BONEINDEXES]); - return vert[weight_index]; -} - -void KRModel::setBoneIndex(int index, int weight_index, int bone_index) -{ - unsigned char *vert = (unsigned char *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_BONEINDEXES]); - vert[weight_index] = bone_index; -} - -float KRModel::getBoneWeight(int index, int weight_index) const -{ - float *vert = (float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_BONEWEIGHTS]); - return vert[weight_index]; -} - -void KRModel::setBoneWeight(int index, int weight_index, float bone_weight) -{ - float *vert = (float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_BONEWEIGHTS]); - vert[weight_index] = bone_weight; -} - -size_t KRModel::VertexSizeForAttributes(__int32_t vertex_attrib_flags) -{ - size_t data_size = 0; - if(vertex_attrib_flags & (1 << KRENGINE_ATTRIB_VERTEX)) { - data_size += sizeof(float) * 3; - } - if(vertex_attrib_flags & (1 << KRENGINE_ATTRIB_NORMAL)) { - data_size += sizeof(float) * 3; - } - if(vertex_attrib_flags & (1 << KRENGINE_ATTRIB_TANGENT)) { - data_size += sizeof(float) * 3; - } - if(vertex_attrib_flags & (1 << KRENGINE_ATTRIB_TEXUVA)) { - data_size += sizeof(float) * 2; - } - if(vertex_attrib_flags & (1 << KRENGINE_ATTRIB_TEXUVB)) { - data_size += sizeof(float) * 2; - } - if(vertex_attrib_flags & (1 << KRENGINE_ATTRIB_BONEINDEXES)) { - data_size += 4; // 4 bytes - } - if(vertex_attrib_flags & (1 << KRENGINE_ATTRIB_BONEWEIGHTS)) { - data_size += sizeof(float) * 4; - } - return data_size; -} - -void KRModel::updateAttributeOffsets() -{ - pack_header *header = getHeader(); - int mask = 0; - for(int i=0; i < KRENGINE_NUM_ATTRIBUTES; i++) { - if(has_vertex_attribute((vertex_attrib_t)i)) { - m_vertex_attribute_offset[i] = VertexSizeForAttributes(header->vertex_attrib_flags & mask); - } else { - m_vertex_attribute_offset[i] = -1; - } - mask = (mask << 1) | 1; - } - m_vertex_size = VertexSizeForAttributes(header->vertex_attrib_flags); -} - -size_t KRModel::AttributeOffset(__int32_t vertex_attrib, __int32_t vertex_attrib_flags) -{ - int mask = 0; - for(int i=0; i < vertex_attrib; i++) { - if(vertex_attrib_flags & (1 << i)) { - mask |= (1 << i); - } - } - return VertexSizeForAttributes(mask); -} - -int KRModel::getBoneCount() -{ - pack_header *header = getHeader(); - return header->bone_count; -} - -char *KRModel::getBoneName(int bone_index) -{ - return getBone(bone_index)->szName; -} - -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() const -{ - return (model_format_t)getHeader()->model_format; -} - -bool KRModel::rayCast(const KRVector3 &line_v0, const KRVector3 &dir, const KRVector3 &tri_v0, const KRVector3 &tri_v1, const KRVector3 &tri_v2, const KRVector3 &tri_n0, const KRVector3 &tri_n1, const KRVector3 &tri_n2, KRHitInfo &hitinfo) -{ - // algorithm based on Dan Sunday's implementation at http://geomalgorithms.com/a06-_intersect-2.html - const float SMALL_NUM = 0.00000001; // anything that avoids division overflow - KRVector3 u, v, n; // triangle vectors - KRVector3 w0, w; // ray vectors - float r, a, b; // params to calc ray-plane intersect - - // get triangle edge vectors and plane normal - u = tri_v1 - tri_v0; - v = tri_v2 - tri_v0; - n = KRVector3::Cross(u, v); // cross product - if (n == KRVector3::Zero()) // triangle is degenerate - return false; // do not deal with this case - - w0 = line_v0 - tri_v0; - a = -KRVector3::Dot(n, w0); - b = KRVector3::Dot(n,dir); - if (fabs(b) < SMALL_NUM) { // ray is parallel to triangle plane - if (a == 0) - return false; // ray lies in triangle plane - else { - return false; // ray disjoint from plane - } - } - - // get intersect point of ray with triangle plane - r = a / b; - if (r < 0.0) // ray goes away from triangle - return false; // => no intersect - // for a segment, also test if (r > 1.0) => no intersect - - - KRVector3 hit_point = line_v0 + dir * r; // intersect point of ray and plane - - // is hit_point inside triangle? - float uu, uv, vv, wu, wv, D; - uu = KRVector3::Dot(u,u); - uv = KRVector3::Dot(u,v); - vv = KRVector3::Dot(v,v); - w = hit_point - tri_v0; - wu = KRVector3::Dot(w,u); - wv = KRVector3::Dot(w,v); - D = uv * uv - uu * vv; - - // get and test parametric coords - float s, t; - s = (uv * wv - vv * wu) / D; - if (s < 0.0 || s > 1.0) // hit_point is outside triangle return false; - t = (uv * wu - uu * wv) / D; - if (t < 0.0 || (s + t) > 1.0) // hit_point is outside triangle - return false; - - float new_hit_distance_sqr = (hit_point - line_v0).sqrMagnitude(); - float prev_hit_distance_sqr = (hitinfo.getPosition() - line_v0).sqrMagnitude(); - if(new_hit_distance_sqr < prev_hit_distance_sqr) { - // Update the hitinfo object if this hit is closer than the prior hit - - // Interpolate between the three vertex normals, performing a 3-way lerp of tri_n0, tri_n1, and tri_n2 - float distance_v0 = (tri_v0 - hit_point).magnitude(); - float distance_v1 = (tri_v1 - hit_point).magnitude(); - float distance_v2 = (tri_v2 - hit_point).magnitude(); - float distance_total = distance_v0 + distance_v1 + distance_v2; - distance_v0 /= distance_total; - distance_v1 /= distance_total; - distance_v2 /= distance_total; - KRVector3 normal = KRVector3::Normalize(tri_n0 * (1.0 - distance_v0) + tri_n1 * (1.0 - distance_v1) + tri_n2 * (1.0 - distance_v2)); - - hitinfo = KRHitInfo(hit_point, normal); } - - return true; // hit_point is in triangle } -bool KRModel::rayCast(const KRVector3 &line_v0, const KRVector3 &dir, int tri_index0, int tri_index1, int tri_index2, KRHitInfo &hitinfo) const -{ - return rayCast(line_v0, dir, getVertexPosition(tri_index0), getVertexPosition(tri_index1), getVertexPosition(tri_index2), getVertexNormal(tri_index0), getVertexNormal(tri_index1), getVertexNormal(tri_index2), hitinfo); -} - -bool KRModel::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo) const -{ - bool hit_found = false; - for(int submesh_index=0; submesh_index < getSubmeshCount(); submesh_index++) { - int vertex_count = getVertexCount(submesh_index); - switch(getModelFormat()) { - case KRENGINE_MODEL_FORMAT_TRIANGLES: - for(int triangle_index=0; triangle_index < vertex_count / 3; triangle_index++) { - if(rayCast(v0, dir, getVertexPosition(triangle_index*3), getVertexPosition(triangle_index*3+1), getVertexPosition(triangle_index*3+2), getVertexNormal(triangle_index*3), getVertexNormal(triangle_index*3+1), getVertexNormal(triangle_index*3+2), hitinfo)) hit_found = true; - } - break; - case KRENGINE_MODEL_FORMAT_STRIP: - for(int triangle_index=0; triangle_index < vertex_count - 2; triangle_index++) { - if(rayCast(v0, dir, getVertexPosition(triangle_index), getVertexPosition(triangle_index+1), getVertexPosition(triangle_index+2), getVertexNormal(triangle_index), getVertexNormal(triangle_index+1), getVertexNormal(triangle_index+2), hitinfo)) hit_found = true; - } - break; - default: - break; +KRAABB KRModel::getBounds() { + loadModel(); + if(m_models.size() > 0) { + if(m_faces_camera) { + KRAABB normal_bounds = KRAABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix()); + float max_dimension = normal_bounds.longest_radius(); + return KRAABB(normal_bounds.center()-KRVector3(max_dimension), normal_bounds.center() + KRVector3(max_dimension)); + } else { + return KRAABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix()); } + } else { + return KRAABB::Infinite(); } - return hit_found; } -bool KRModel::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo) const -{ - KRHitInfo new_hitinfo; - KRVector3 dir = KRVector3::Normalize(v1 - v0); - if(rayCast(v0, dir, new_hitinfo)) { - if((new_hitinfo.getPosition() - v0).sqrMagnitude() <= (v1 - v0).sqrMagnitude()) { - // The hit was between v1 and v2 - hitinfo = new_hitinfo; - return true; - } - } - return false; // Either no hit, or the hit was beyond v1 -} diff --git a/KREngine/KREngine/Classes/KRModel.h b/KREngine/KREngine/Classes/KRModel.h index 4c757dd..0477cd1 100644 --- a/KREngine/KREngine/Classes/KRModel.h +++ b/KREngine/KREngine/Classes/KRModel.h @@ -28,212 +28,56 @@ // authors and should not be interpreted as representing official policies, either expressed // or implied, of Kearwood Gilbert. // -#import -#import -#import -#import -#import "KRVector2.h" -#import "KRContext.h" -#import "KRBone.h" + + #import "KREngine-common.h" -using std::vector; -using std::set; -using std::list; +#ifndef KRMODEL_H +#define KRMODEL_H - -#define MAX_VBO_SIZE 65535 -#define KRENGINE_MAX_BONE_WEIGHTS_PER_VERTEX 4 -#define KRENGINE_MAX_NAME_LENGTH 256 -// MAX_VBO_SIZE must be divisible by 3 so triangles aren't split across VBO objects... - -#define BUFFER_OFFSET(i) ((char *)NULL + (i)) - -#ifndef KRMODEL_I -#define KRMODEL_I - -#import "KRMaterialManager.h" +#import "KRMesh.h" +#import "KRMat4.h" +#import "KRVector3.h" +#import "KRModel.h" #import "KRCamera.h" -#import "KRViewport.h" -#import "KRHitInfo.h" +#import "KRMeshManager.h" +#import "KRNode.h" +#import "KRContext.h" +#import "KRMesh.h" +#import "KRTexture.h" +#import "KRBone.h" -class KRMaterial; -class KRNode; - - -class KRModel : public KRResource { +class KRModel : public KRNode { public: - KRModel(KRContext &context, std::string name, KRDataBlock *data); - KRModel(KRContext &context, std::string name); + KRModel(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map, float lod_min_coverage, bool receives_shadow, bool faces_camera); virtual ~KRModel(); + virtual std::string getElementName(); + virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent); + + virtual void render(KRCamera *pCamera, std::vector &lights, const KRViewport &viewport, KRNode::RenderPass renderPass); + bool hasTransparency(); - typedef enum { - KRENGINE_ATTRIB_VERTEX = 0, - KRENGINE_ATTRIB_NORMAL, - KRENGINE_ATTRIB_TANGENT, - KRENGINE_ATTRIB_TEXUVA, - KRENGINE_ATTRIB_TEXUVB, - KRENGINE_ATTRIB_BONEINDEXES, - KRENGINE_ATTRIB_BONEWEIGHTS, - KRENGINE_NUM_ATTRIBUTES - } vertex_attrib_t; - typedef enum { - KRENGINE_MODEL_FORMAT_TRIANGLES = 0, - KRENGINE_MODEL_FORMAT_STRIP, - KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES, - KRENGINE_MODEL_FORMAT_INDEXED_STRIP - } model_format_t; + virtual KRAABB getBounds(); - - void render(KRCamera *pCamera, std::vector &lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector &bones); - - std::string m_lodBaseName; - - virtual std::string getExtension(); - virtual bool save(const std::string& path); - virtual bool save(KRDataBlock &data); - - void LoadData(std::vector vertices, std::vector uva, std::vector uvb, std::vector normals, std::vector tangents, std::vector submesh_starts, std::vector submesh_lengths, std::vector material_names, std::vector bone_names, std::vector > bone_indexes, std::vector > 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; - char szMaterialName[KRENGINE_MAX_NAME_LENGTH]; - } Submesh; - - typedef struct { - GLfloat x; - GLfloat y; - GLfloat z; - } KRVector3D; - - typedef struct { - GLfloat u; - GLfloat v; - } TexCoord; - - typedef struct { - KRVector3D vertex; - KRVector3D normal; - KRVector3D tangent; - TexCoord uva; - TexCoord uvb; - } VertexData; - - vector getSubmeshes(); - - typedef struct { - int32_t start_vertex; - int32_t vertex_count; - char szName[KRENGINE_MAX_NAME_LENGTH]; - } pack_material; - - typedef struct { - char szName[KRENGINE_MAX_NAME_LENGTH]; - } pack_bone; - - int getLODCoverage() const; - std::string getLODBaseName() const; - - - static bool lod_sort_predicate(const KRModel *m1, const KRModel *m2); - bool has_vertex_attribute(vertex_attrib_t attribute_type) const; - - int getSubmeshCount() const; - int getVertexCount(int submesh) const; - KRVector3 getVertexPosition(int index) const; - KRVector3 getVertexNormal(int index) const; - KRVector3 getVertexTangent(int index) const; - KRVector2 getVertexUVA(int index) const; - KRVector2 getVertexUVB(int index) const; - int getBoneIndex(int index, int weight_index) const; - float getBoneWeight(int index, int weight_index) const; - - void setVertexPosition(int index, const KRVector3 &v); - void setVertexNormal(int index, const KRVector3 &v); - void setVertexTangent(int index, const KRVector3 & v); - void setVertexUVA(int index, const KRVector2 &v); - void setVertexUVB(int index, const KRVector2 &v); - void setBoneIndex(int index, int weight_index, int bone_index); - void setBoneWeight(int index, int weight_index, float bone_weight); - - static size_t VertexSizeForAttributes(__int32_t vertex_attrib_flags); - static size_t AttributeOffset(__int32_t vertex_attrib, __int32_t vertex_attrib_flags); - - int getBoneCount(); - char *getBoneName(int bone_index); - - - model_format_t getModelFormat() const; - - bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo) const; - bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo) const; - - static int GetLODCoverage(const std::string &name); private: - bool rayCast(const KRVector3 &line_v0, const KRVector3 &dir, int tri_index0, int tri_index1, int tri_index2, KRHitInfo &hitinfo) const; - static bool rayCast(const KRVector3 &line_v0, const KRVector3 &dir, const KRVector3 &tri_v0, const KRVector3 &tri_v1, const KRVector3 &tri_v2, const KRVector3 &tri_n0, const KRVector3 &tri_n1, const KRVector3 &tri_n2, KRHitInfo &hitinfo); - - 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 m_materials; - set m_uniqueMaterials; - - bool m_hasTransparency; + std::vector m_models; + std::map > m_bones; // Outer std::map connects model to set of bones + KRTexture *m_pLightMap; + std::string m_lightMap; + std::string m_model_name; - KRVector3 m_minPoint, m_maxPoint; + float m_min_lod_coverage; + void loadModel(); - KRDataBlock *m_pData; - - - - typedef struct { - char szTag[16]; - 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; - int32_t bone_count; - float minx, miny, minz, maxx, maxy, maxz; // Axis aligned bounding box, in model's coordinate space - unsigned char reserved[452]; // Pad out to 512 bytes - } pack_header; - - vector m_submeshes; - int m_vertex_attribute_offset[KRENGINE_NUM_ATTRIBUTES]; - int m_vertex_size; - void updateAttributeOffsets(); - - - void clearData(); - void clearBuffers(); - - void setName(const std::string name); - void optimize(); - - - - pack_material *getSubmesh(int mesh_index) const; - unsigned char *getVertexData() const; - unsigned char *getVertexData(int index) const; - pack_header *getHeader() const; - pack_bone *getBone(int index); + bool m_receivesShadow; + bool m_faces_camera; }; -#endif // KRMODEL_I \ No newline at end of file +#endif diff --git a/KREngine/KREngine/Classes/KRNode.cpp b/KREngine/KREngine/Classes/KRNode.cpp index 6be044d..738fe71 100644 --- a/KREngine/KREngine/Classes/KRNode.cpp +++ b/KREngine/KREngine/Classes/KRNode.cpp @@ -14,7 +14,7 @@ #import "KRPointLight.h" #import "KRSpotLight.h" #import "KRDirectionalLight.h" -#import "KRInstance.h" +#import "KRModel.h" #import "KRCollider.h" #import "KRParticleSystem.h" #import "KRParticleSystemNewtonian.h" @@ -22,6 +22,7 @@ #import "KRQuaternion.h" #import "KRBone.h" #import "KRAudioSource.h" +#import "KRReverbZone.h" KRNode::KRNode(KRScene &scene, std::string name) : KRContextObject(scene.getContext()) @@ -217,7 +218,7 @@ KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) { new_node = new KRSpotLight(scene, szName); } else if(strcmp(szElementName, "particles_newtonian") == 0) { new_node = new KRParticleSystemNewtonian(scene, szName); - } else if(strcmp(szElementName, "mesh") == 0) { + } else if(strcmp(szElementName, "model") == 0) { float lod_min_coverage = 0.0f; if(e->QueryFloatAttribute("lod_min_coverage", &lod_min_coverage) != tinyxml2::XML_SUCCESS) { lod_min_coverage = 0.0f; @@ -230,13 +231,15 @@ KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) { if(e->QueryBoolAttribute("faces_camera", &faces_camera) != tinyxml2::XML_SUCCESS) { faces_camera = false; } - new_node = new KRInstance(scene, szName, e->Attribute("mesh_name"), e->Attribute("light_map"), lod_min_coverage, receives_shadow, faces_camera); + new_node = new KRModel(scene, szName, e->Attribute("mesh"), e->Attribute("light_map"), lod_min_coverage, receives_shadow, faces_camera); } else if(strcmp(szElementName, "collider") == 0) { - new_node = new KRCollider(scene, szName, e->Attribute("collider_name")); + new_node = new KRCollider(scene, szName, e->Attribute("collider_name"), 65535, 1.0f); } else if(strcmp(szElementName, "bone") == 0) { new_node = new KRBone(scene, szName); } else if(strcmp(szElementName, "audio_source") == 0) { new_node = new KRAudioSource(scene, szName); + } else if(strcmp(szElementName, "reverb_zone") == 0) { + new_node = new KRReverbZone(scene, szName); } if(new_node) { diff --git a/KREngine/KREngine/Classes/KRNode.h b/KREngine/KREngine/Classes/KRNode.h index c2791a9..6fbcf81 100644 --- a/KREngine/KREngine/Classes/KRNode.h +++ b/KREngine/KREngine/Classes/KRNode.h @@ -17,7 +17,7 @@ class KRCamera; class KRShaderManager; -class KRModelManager; +class KRMeshManager; class KRMaterialManager; class KRMat4; class KRTextureManager; diff --git a/KREngine/KREngine/Classes/KROctree.cpp b/KREngine/KREngine/Classes/KROctree.cpp index 1153cc8..18b1045 100644 --- a/KREngine/KREngine/Classes/KROctree.cpp +++ b/KREngine/KREngine/Classes/KROctree.cpp @@ -95,7 +95,7 @@ std::set &KROctree::getOuterSceneNodes() } -bool KROctree::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo) +bool KROctree::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask) { bool hit_found = false; std::vector outer_colliders; @@ -107,26 +107,26 @@ bool KROctree::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hit } } for(std::vector::iterator itr=outer_colliders.begin(); itr != outer_colliders.end(); itr++) { - if((*itr)->lineCast(v0, v1, hitinfo)) hit_found = true; + if((*itr)->lineCast(v0, v1, hitinfo, layer_mask)) hit_found = true; } if(m_pRootNode) { - if(m_pRootNode->lineCast(v0, v1, hitinfo)) hit_found = true; + if(m_pRootNode->lineCast(v0, v1, hitinfo, layer_mask)) hit_found = true; } return hit_found; } -bool KROctree::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo) +bool KROctree::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask) { bool hit_found = false; for(std::set::iterator outer_nodes_itr=m_outerSceneNodes.begin(); outer_nodes_itr != m_outerSceneNodes.end(); outer_nodes_itr++) { KRCollider *collider = dynamic_cast(*outer_nodes_itr); if(collider) { - if(collider->rayCast(v0, dir, hitinfo)) hit_found = true; + if(collider->rayCast(v0, dir, hitinfo, layer_mask)) hit_found = true; } } if(m_pRootNode) { - if(m_pRootNode->lineCast(v0, dir, hitinfo)) hit_found = true; + if(m_pRootNode->lineCast(v0, dir, hitinfo, layer_mask)) hit_found = true; } return hit_found; } diff --git a/KREngine/KREngine/Classes/KROctree.h b/KREngine/KREngine/Classes/KROctree.h index edbb731..9ee9189 100644 --- a/KREngine/KREngine/Classes/KROctree.h +++ b/KREngine/KREngine/Classes/KROctree.h @@ -28,8 +28,8 @@ public: KROctreeNode *getRootNode(); std::set &getOuterSceneNodes(); - bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo); - bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo); + bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); + bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask); private: KROctreeNode *m_pRootNode; diff --git a/KREngine/KREngine/Classes/KROctreeNode.cpp b/KREngine/KREngine/Classes/KROctreeNode.cpp index 0f5ba5d..5928997 100644 --- a/KREngine/KREngine/Classes/KROctreeNode.cpp +++ b/KREngine/KREngine/Classes/KROctreeNode.cpp @@ -173,25 +173,25 @@ std::set &KROctreeNode::getSceneNodes() } -bool KROctreeNode::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo) +bool KROctreeNode::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask) { bool hit_found = false; if(hitinfo.didHit() && v1 != hitinfo.getPosition()) { // Optimization: If we already have a hit, only search for hits that are closer - hit_found = lineCast(v0, hitinfo.getPosition(), hitinfo); + 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); if(collider) { - if(collider->lineCast(v0, v1, hitinfo)) hit_found = true; + if(collider->lineCast(v0, v1, hitinfo, layer_mask)) hit_found = true; } } for(int i=0; i<8; i++) { if(m_children[i]) { - if(m_children[i]->lineCast(v0, v1, hitinfo)) { + if(m_children[i]->lineCast(v0, v1, hitinfo, layer_mask)) { hit_found = true; } } @@ -202,24 +202,24 @@ bool KROctreeNode::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo return hit_found; } -bool KROctreeNode::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo) +bool KROctreeNode::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask) { bool hit_found = false; if(hitinfo.didHit()) { // Optimization: If we already have a hit, only search for hits that are closer - hit_found = lineCast(v0, hitinfo.getPosition(), hitinfo); // Note: This is purposefully lineCast as opposed to RayCast + hit_found = lineCast(v0, hitinfo.getPosition(), hitinfo, layer_mask); // Note: This is purposefully lineCast as opposed to RayCast } else { if(getBounds().intersectsRay(v0, dir)) { for(std::set::iterator nodes_itr=m_sceneNodes.begin(); nodes_itr != m_sceneNodes.end(); nodes_itr++) { KRCollider *collider = dynamic_cast(*nodes_itr); if(collider) { - if(collider->rayCast(v0, dir, hitinfo)) hit_found = true; + if(collider->rayCast(v0, dir, hitinfo, layer_mask)) hit_found = true; } } for(int i=0; i<8; i++) { if(m_children[i]) { - if(m_children[i]->rayCast(v0, dir, hitinfo)) { + if(m_children[i]->rayCast(v0, dir, hitinfo, layer_mask)) { hit_found = true; } } diff --git a/KREngine/KREngine/Classes/KROctreeNode.h b/KREngine/KREngine/Classes/KROctreeNode.h index 43dbb96..6c820d0 100644 --- a/KREngine/KREngine/Classes/KROctreeNode.h +++ b/KREngine/KREngine/Classes/KROctreeNode.h @@ -47,8 +47,8 @@ public: bool m_occlusionTested; bool m_activeQuery; - bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo); - bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo); + bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); + bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask); private: KRAABB m_bounds; diff --git a/KREngine/KREngine/Classes/KRParticleSystemNewtonian.cpp b/KREngine/KREngine/Classes/KRParticleSystemNewtonian.cpp index b4d781c..7f069db 100644 --- a/KREngine/KREngine/Classes/KRParticleSystemNewtonian.cpp +++ b/KREngine/KREngine/Classes/KRParticleSystemNewtonian.cpp @@ -81,7 +81,7 @@ void KRParticleSystemNewtonian::render(KRCamera *pCamera, std::vector 1.0f )); - m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getRandomParticles(), particle_count * 3 * sizeof(KRModelManager::RandomParticleVertexData), true, false, false, true, false, false, false); + m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getRandomParticles(), particle_count * 3 * sizeof(KRMeshManager::RandomParticleVertexData), true, false, false, true, false, false, false); GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, particle_count*3)); } } @@ -109,7 +109,7 @@ void KRParticleSystemNewtonian::render(KRCamera *pCamera, std::vector // 1.0f // )); // -// m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getRandomParticles(), particle_count * 3 * sizeof(KRModelManager::RandomParticleVertexData), true, false, false, true, false); +// m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getRandomParticles(), particle_count * 3 * sizeof(KRMeshManager::RandomParticleVertexData), true, false, false, true, false); // GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, particle_count*3)); // } //// } diff --git a/KREngine/KREngine/Classes/KRPointLight.cpp b/KREngine/KREngine/Classes/KRPointLight.cpp index 70909f8..6e65642 100644 --- a/KREngine/KREngine/Classes/KRPointLight.cpp +++ b/KREngine/KREngine/Classes/KRPointLight.cpp @@ -125,7 +125,7 @@ void KRPointLight::render(KRCamera *pCamera, std::vector &lights, con GLDEBUG(glDepthFunc(GL_LEQUAL)); GLDEBUG(glDepthRangef(0.0, 1.0)); - GLDEBUG(glVertexAttribPointer(KRModel::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, m_sphereVertices)); + GLDEBUG(glVertexAttribPointer(KRMesh::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, m_sphereVertices)); GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, m_cVertices)); } } diff --git a/KREngine/KREngine/Classes/KRPointLight.h b/KREngine/KREngine/Classes/KRPointLight.h index 06a929a..8a91a94 100644 --- a/KREngine/KREngine/Classes/KRPointLight.h +++ b/KREngine/KREngine/Classes/KRPointLight.h @@ -6,8 +6,8 @@ // Copyright (c) 2012 Kearwood Software. All rights reserved. // -#ifndef KREngine_KRPointLight_h -#define KREngine_KRPointLight_h +#ifndef KRPOINTLIGHT_H +#define KRPOINTLIGHT_H #import "KRLight.h" #import "KRMat4.h" diff --git a/KREngine/KREngine/Classes/KRQuaternion.h b/KREngine/KREngine/Classes/KRQuaternion.h index b9c4b27..444dec6 100644 --- a/KREngine/KREngine/Classes/KRQuaternion.h +++ b/KREngine/KREngine/Classes/KRQuaternion.h @@ -29,8 +29,8 @@ // or implied, of Kearwood Gilbert. // -#ifndef KRQUATERNION -#define KRQUATERNION +#ifndef KRQUATERNION_H +#define KRQUATERNION_H #include #import "KREngine-common.h" diff --git a/KREngine/KREngine/Classes/KRResource+blend.h b/KREngine/KREngine/Classes/KRResource+blend.h index a6e8882..4199085 100644 --- a/KREngine/KREngine/Classes/KRResource+blend.h +++ b/KREngine/KREngine/Classes/KRResource+blend.h @@ -6,8 +6,8 @@ // Copyright (c) 2012 Kearwood Software. All rights reserved. // -#ifndef KREngine_KRResource_blend_h -#define KREngine_KRResource_blend_h +#ifndef KRRESOURCE_BLEND_H +#define KRRESOURCE_BLEND_H class KRBlendFile { public: diff --git a/KREngine/KREngine/Classes/KRResource+fbx.cpp b/KREngine/KREngine/Classes/KRResource+fbx.cpp index 9b028fa..d0ea6e3 100644 --- a/KREngine/KREngine/Classes/KRResource+fbx.cpp +++ b/KREngine/KREngine/Classes/KRResource+fbx.cpp @@ -23,7 +23,7 @@ #include "KRResource.h" -#include "KRModel.h" +#include "KRMesh.h" #include "KRMaterial.h" #include "KRLight.h" #include "KRPointLight.h" @@ -34,7 +34,7 @@ #include "KRQuaternion.h" #include "KRBone.h" #include "KRBundle.h" -#include "KRInstance.h" +#include "KRModel.h" #include "KRCollider.h" #ifdef IOS_REF @@ -190,7 +190,7 @@ std::vector KRResource::LoadFbx(KRContext &context, const std::str animation_bundle.append(*resource); // } else if(dynamic_cast(resource) != NULL) { // material_bundle.append(*resource); - } else if(dynamic_cast(resource) != NULL) { + } else if(dynamic_cast(resource) != NULL) { meshes_bundle.append(*resource); } else { main_bundle->append(*resource); @@ -1143,8 +1143,8 @@ void LoadMesh(KRContext &context, std::vector &resources, FbxGeome delete control_point_weights; - KRModel *new_mesh = new KRModel(context, pSourceMesh->GetNode()->GetName()); - 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); + KRMesh *new_mesh = new KRMesh(context, pSourceMesh->GetNode()->GetName()); + new_mesh->LoadData(vertices, uva, uvb, normals, tangents, submesh_starts, submesh_lengths, material_names, bone_names, bone_indexes, bone_weights,KRMesh::KRENGINE_MODEL_FORMAT_TRIANGLES); resources.push_back(new_mesh); } @@ -1153,18 +1153,22 @@ KRNode *LoadMesh(KRNode *parent_node, std::vector &resources, FbxG KFbxMesh* pSourceMesh = (KFbxMesh*) pNode->GetNodeAttribute(); - if(KRModel::GetLODCoverage(pNode->GetName()) == 100) { + if(KRMesh::GetLODCoverage(pNode->GetName()) == 100) { // If this is the full detail model, add an instance of it to the scene file std::string light_map = pNode->GetName(); light_map.append("_lightmap"); - const char *collider_prefix = "collider_"; + // FINDME, HACK - Until we have a GUI, we're using prefixes to select correct object type const char *node_name = pNode->GetName(); - if(strncmp(node_name, collider_prefix, strlen(collider_prefix)) == 0) { - // FINDME, HACK - Until we have a GUI, we're using prefixes to select correct object type - return new KRCollider(parent_node->getScene(), GetFbxObjectName(pNode), pSourceMesh->GetNode()->GetName()); + if(strncmp(node_name, "physics_collider_", strlen("physics_collider_")) == 0) { + return new KRCollider(parent_node->getScene(), GetFbxObjectName(pNode), pSourceMesh->GetNode()->GetName(), KRAKEN_COLLIDER_PHYSICS, 0.0f); + } else if(strncmp(node_name, "audio_collider_", strlen("audio_collider_")) == 0) { + return new KRCollider(parent_node->getScene(), GetFbxObjectName(pNode), pSourceMesh->GetNode()->GetName(), KRAKEN_COLLIDER_AUDIO, 1.0f); + } else if(strncmp(node_name, "collider_", strlen("collider_")) == 0) { + + return new KRCollider(parent_node->getScene(), GetFbxObjectName(pNode), pSourceMesh->GetNode()->GetName(), KRAKEN_COLLIDER_PHYSICS | KRAKEN_COLLIDER_AUDIO, 1.0f); } else { - return new KRInstance(parent_node->getScene(), GetFbxObjectName(pNode), pSourceMesh->GetNode()->GetName(), light_map, 0.0f, true, false); + return new KRModel(parent_node->getScene(), GetFbxObjectName(pNode), pSourceMesh->GetNode()->GetName(), light_map, 0.0f, true, false); } } else { return NULL; diff --git a/KREngine/KREngine/Classes/KRResource+obj.cpp b/KREngine/KREngine/Classes/KRResource+obj.cpp index 8859843..afafda7 100644 --- a/KREngine/KREngine/Classes/KRResource+obj.cpp +++ b/KREngine/KREngine/Classes/KRResource+obj.cpp @@ -17,13 +17,13 @@ #include #include "KRResource.h" -#include "KRModel.h" +#include "KRMesh.h" std::vector KRResource::LoadObj(KRContext &context, const std::string& path) { std::vector resources; - KRModel *new_mesh = new KRModel(context, KRResource::GetFileBase(path)); + KRMesh *new_mesh = new KRMesh(context, KRResource::GetFileBase(path)); resources.push_back(new_mesh); std::vector vertices; std::vector uva; @@ -42,7 +42,7 @@ std::vector KRResource::LoadObj(KRContext &context, const std::str int *pFaces = NULL; - vector m_materials; + vector m_materials; if(data.load(path)) { // -----=====----- Get counts -----=====----- @@ -246,7 +246,7 @@ std::vector KRResource::LoadObj(KRContext &context, const std::str std::vector::iterator material_itr = material_names_t.begin(); - KRModel::pack_material *pMaterial = new KRModel::pack_material(); + KRMesh::pack_material *pMaterial = new KRMesh::pack_material(); pMaterial->start_vertex = iVertex; pMaterial->vertex_count = 0; memset(pMaterial->szName, 256, 0); @@ -311,7 +311,7 @@ std::vector KRResource::LoadObj(KRContext &context, const std::str } pMaterial->vertex_count = iVertex - pMaterial->start_vertex; if(*pFace != 0) { - pMaterial = new KRModel::pack_material(); + pMaterial = new KRMesh::pack_material(); pMaterial->start_vertex = iVertex; pMaterial->vertex_count = 0; memset(pMaterial->szName, 256, 0); @@ -324,7 +324,7 @@ std::vector KRResource::LoadObj(KRContext &context, const std::str } for(int iMaterial=0; iMaterial < m_materials.size(); iMaterial++) { - KRModel::pack_material *pNewMaterial = m_materials[iMaterial]; + KRMesh::pack_material *pNewMaterial = m_materials[iMaterial]; if(pNewMaterial->vertex_count > 0) { material_names.push_back(std::string(pNewMaterial->szName)); submesh_starts.push_back(pNewMaterial->start_vertex); @@ -338,7 +338,7 @@ std::vector KRResource::LoadObj(KRContext &context, const std::str std::vector > bone_indexes; std::vector > 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); + new_mesh->LoadData(vertices, uva, uvb, normals, tangents, submesh_starts, submesh_lengths, material_names, bone_names, bone_indexes, bone_weights, KRMesh::KRENGINE_MODEL_FORMAT_TRIANGLES); } if(pFaces) { diff --git a/KREngine/KREngine/Classes/KRResource.h b/KREngine/KREngine/Classes/KRResource.h index b4f3905..a52e187 100644 --- a/KREngine/KREngine/Classes/KRResource.h +++ b/KREngine/KREngine/Classes/KRResource.h @@ -15,8 +15,8 @@ #import "KRContextObject.h" #import "KRDataBlock.h" -#ifndef KREngine_KRResource_h -#define KREngine_KRResource_h +#ifndef KRRESOURCE_H +#define KRRESOURCE_H class KRResource : public KRContextObject { diff --git a/KREngine/KREngine/Classes/KRReverbZone.cpp b/KREngine/KREngine/Classes/KRReverbZone.cpp new file mode 100644 index 0000000..7831402 --- /dev/null +++ b/KREngine/KREngine/Classes/KRReverbZone.cpp @@ -0,0 +1,134 @@ +// +// KRReverbZone.cpp +// KREngine +// +// Created by Kearwood Gilbert on 2012-12-06. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + +#include "KRReverbZone.h" +#include "KRContext.h" + +KRReverbZone::KRReverbZone(KRScene &scene, std::string name) : KRNode(scene, name) +{ + +} + +KRReverbZone::~KRReverbZone() +{ +} + +std::string KRReverbZone::getElementName() { + return "reverb_zone"; +} + +tinyxml2::XMLElement *KRReverbZone::saveXML( tinyxml2::XMLNode *parent) +{ + tinyxml2::XMLElement *e = KRNode::saveXML(parent); + return e; +} + +void KRReverbZone::loadXML(tinyxml2::XMLElement *e) +{ + KRNode::loadXML(e); +} + +std::string KRReverbZone::getReverbPreset() +{ + return m_reverb_preset_name; +} + +void KRReverbZone::setReverbPreset(const std::string &reverb_preset_name) +{ + m_reverb_preset_name = reverb_preset_name; +} + + +unsigned int KRReverbZone::getReverbSettingId() +{ + if(m_reverb_preset_name.compare("small_room") == 0) { + return ALC_ASA_REVERB_ROOM_TYPE_SmallRoom; + } else if(m_reverb_preset_name.compare("medium_room") == 0) { + return ALC_ASA_REVERB_ROOM_TYPE_MediumRoom; + } else if(m_reverb_preset_name.compare("large_room") == 0) { + return ALC_ASA_REVERB_ROOM_TYPE_LargeRoom; + } else if(m_reverb_preset_name.compare("medium_hall") == 0) { + return ALC_ASA_REVERB_ROOM_TYPE_MediumHall; + } else if(m_reverb_preset_name.compare("large_hall") == 0) { + return ALC_ASA_REVERB_ROOM_TYPE_LargeHall; + } else if(m_reverb_preset_name.compare("plate") == 0) { + return ALC_ASA_REVERB_ROOM_TYPE_Plate; + } else if(m_reverb_preset_name.compare("medium_chamber") == 0) { + return ALC_ASA_REVERB_ROOM_TYPE_MediumChamber; + } else if(m_reverb_preset_name.compare("large_chamber") == 0) { + return ALC_ASA_REVERB_ROOM_TYPE_LargeChamber; + } else if(m_reverb_preset_name.compare("cathedral") == 0) { + return ALC_ASA_REVERB_ROOM_TYPE_Cathedral; + } else if(m_reverb_preset_name.compare("large_room2") == 0) { + return ALC_ASA_REVERB_ROOM_TYPE_LargeRoom2; + } else if(m_reverb_preset_name.compare("medium_hall2") == 0) { + return ALC_ASA_REVERB_ROOM_TYPE_MediumHall2; + } else if(m_reverb_preset_name.compare("medium_hall3") == 0) { + return ALC_ASA_REVERB_ROOM_TYPE_MediumHall3; + } else if(m_reverb_preset_name.compare("large_hall2") == 0) { + return ALC_ASA_REVERB_ROOM_TYPE_LargeHall2; + } else { + return ALC_ASA_REVERB_ROOM_TYPE_SmallRoom; + } +} + +void KRReverbZone::render(KRCamera *pCamera, std::vector &lights, const KRViewport &viewport, KRNode::RenderPass renderPass) +{ + + KRNode::render(pCamera, lights, viewport, renderPass); + + bool bVisualize = false; + + 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 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)); + } + } +} + + +float KRReverbZone::getGradientDistance() +{ + return m_gradient_distance; +} + +void KRReverbZone::setGradientDistance(float gradient_distance) +{ + m_gradient_distance = gradient_distance; +} + +KRAABB KRReverbZone::getBounds() { + // Reverb zones always have a -1, -1, -1 to 1, 1, 1 bounding box + return KRAABB(-KRVector3::One(), KRVector3::One(), getModelMatrix()); +} diff --git a/KREngine/KREngine/Classes/KRReverbZone.h b/KREngine/KREngine/Classes/KRReverbZone.h new file mode 100644 index 0000000..5b47f77 --- /dev/null +++ b/KREngine/KREngine/Classes/KRReverbZone.h @@ -0,0 +1,42 @@ +// +// KRReverbZone.h +// KREngine +// +// Created by Kearwood Gilbert on 2012-12-06. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + +#ifndef KRREVERB_ZONE_H +#define KRREVERB_ZONE_H + +#import "KRResource.h" +#import "KRNode.h" +#import "KRTexture.h" + +class KRReverbZone : public KRNode { +public: + KRReverbZone(KRScene &scene, std::string name); + virtual ~KRReverbZone(); + virtual std::string getElementName(); + virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent); + virtual void loadXML(tinyxml2::XMLElement *e); + + void render(KRCamera *pCamera, std::vector &lights, const KRViewport &viewport, KRNode::RenderPass renderPass); + + float getGradientDistance(); + void setGradientDistance(float gradient_distance); + + std::string getReverbPreset(); + void setReverbPreset(const std::string &reverb_preset_name); + + unsigned int getReverbSettingId(); + + virtual KRAABB getBounds(); + +private: + float m_gradient_distance; + std::string m_reverb_preset_name; +}; + + +#endif diff --git a/KREngine/KREngine/Classes/KRScene.cpp b/KREngine/KREngine/Classes/KRScene.cpp index b4e3c7b..0d8af27 100644 --- a/KREngine/KREngine/Classes/KRScene.cpp +++ b/KREngine/KREngine/Classes/KRScene.cpp @@ -443,12 +443,12 @@ KRAABB KRScene::getRootOctreeBounds() } -bool KRScene::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo) +bool KRScene::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask) { - return m_nodeTree.lineCast(v0, v1, hitinfo); + return m_nodeTree.lineCast(v0, v1, hitinfo, layer_mask); } -bool KRScene::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo) +bool KRScene::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask) { - return m_nodeTree.rayCast(v0, dir, hitinfo); + return m_nodeTree.rayCast(v0, dir, hitinfo, layer_mask); } diff --git a/KREngine/KREngine/Classes/KRScene.h b/KREngine/KREngine/Classes/KRScene.h index a8a6313..457d968 100644 --- a/KREngine/KREngine/Classes/KRScene.h +++ b/KREngine/KREngine/Classes/KRScene.h @@ -35,14 +35,14 @@ #import "KREngine-common.h" #import -#import "KRInstance.h" -#import "KRMat4.h" #import "KRModel.h" +#import "KRMat4.h" +#import "KRMesh.h" #import "KRCamera.h" -#import "KRModelManager.h" +#import "KRMeshManager.h" #import "KRNode.h" #import "KROctree.h" -class KRInstance; +class KRModel; class KRLight; using std::vector; @@ -62,8 +62,8 @@ public: KRNode *getRootNode(); KRLight *getFirstLight(); - bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo); - bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo); + bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); + bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask); void renderFrame(float deltaTime); void render(KRCamera *pCamera, std::map &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame); diff --git a/KREngine/KREngine/Classes/KRShader.cpp b/KREngine/KREngine/Classes/KRShader.cpp index cf4207d..456a9d7 100644 --- a/KREngine/KREngine/Classes/KRShader.cpp +++ b/KREngine/KREngine/Classes/KRShader.cpp @@ -156,13 +156,13 @@ KRShader::KRShader(KRContext &context, char *szKey, std::string options, std::st // Bind attribute locations. // This needs to be done prior to linking. - GLDEBUG(glBindAttribLocation(m_iProgram, KRModel::KRENGINE_ATTRIB_VERTEX, "vertex_position")); - GLDEBUG(glBindAttribLocation(m_iProgram, KRModel::KRENGINE_ATTRIB_NORMAL, "vertex_normal")); - GLDEBUG(glBindAttribLocation(m_iProgram, KRModel::KRENGINE_ATTRIB_TANGENT, "vertex_tangent")); - GLDEBUG(glBindAttribLocation(m_iProgram, KRModel::KRENGINE_ATTRIB_TEXUVA, "vertex_uv")); - GLDEBUG(glBindAttribLocation(m_iProgram, KRModel::KRENGINE_ATTRIB_TEXUVB, "vertex_lightmap_uv")); - GLDEBUG(glBindAttribLocation(m_iProgram, KRModel::KRENGINE_ATTRIB_BONEINDEXES, "bone_indexes")); - GLDEBUG(glBindAttribLocation(m_iProgram, KRModel::KRENGINE_ATTRIB_BONEWEIGHTS, "bone_weights")); + GLDEBUG(glBindAttribLocation(m_iProgram, KRMesh::KRENGINE_ATTRIB_VERTEX, "vertex_position")); + GLDEBUG(glBindAttribLocation(m_iProgram, KRMesh::KRENGINE_ATTRIB_NORMAL, "vertex_normal")); + GLDEBUG(glBindAttribLocation(m_iProgram, KRMesh::KRENGINE_ATTRIB_TANGENT, "vertex_tangent")); + GLDEBUG(glBindAttribLocation(m_iProgram, KRMesh::KRENGINE_ATTRIB_TEXUVA, "vertex_uv")); + GLDEBUG(glBindAttribLocation(m_iProgram, KRMesh::KRENGINE_ATTRIB_TEXUVB, "vertex_lightmap_uv")); + GLDEBUG(glBindAttribLocation(m_iProgram, KRMesh::KRENGINE_ATTRIB_BONEINDEXES, "bone_indexes")); + GLDEBUG(glBindAttribLocation(m_iProgram, KRMesh::KRENGINE_ATTRIB_BONEWEIGHTS, "bone_weights")); // Link program. GLDEBUG(glLinkProgram(m_iProgram));