diff --git a/Documentation/ScriptingAPI-Documentation.md b/Documentation/ScriptingAPI-Documentation.md index 83b734070..384261a0a 100644 --- a/Documentation/ScriptingAPI-Documentation.md +++ b/Documentation/ScriptingAPI-Documentation.md @@ -115,10 +115,10 @@ You can use the Renderer with the following functions, all of which are in the g - GetRenderWidth() : float result - GetRenderHeight(): float result - GetCameras() : string result -- GetCamera(opt String name) : Camera result // If string is provided, it will search a camera by name, otherwise, returns the main camera -- LoadModel(string fileName, opt string identifier, opt Matrix transform) : Model? result -- LoadWorldInfo(string fileName) -- FinishLoading() +- GetCamera(opt String name) : Camera result -- If string is provided, it will search a camera by name, otherwise, returns the main camera +- LoadModel(string fileName, opt Matrix transform) : Model? result -- Returns the model that was loaded +- LoadWorldInfo(string fileName) -- Loads world information from file +- DuplicateInstance(Object object) : Object result -- Copies the specified object in the scene as an instanced mesh - SetEnvironmentMap(Texture cubemap) - SetColorGrading(Texture texture2D) - HairParticleSettings(opt int lod0, opt int lod1, opt int lod2) @@ -132,7 +132,7 @@ You can use the Renderer with the following functions, all of which are in the g - SetVSyncEnabled(opt bool enabled) - SetOcclusionCullingEnabled(bool enabled) - SetPhysicsParams(opt bool rigidBodyPhysicsEnabled, opt bool softBodyPhysicsEnabled, opt int softBodyIterationCount) -- Pick(Ray ray, opt PICKTYPE pickType, opt uint layerMask) : Object? object, Vector position,normal, float distance +- Pick(Ray ray, opt PICKTYPE pickType, opt uint layerMask) : Object? object, Vector position,normal, float distance -- Perform ray-picking in the scene. pickType is a bitmask specifying object types to check against. layerMask is a bitmask specifying which layers to check against - DrawLine(Vector origin,end, opt Vector color) - PutWaterRipple(String imagename, Vector position) - PutDecal(Decal decal) @@ -472,6 +472,8 @@ A RenderableComponent describes a scene wich can render itself. - Compose() - OnStart(string task) - OnStop(string task) +- GetLayerMask() : uint result +- SetLayerMask(uint mask) #### Renderable2DComponent It can hold Sprites and Fonts and can sort them by layers, update and render them. diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 773a48cc8..a3423d0a7 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -1348,7 +1348,6 @@ void EditorComponent::Update(float dt) if (x->object != nullptr) { Object* o = new Object(*x->object); - o->detach(); wiRenderer::Add(o); x->transform = o; x->object = o; @@ -1356,7 +1355,6 @@ void EditorComponent::Update(float dt) if (x->light != nullptr) { Light* l = new Light(*x->light); - l->detach(); wiRenderer::Add(l); x->transform = l; x->light = l; @@ -1364,7 +1362,6 @@ void EditorComponent::Update(float dt) if (x->forceField != nullptr) { ForceField* l = new ForceField(*x->forceField); - l->detach(); wiRenderer::Add(l); x->transform = l; x->forceField = l; @@ -1372,7 +1369,6 @@ void EditorComponent::Update(float dt) if (x->camera != nullptr) { Camera* l = new Camera(*x->camera); - l->detach(); wiRenderer::Add(l); x->transform = l; x->camera = l; diff --git a/Editor/startup.lua b/Editor/startup.lua index f9b498dee..e6f5f9514 100644 --- a/Editor/startup.lua +++ b/Editor/startup.lua @@ -39,7 +39,6 @@ runProcess(function() if(input.Press(VK_F10)) then s = SoundEffect("C:\\PROJECTS\\DXProject\\DXProject\\sound\\1.wav") s.Play() - --PutEnvProbe(GetCamera().GetPosition(),256); end if(input.Press(VK_F4)) then @@ -53,13 +52,12 @@ runProcess(function() end if(input.Press(VK_F7)) then - -- LoadModel("C:\\PROJECTS\\WickedEngine\\WickedEngine\\Scene\\Sponza\\","sponza"); runProcess(function() local row = 16 for i = 1, row do for j = 1, row do - LoadModel("C:\\PROJECTS\\BLENDER\\Stormtrooper\\Stormtrooper.wimf", "_"..i..j,matrix.Translation(Vector(i*2-row,0,j*2-row))); - --waitSeconds(0.05) + LoadModel("../models/Stormtrooper/model.wimf",matrix.Translation(Vector(i*2-row,0,j*2-row))); + waitSeconds(0.05) end end end) diff --git a/WickedEngine/DeferredRenderableComponent.cpp b/WickedEngine/DeferredRenderableComponent.cpp index 05206ec6e..80dc9e0ee 100644 --- a/WickedEngine/DeferredRenderableComponent.cpp +++ b/WickedEngine/DeferredRenderableComponent.cpp @@ -126,7 +126,7 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) rtGBuffer.Activate(threadID, 0, 0, 0, 0); { wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); - wiRenderer::DrawWorld(wiRenderer::getCamera(), getTessellationEnabled(), threadID, SHADERTYPE_DEFERRED, getHairParticlesEnabled(), true); + wiRenderer::DrawWorld(wiRenderer::getCamera(), getTessellationEnabled(), threadID, SHADERTYPE_DEFERRED, getHairParticlesEnabled(), true, getLayerMask()); } wiRenderer::GetDevice()->TransitionBarrier(dsv, ARRAYSIZE(dsv), RESOURCE_STATE_DEPTH_WRITE, RESOURCE_STATE_COPY_SOURCE, threadID); diff --git a/WickedEngine/DeferredRenderableComponent_BindLua.cpp b/WickedEngine/DeferredRenderableComponent_BindLua.cpp index f2781d39a..79f5fc180 100644 --- a/WickedEngine/DeferredRenderableComponent_BindLua.cpp +++ b/WickedEngine/DeferredRenderableComponent_BindLua.cpp @@ -30,6 +30,8 @@ Luna::FunctionType DeferredRenderableCompon lunamethod(RenderableComponent_BindLua, Compose), lunamethod(RenderableComponent_BindLua, OnStart), lunamethod(RenderableComponent_BindLua, OnStop), + lunamethod(RenderableComponent_BindLua, GetLayerMask), + lunamethod(RenderableComponent_BindLua, SetLayerMask), lunamethod(Renderable3DComponent_BindLua, SetSSAOEnabled), lunamethod(Renderable3DComponent_BindLua, SetSSREnabled), diff --git a/WickedEngine/ForwardRenderableComponent.cpp b/WickedEngine/ForwardRenderableComponent.cpp index f77c53ffd..dfaa3ec80 100644 --- a/WickedEngine/ForwardRenderableComponent.cpp +++ b/WickedEngine/ForwardRenderableComponent.cpp @@ -113,7 +113,7 @@ void ForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); wiRenderer::GetDevice()->BindResource(PS, getSSAOEnabled() ? rtSSAO.back().GetTexture() : wiTextureHelper::getInstance()->getWhite(), TEXSLOT_RENDERABLECOMPONENT_SSAO, threadID); wiRenderer::GetDevice()->BindResource(PS, getSSREnabled() ? rtSSR.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_SSR, threadID); - wiRenderer::DrawWorld(wiRenderer::getCamera(), getTessellationEnabled(), threadID, SHADERTYPE_FORWARD, getHairParticlesEnabled(), true); + wiRenderer::DrawWorld(wiRenderer::getCamera(), getTessellationEnabled(), threadID, SHADERTYPE_FORWARD, getHairParticlesEnabled(), true, getLayerMask()); wiRenderer::DrawSky(threadID); } rtMain.Deactivate(threadID); diff --git a/WickedEngine/ForwardRenderableComponent_BindLua.cpp b/WickedEngine/ForwardRenderableComponent_BindLua.cpp index f19f13a8f..cb6766248 100644 --- a/WickedEngine/ForwardRenderableComponent_BindLua.cpp +++ b/WickedEngine/ForwardRenderableComponent_BindLua.cpp @@ -30,6 +30,8 @@ Luna::FunctionType ForwardRenderableComponen lunamethod(RenderableComponent_BindLua, Compose), lunamethod(RenderableComponent_BindLua, OnStart), lunamethod(RenderableComponent_BindLua, OnStop), + lunamethod(RenderableComponent_BindLua, GetLayerMask), + lunamethod(RenderableComponent_BindLua, SetLayerMask), lunamethod(Renderable3DComponent_BindLua, SetSSAOEnabled), lunamethod(Renderable3DComponent_BindLua, SetSSREnabled), diff --git a/WickedEngine/LoadingScreenComponent_BindLua.cpp b/WickedEngine/LoadingScreenComponent_BindLua.cpp index 221d763d8..e0afbc8bd 100644 --- a/WickedEngine/LoadingScreenComponent_BindLua.cpp +++ b/WickedEngine/LoadingScreenComponent_BindLua.cpp @@ -30,6 +30,8 @@ Luna::FunctionType LoadingScreenComponent_BindLu lunamethod(LoadingScreenComponent_BindLua, Compose), lunamethod(RenderableComponent_BindLua, OnStart), lunamethod(RenderableComponent_BindLua, OnStop), + lunamethod(RenderableComponent_BindLua, GetLayerMask), + lunamethod(RenderableComponent_BindLua, SetLayerMask), lunamethod(LoadingScreenComponent_BindLua, AddLoadingTask), lunamethod(LoadingScreenComponent_BindLua, OnFinished), diff --git a/WickedEngine/Renderable2DComponent_BindLua.cpp b/WickedEngine/Renderable2DComponent_BindLua.cpp index bbec8cfb4..555b630c5 100644 --- a/WickedEngine/Renderable2DComponent_BindLua.cpp +++ b/WickedEngine/Renderable2DComponent_BindLua.cpp @@ -35,6 +35,8 @@ Luna::FunctionType Renderable2DComponent_BindLua: lunamethod(Renderable2DComponent_BindLua, Compose), lunamethod(RenderableComponent_BindLua, OnStart), lunamethod(RenderableComponent_BindLua, OnStop), + lunamethod(RenderableComponent_BindLua, GetLayerMask), + lunamethod(RenderableComponent_BindLua, SetLayerMask), { NULL, NULL } }; Luna::PropertyType Renderable2DComponent_BindLua::properties[] = { diff --git a/WickedEngine/Renderable3DComponent.cpp b/WickedEngine/Renderable3DComponent.cpp index 9fcc7b64d..ab6a4262d 100644 --- a/WickedEngine/Renderable3DComponent.cpp +++ b/WickedEngine/Renderable3DComponent.cpp @@ -294,7 +294,7 @@ void Renderable3DComponent::RenderReflections(GRAPHICSTHREAD threadID) wiRenderer::SetClipPlane(water, threadID); - wiRenderer::DrawWorld(wiRenderer::getRefCamera(), false, threadID, SHADERTYPE_TEXTURE, getHairParticlesReflectionEnabled(), false); + wiRenderer::DrawWorld(wiRenderer::getRefCamera(), false, threadID, SHADERTYPE_TEXTURE, getHairParticlesReflectionEnabled(), false, getLayerMask()); wiRenderer::DrawSky(threadID); wiRenderer::SetClipPlane(XMFLOAT4(0, 0, 0, 0), threadID); @@ -313,7 +313,7 @@ void Renderable3DComponent::RenderShadows(GRAPHICSTHREAD threadID) if (getShadowsEnabled()) { - wiRenderer::DrawForShadowMap(threadID); + wiRenderer::DrawForShadowMap(threadID, getLayerMask()); } wiRenderer::VoxelRadiance(threadID); @@ -500,7 +500,7 @@ void Renderable3DComponent::RenderTransparentScene(wiRenderTarget& refractionRT, wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); wiRenderer::GetDevice()->BindResource(PS, refractionRT.GetTexture(), TEXSLOT_RENDERABLECOMPONENT_REFRACTION, threadID); wiRenderer::GetDevice()->BindResource(PS, rtWaterRipple.GetTexture(), TEXSLOT_RENDERABLECOMPONENT_WATERRIPPLES, threadID); - wiRenderer::DrawWorldTransparent(wiRenderer::getCamera(), SHADERTYPE_FORWARD, threadID, false, true); + wiRenderer::DrawWorldTransparent(wiRenderer::getCamera(), SHADERTYPE_FORWARD, threadID, false, true, getLayerMask()); wiProfiler::GetInstance().EndRange(threadID); // Transparent Scene } diff --git a/WickedEngine/Renderable3DComponent.h b/WickedEngine/Renderable3DComponent.h index abe517c81..436f1d4e2 100644 --- a/WickedEngine/Renderable3DComponent.h +++ b/WickedEngine/Renderable3DComponent.h @@ -46,7 +46,6 @@ private: UINT msaaSampleCount; - protected: static wiRenderTarget rtReflection @@ -154,6 +153,7 @@ public: inline void setMSAASampleCount(UINT value) { msaaSampleCount = value; ResizeBuffers(); } + virtual void setPreferredThreadingCount(unsigned short value); void setProperties(); diff --git a/WickedEngine/Renderable3DComponent_BindLua.cpp b/WickedEngine/Renderable3DComponent_BindLua.cpp index 87fa6e49e..5fea6439a 100644 --- a/WickedEngine/Renderable3DComponent_BindLua.cpp +++ b/WickedEngine/Renderable3DComponent_BindLua.cpp @@ -31,6 +31,8 @@ Luna::FunctionType Renderable3DComponent_BindLua: lunamethod(Renderable3DComponent_BindLua, Compose), lunamethod(RenderableComponent_BindLua, OnStart), lunamethod(RenderableComponent_BindLua, OnStop), + lunamethod(RenderableComponent_BindLua, GetLayerMask), + lunamethod(RenderableComponent_BindLua, SetLayerMask), lunamethod(Renderable3DComponent_BindLua, SetSSAOEnabled), lunamethod(Renderable3DComponent_BindLua, SetSSREnabled), diff --git a/WickedEngine/RenderableComponent.h b/WickedEngine/RenderableComponent.h index 61a8ee9ef..8a1e7ce3f 100644 --- a/WickedEngine/RenderableComponent.h +++ b/WickedEngine/RenderableComponent.h @@ -7,6 +7,8 @@ class RenderableComponent { +private: + uint32_t layerMask = 0xFFFFFFFF; protected: // create resolution dependant resources virtual void ResizeBuffers() {} @@ -40,5 +42,9 @@ public: // Compose the rendered layers (for example blend the layers together as Images) // This will be rendered to the backbuffer virtual void Compose() {} + + + inline uint32_t getLayerMask() { return layerMask; } + inline void setlayerMask(uint32_t value) { layerMask = value; } }; diff --git a/WickedEngine/RenderableComponent_BindLua.cpp b/WickedEngine/RenderableComponent_BindLua.cpp index d27ac8c71..252d508dc 100644 --- a/WickedEngine/RenderableComponent_BindLua.cpp +++ b/WickedEngine/RenderableComponent_BindLua.cpp @@ -18,6 +18,8 @@ Luna::FunctionType RenderableComponent_BindLua::met lunamethod(RenderableComponent_BindLua, Compose), lunamethod(RenderableComponent_BindLua, OnStart), lunamethod(RenderableComponent_BindLua, OnStop), + lunamethod(RenderableComponent_BindLua, GetLayerMask), + lunamethod(RenderableComponent_BindLua, SetLayerMask), { NULL, NULL } }; Luna::PropertyType RenderableComponent_BindLua::properties[] = { @@ -179,6 +181,26 @@ int RenderableComponent_BindLua::OnStop(lua_State* L) return 0; } + +int RenderableComponent_BindLua::GetLayerMask(lua_State* L) +{ + uint32_t mask = component->getLayerMask(); + wiLua::SSetInt(L, *reinterpret_cast(&mask)); + return 1; +} +int RenderableComponent_BindLua::SetLayerMask(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + int mask = wiLua::SGetInt(L, 1); + component->setlayerMask(*reinterpret_cast(&mask)); + } + else + wiLua::SError(L, "SetLayerMask(uint mask) not enough arguments!"); + return 0; +} + void RenderableComponent_BindLua::Bind() { diff --git a/WickedEngine/RenderableComponent_BindLua.h b/WickedEngine/RenderableComponent_BindLua.h index f0e3a725d..60b9d9ef7 100644 --- a/WickedEngine/RenderableComponent_BindLua.h +++ b/WickedEngine/RenderableComponent_BindLua.h @@ -30,6 +30,9 @@ public: virtual int OnStart(lua_State* L); virtual int OnStop(lua_State* L); + virtual int GetLayerMask(lua_State* L); + virtual int SetLayerMask(lua_State* L); + static void Bind(); }; diff --git a/WickedEngine/TiledDeferredRenderableComponent.cpp b/WickedEngine/TiledDeferredRenderableComponent.cpp index 9e752da9a..e9fad51ea 100644 --- a/WickedEngine/TiledDeferredRenderableComponent.cpp +++ b/WickedEngine/TiledDeferredRenderableComponent.cpp @@ -37,7 +37,7 @@ void TiledDeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) rtGBuffer.Activate(threadID, 0, 0, 0, 0); { wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); - wiRenderer::DrawWorld(wiRenderer::getCamera(), getTessellationEnabled(), threadID, SHADERTYPE_DEFERRED, getHairParticlesEnabled(), true); + wiRenderer::DrawWorld(wiRenderer::getCamera(), getTessellationEnabled(), threadID, SHADERTYPE_DEFERRED, getHairParticlesEnabled(), true, getLayerMask()); } @@ -200,7 +200,7 @@ void TiledDeferredRenderableComponent::RenderTransparentScene(wiRenderTarget& re wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); wiRenderer::GetDevice()->BindResource(PS, refractionRT.GetTexture(), TEXSLOT_RENDERABLECOMPONENT_REFRACTION, threadID); wiRenderer::GetDevice()->BindResource(PS, rtWaterRipple.GetTexture(), TEXSLOT_RENDERABLECOMPONENT_WATERRIPPLES, threadID); - wiRenderer::DrawWorldTransparent(wiRenderer::getCamera(), SHADERTYPE_TILEDFORWARD, threadID, getHairParticlesEnabled(), true); + wiRenderer::DrawWorldTransparent(wiRenderer::getCamera(), SHADERTYPE_TILEDFORWARD, threadID, getHairParticlesEnabled(), true, getLayerMask()); wiProfiler::GetInstance().EndRange(); // Transparent Scene } diff --git a/WickedEngine/TiledDeferredRenderableComponent_BindLua.cpp b/WickedEngine/TiledDeferredRenderableComponent_BindLua.cpp index 3ba6ac588..4592cb048 100644 --- a/WickedEngine/TiledDeferredRenderableComponent_BindLua.cpp +++ b/WickedEngine/TiledDeferredRenderableComponent_BindLua.cpp @@ -30,6 +30,8 @@ Luna::FunctionType TiledDeferredRender lunamethod(RenderableComponent_BindLua, Compose), lunamethod(RenderableComponent_BindLua, OnStart), lunamethod(RenderableComponent_BindLua, OnStop), + lunamethod(RenderableComponent_BindLua, GetLayerMask), + lunamethod(RenderableComponent_BindLua, SetLayerMask), lunamethod(Renderable3DComponent_BindLua, SetSSAOEnabled), lunamethod(Renderable3DComponent_BindLua, SetSSREnabled), diff --git a/WickedEngine/TiledForwardRenderableComponent.cpp b/WickedEngine/TiledForwardRenderableComponent.cpp index 55eb8c3c1..15c8f0e52 100644 --- a/WickedEngine/TiledForwardRenderableComponent.cpp +++ b/WickedEngine/TiledForwardRenderableComponent.cpp @@ -28,7 +28,7 @@ void TiledForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) wiProfiler::GetInstance().BeginRange("Z-Prepass", wiProfiler::DOMAIN_GPU, threadID); rtMain.Activate(threadID, 0, 0, 0, 0, true); // depth prepass { - wiRenderer::DrawWorld(wiRenderer::getCamera(), getTessellationEnabled(), threadID, SHADERTYPE_DEPTHONLY, getHairParticlesEnabled(), true); + wiRenderer::DrawWorld(wiRenderer::getCamera(), getTessellationEnabled(), threadID, SHADERTYPE_DEPTHONLY, getHairParticlesEnabled(), true, getLayerMask()); } wiProfiler::GetInstance().EndRange(threadID); diff --git a/WickedEngine/TiledForwardRenderableComponent_BindLua.cpp b/WickedEngine/TiledForwardRenderableComponent_BindLua.cpp index f4533ec32..e6baa6987 100644 --- a/WickedEngine/TiledForwardRenderableComponent_BindLua.cpp +++ b/WickedEngine/TiledForwardRenderableComponent_BindLua.cpp @@ -30,6 +30,8 @@ Luna::FunctionType TiledForwardRenderab lunamethod(RenderableComponent_BindLua, Compose), lunamethod(RenderableComponent_BindLua, OnStart), lunamethod(RenderableComponent_BindLua, OnStop), + lunamethod(RenderableComponent_BindLua, GetLayerMask), + lunamethod(RenderableComponent_BindLua, SetLayerMask), lunamethod(Renderable3DComponent_BindLua, SetSSAOEnabled), lunamethod(Renderable3DComponent_BindLua, SetSSREnabled), diff --git a/WickedEngine/wiLoader.cpp b/WickedEngine/wiLoader.cpp index 74ef10aae..a822b68c3 100644 --- a/WickedEngine/wiLoader.cpp +++ b/WickedEngine/wiLoader.cpp @@ -25,7 +25,7 @@ using namespace std; using namespace wiGraphicsTypes; -void LoadWiArmatures(const std::string& directory, const std::string& name, const std::string& identifier, unordered_set& armatures) +void LoadWiArmatures(const std::string& directory, const std::string& name, unordered_set& armatures) { stringstream filename(""); filename<>line; if(line[0]=='/' && line.substr(2,8)=="ARMATURE") { - armature = new Armature(line.substr(11, strlen(line.c_str()) - 11), identifier); + armature = new Armature(line.substr(11, strlen(line.c_str()) - 11)); armatures.insert(armature); } else @@ -114,30 +114,7 @@ void LoadWiArmatures(const std::string& directory, const std::string& name, cons } } -void RecursiveRest(Armature* armature, Bone* bone){ - Bone* parent = (Bone*)bone->parent; - - if(parent!=nullptr){ - XMMATRIX recRest = - XMLoadFloat4x4(&bone->world_rest) - * - XMLoadFloat4x4(&parent->recursiveRest) - //* - //XMLoadFloat4x4(&armature->boneCollection[boneI].rest) - ; - XMStoreFloat4x4( &bone->recursiveRest, recRest ); - XMStoreFloat4x4( &bone->recursiveRestInv, XMMatrixInverse(0,recRest) ); - } - else{ - bone->recursiveRest = bone->world_rest ; - XMStoreFloat4x4( &bone->recursiveRestInv, XMMatrixInverse(0,XMLoadFloat4x4(&bone->recursiveRest)) ); - } - - for (unsigned int i = 0; ichildrenI.size(); ++i){ - RecursiveRest(armature,bone->childrenI[i]); - } -} -void LoadWiMaterialLibrary(const std::string& directory, const std::string& name, const std::string& identifier, const std::string& texturesDir,MaterialCollection& materials) +void LoadWiMaterialLibrary(const std::string& directory, const std::string& name, const std::string& texturesDir,MaterialCollection& materials) { int materialI=(int)(materials.size()-1); @@ -158,9 +135,7 @@ void LoadWiMaterialLibrary(const std::string& directory, const std::string& name materials.insert(pair(currentMat->name, currentMat)); } - stringstream identified_name(""); - identified_name<& objects +void LoadWiObjects(const std::string& directory, const std::string& name, unordered_set& objects , unordered_set& armatures , MeshCollection& meshes, const MaterialCollection& materials) { @@ -306,9 +281,7 @@ void LoadWiObjects(const std::string& directory, const std::string& name, const file>>line; if(line[0]=='/' && !strcmp(line.substr(2,6).c_str(),"OBJECT")) { - stringstream identified_name(""); - identified_name<>meshName; - stringstream identified_mesh(""); - identified_mesh<meshName = identified_mesh.str(); - MeshCollection::iterator iter = meshes.find(identified_mesh.str()); + object->meshName = meshName; + MeshCollection::iterator iter = meshes.find(meshName); if(line[1]=='b') { @@ -330,11 +301,11 @@ void LoadWiObjects(const std::string& directory, const std::string& name, const if(iter==meshes.end()) { stringstream meshFileName(""); - meshFileName<LoadFromFile(identified_mesh.str(),meshFileName.str(),materials,armatures,identifier); - object->mesh=mesh; - meshes.insert(pair(identified_mesh.str(),mesh)); + mesh->LoadFromFile(meshName, meshFileName.str(), materials, armatures); + object->mesh = mesh; + meshes.insert(pair(meshName, mesh)); } else { @@ -352,18 +323,12 @@ void LoadWiObjects(const std::string& directory, const std::string& name, const break; case 'p': { - string parentName=""; - file>>parentName; - stringstream identified_parentName(""); - identified_parentName<parentName = identified_parentName.str(); + file >> object->parentName; } break; case 'b': { - string bone=""; - file>>bone; - object->boneParent = bone; + file >> object->boneParent; } break; case 'I': @@ -400,17 +365,11 @@ void LoadWiObjects(const std::string& directory, const std::string& name, const file>>systemName>>visibleEmitter>>materialName>>size>>randfac>>norfac>>count>>life>>randlife; file>>scaleX>>scaleY>>rot; - if(wiRenderer::EMITTERSENABLED){ - stringstream identified_materialName(""); - identified_materialName<mesh) - { - object->eParticleSystems.push_back( - new wiEmittedParticle(identified_systemName.str(),identified_materialName.str(),object,size,randfac,norfac,count,life,randlife,scaleX,scaleY,rot) - ); - } + if (object->mesh) + { + object->eParticleSystems.push_back( + new wiEmittedParticle(systemName, materialName, object, size, randfac, norfac, count, life, randlife, scaleX, scaleY, rot) + ); } } break; @@ -421,11 +380,7 @@ void LoadWiObjects(const std::string& directory, const std::string& name, const int count; file>>name>>mat>>len>>count>>densityG>>lenG; - if(wiRenderer::HAIRPARTICLEENABLED){ - stringstream identified_materialName(""); - identified_materialName<hParticleSystems.push_back(new wiHairParticle(name,len,count,identified_materialName.str(),object,densityG,lenG) ); - } + object->hParticleSystems.push_back(new wiHairParticle(name, len, count, mat, object, densityG, lenG)); } break; case 'P': @@ -445,7 +400,7 @@ void LoadWiObjects(const std::string& directory, const std::string& name, const file.close(); } -void LoadWiMeshes(const std::string& directory, const std::string& name, const std::string& identifier, MeshCollection& meshes, +void LoadWiMeshes(const std::string& directory, const std::string& name, MeshCollection& meshes, const unordered_set& armatures, const MaterialCollection& materials) { int meshI=(int)(meshes.size()-1); @@ -462,9 +417,7 @@ void LoadWiMeshes(const std::string& directory, const std::string& name, const s string line=""; file>>line; if(line[0]=='/' && !line.substr(2,4).compare("MESH")) { - stringstream identified_name(""); - identified_name<(currentMesh->name,currentMesh) ); meshI++; } @@ -474,12 +427,7 @@ void LoadWiMeshes(const std::string& directory, const std::string& name, const s { case 'p': { - string parentArmature=""; - file>>parentArmature; - - stringstream identified_parentArmature(""); - identified_parentArmature<parent=identified_parentArmature.str(); + file >> currentMesh->parent; for (auto& a : armatures) { if (!a->name.compare(currentMesh->parent)) @@ -611,15 +559,12 @@ void LoadWiMeshes(const std::string& directory, const std::string& name, const s { string mName=""; file>>mName; - stringstream identified_material(""); - identified_material<materialNames.push_back(identified_material.str()); - MaterialCollection::const_iterator iter = materials.find(identified_material.str()); + currentMesh->materialNames.push_back(mName); + MaterialCollection::const_iterator iter = materials.find(mName); if(iter!=materials.end()) { currentMesh->subsets.push_back(MeshSubset()); currentMesh->renderable=true; currentMesh->subsets.back().material = (iter->second); - //currentMesh->materialIndices.push_back(currentMesh->materials.size()); //CONNECT meshes WITH MATERIALS } } break; @@ -671,7 +616,7 @@ void LoadWiMeshes(const std::string& directory, const std::string& name, const s meshes.insert( pair(currentMesh->name,currentMesh) ); } -void LoadWiActions(const std::string& directory, const std::string& name, const std::string& identifier, unordered_set& armatures) +void LoadWiActions(const std::string& directory, const std::string& name, unordered_set& armatures) { Armature* armatureI=nullptr; Bone* boneI=nullptr; @@ -686,14 +631,7 @@ void LoadWiActions(const std::string& directory, const std::string& name, const string line=""; file>>line; if(line[0]=='/' && !strcmp(line.substr(2,8).c_str(),"ARMATURE")) { - stringstream identified_name(""); - identified_name<name.compare(armaturename)){ - // armatureI=i; - // break; - // } + string armaturename = line.substr(11, strlen(line.c_str()) - 11); for (auto& a : armatures) { if (!a->name.compare(armaturename)) { @@ -715,12 +653,6 @@ void LoadWiActions(const std::string& directory, const std::string& name, const { string boneName; file>>boneName; - //for (unsigned int i = 0; iboneCollection.size(); i++) - // if(!armatures[armatureI]->boneCollection[i]->name.compare(boneName)){ - // boneI=i; - // break; - // } //GOT BONE INDEX - //armatures[armatureI]->boneCollection[boneI]->actionFrames.resize(armatures[armatureI]->actions.size()); boneI = armatureI->GetBone(boneName); if (boneI != nullptr) { @@ -762,7 +694,7 @@ void LoadWiActions(const std::string& directory, const std::string& name, const } file.close(); } -void LoadWiLights(const std::string& directory, const std::string& name, const std::string& identifier, unordered_set& lights) +void LoadWiLights(const std::string& directory, const std::string& name, unordered_set& lights) { stringstream filename(""); @@ -783,11 +715,7 @@ void LoadWiLights(const std::string& directory, const std::string& name, const s light = new Light(); lights.insert(light); light->SetType(Light::POINT); - string lname = ""; - file>>lname>> light->shadow; - stringstream identified_name(""); - identified_name<name=identified_name.str(); + file >> light->name >> light->shadow; } break; case 'D': @@ -810,19 +738,12 @@ void LoadWiLights(const std::string& directory, const std::string& name, const s break; case 'p': { - string parentName=""; - file>>parentName; - - stringstream identified_parentName(""); - identified_parentName<parentName=identified_parentName.str(); + file >> light->parentName; } break; case 'b': { - string parentBone=""; - file>>parentBone; - light->boneParent = parentBone; + file >> light->boneParent; } break; case 'I': @@ -958,7 +879,7 @@ void LoadWiWorldInfo(const std::string& fileName, WorldInfo& worldInfo, Wind& wi } file.close(); } -void LoadWiCameras(const std::string&directory, const std::string& name, const std::string& identifier, std::list& cameras +void LoadWiCameras(const std::string&directory, const std::string& name, std::list& cameras ,const unordered_set& armatures) { stringstream filename(""); @@ -980,24 +901,12 @@ void LoadWiCameras(const std::string&directory, const std::string& name, const s XMFLOAT4 rot; string name(""),parentA(""),parentB(""); file>>name>>parentA>>parentB>>trans.x>>trans.y>>trans.z>>rot.x>>rot.y>>rot.z>>rot.w; - - - stringstream identified_parentArmature(""); - identified_parentArmature<name.compare(identified_parentArmature.str())){ - // for (unsigned int j = 0; jboneCollection.size(); ++j){ - // if(!armatures[i]->boneCollection[j]->name.compare(parentB.c_str())) - // cameras.back().attachTo(armatures[i]->boneCollection[j]); - // } - // } - //} for (auto& a : armatures) { Bone* b = a->GetBone(parentB); @@ -1527,8 +1436,7 @@ void Mesh::init() SAFE_INIT(streamoutBuffer_PRE); } -void Mesh::LoadFromFile(const std::string& newName, const std::string& fname - , const MaterialCollection& materialColl, const unordered_set& armatures, const std::string& identifier) { +void Mesh::LoadFromFile(const std::string& newName, const std::string& fname, const MaterialCollection& materialColl, const unordered_set& armatures) { name = newName; BYTE* buffer; @@ -1580,7 +1488,7 @@ void Mesh::LoadFromFile(const std::string& newName, const std::string& fname delete[] pName; stringstream identified_parent(""); - identified_parent << parent << identifier; + identified_parent << parent; for (Armature* a : armatures) { if (!a->name.compare(identified_parent.str())) { armatureName = identified_parent.str(); @@ -1601,7 +1509,7 @@ void Mesh::LoadFromFile(const std::string& newName, const std::string& fname offset += matNameLen; stringstream identified_matname(""); - identified_matname << matName << identifier; + identified_matname << matName; MaterialCollection::const_iterator iter = materialColl.find(identified_matname.str()); if (iter != materialColl.end()) { subsets.push_back(MeshSubset()); @@ -2735,7 +2643,7 @@ void Model::CleanUp() } environmentProbes.clear(); } -void Model::LoadFromDisk(const std::string& fileName, const std::string& identifier) +void Model::LoadFromDisk(const std::string& fileName) { string directory, name; wiHelper::SplitPath(fileName, directory, name); @@ -2765,13 +2673,13 @@ void Model::LoadFromDisk(const std::string& fileName, const std::string& identif if (success) { - this->name = name + identifier; + this->name = name; // Load material library: vector materialLibrary = {}; for (auto& obj_material : obj_materials) { - Material* material = new Material(obj_material.name + identifier); + Material* material = new Material(obj_material.name); material->diffuseColor = XMFLOAT3(obj_material.diffuse[0], obj_material.diffuse[1], obj_material.diffuse[2]); material->textureName = obj_material.diffuse_texname; @@ -2836,8 +2744,8 @@ void Model::LoadFromDisk(const std::string& fileName, const std::string& identif // Load objects, meshes: for (auto& shape : obj_shapes) { - Object* object = new Object(shape.name + identifier); - Mesh* mesh = new Mesh(shape.name + "_mesh" + identifier); + Object* object = new Object(shape.name); + Mesh* mesh = new Mesh(shape.name + "_mesh"); object->mesh = mesh; mesh->renderable = true; @@ -2978,14 +2886,14 @@ void Model::LoadFromDisk(const std::string& fileName, const std::string& identif decalsFilePath << name << ".wid"; camerasFilePath << name << ".wic"; - LoadWiArmatures(directory, armatureFilePath.str(), identifier, armatures); - LoadWiMaterialLibrary(directory, materialLibFilePath.str(), identifier, "textures/", materials); - LoadWiMeshes(directory, meshesFilePath.str(), identifier, meshes, armatures, materials); - LoadWiObjects(directory, objectsFilePath.str(), identifier, objects, armatures, meshes, materials); - LoadWiActions(directory, actionsFilePath.str(), identifier, armatures); - LoadWiLights(directory, lightsFilePath.str(), identifier, lights); + LoadWiArmatures(directory, armatureFilePath.str(), armatures); + LoadWiMaterialLibrary(directory, materialLibFilePath.str(), "textures/", materials); + LoadWiMeshes(directory, meshesFilePath.str(), meshes, armatures, materials); + LoadWiObjects(directory, objectsFilePath.str(), objects, armatures, meshes, materials); + LoadWiActions(directory, actionsFilePath.str(), armatures); + LoadWiLights(directory, lightsFilePath.str(), lights); LoadWiDecals(directory, decalsFilePath.str(), "textures/", decals); - LoadWiCameras(directory, camerasFilePath.str(), identifier, cameras, armatures); + LoadWiCameras(directory, camerasFilePath.str(), cameras, armatures); FinishLoading(); } @@ -3003,17 +2911,36 @@ void Model::FinishLoading() x->GetPrimaryAnimation()->ChangeAction(1); } transforms.push_back(x); + x->parentModel = this; } for (Object* x : objects) { transforms.push_back(x); + x->parentModel = this; } for (Light* x : lights) { transforms.push_back(x); + x->parentModel = this; } for (Decal* x : decals) { transforms.push_back(x); + x->parentModel = this; + } + for (EnvironmentProbe* x : environmentProbes) + { + transforms.push_back(x); + x->parentModel = this; + } + for (ForceField* x : forces) + { + transforms.push_back(x); + x->parentModel = this; + } + for (Camera* x : cameras) + { + transforms.push_back(x); + x->parentModel = this; } @@ -3127,6 +3054,7 @@ void Model::Add(Object* value) { if (value != nullptr) { + value->parentModel = this; objects.insert(value); if (value->mesh != nullptr) { @@ -3143,6 +3071,7 @@ void Model::Add(Armature* value) { if (value != nullptr) { + value->parentModel = this; armatures.insert(value); } } @@ -3150,6 +3079,7 @@ void Model::Add(Light* value) { if (value != nullptr) { + value->parentModel = this; lights.insert(value); } } @@ -3157,6 +3087,7 @@ void Model::Add(Decal* value) { if (value != nullptr) { + value->parentModel = this; decals.insert(value); } } @@ -3164,6 +3095,7 @@ void Model::Add(ForceField* value) { if (value != nullptr) { + value->parentModel = this; forces.insert(value); } } @@ -3171,6 +3103,7 @@ void Model::Add(EnvironmentProbe* value) { if (value != nullptr) { + value->parentModel = this; environmentProbes.push_back(value); } } @@ -3178,6 +3111,7 @@ void Model::Add(Camera* value) { if (value != nullptr) { + value->parentModel = this; cameras.push_back(value); } } @@ -3865,6 +3799,7 @@ XMVECTOR Armature::InterPolateKeyFrames(float cf, const int maxCf, const std::ve return result; } + void Armature::ChangeAction(const std::string& actionName, float blendFrames, const std::string& animLayer, float weight) { AnimationLayer* anim = GetPrimaryAnimation(); @@ -3928,6 +3863,28 @@ void Armature::DeleteAnimLayer(const std::string& name) } } } +void Armature::RecursiveRest(Bone* bone) +{ + Bone* parent = (Bone*)bone->parent; + + if (parent != nullptr) { + XMMATRIX recRest = + XMLoadFloat4x4(&bone->world_rest) + * + XMLoadFloat4x4(&parent->recursiveRest) + ; + XMStoreFloat4x4(&bone->recursiveRest, recRest); + XMStoreFloat4x4(&bone->recursiveRestInv, XMMatrixInverse(0, recRest)); + } + else { + bone->recursiveRest = bone->world_rest; + XMStoreFloat4x4(&bone->recursiveRestInv, XMMatrixInverse(0, XMLoadFloat4x4(&bone->recursiveRest))); + } + + for (unsigned int i = 0; ichildrenI.size(); ++i) { + RecursiveRest(bone->childrenI[i]); + } +} void Armature::CreateFamily() { for (Bone* i : boneCollection) { @@ -3948,8 +3905,9 @@ void Armature::CreateFamily() } } - for (unsigned int i = 0; i> unidentified_name; + string voidStr; + archive >> voidStr; // no longer needed (it was unidentified_name previously...) size_t boneCount; archive >> boneCount; for (size_t i = 0; i < boneCount; ++i) @@ -4016,7 +3975,8 @@ void Armature::Serialize(wiArchive& archive) } else { - archive << unidentified_name; + string voidStr = ""; + archive << voidStr; // no longer needed (it was unidentified_name previously...) archive << boneCollection.size(); for (auto& x : boneCollection) { @@ -4224,6 +4184,8 @@ Object::Object(const Object& other):Cullable(other),Transform(other) transparency = other.transparency; color = other.color; + parentModel = other.parentModel; + for (auto&x : other.eParticleSystems) { eParticleSystems.push_back(new wiEmittedParticle(*x)); diff --git a/WickedEngine/wiLoader.h b/WickedEngine/wiLoader.h index 583a63e2c..153f0cd82 100644 --- a/WickedEngine/wiLoader.h +++ b/WickedEngine/wiLoader.h @@ -28,12 +28,18 @@ struct Bone; struct Mesh; struct Material; struct Object; +struct Model; typedef std::map MeshCollection; typedef std::map MaterialCollection; class wiArchive; +struct ModelChild +{ + Model* parentModel = nullptr; +}; + GFX_STRUCT Instance { XMFLOAT4A mat0; @@ -492,8 +498,7 @@ public: Mesh(const std::string& newName = ""); ~Mesh(); - void LoadFromFile(const std::string& newName, const std::string& fname - , const MaterialCollection& materialColl, const std::unordered_set& armatures, const std::string& identifier=""); + void LoadFromFile(const std::string& newName, const std::string& fname, const MaterialCollection& materialColl, const std::unordered_set& armatures); void Optimize(); void CreateRenderData(); static void CreateImpostorVB(); @@ -517,7 +522,7 @@ public: AABB bounds; void Serialize(wiArchive& archive); }; -struct Object : public Cullable, public Transform +struct Object : public Cullable, public Transform, public ModelChild { std::string meshName; Mesh* mesh; @@ -689,10 +694,9 @@ struct AnimationLayer void Serialize(wiArchive& archive); }; -struct Armature : public Transform +struct Armature : public Transform, public ModelChild { public: - std::string unidentified_name; std::vector boneCollection; std::vector rootbones; @@ -720,11 +724,8 @@ public: Armature() :Transform(){ init(); }; - Armature(const std::string& newName, const std::string& identifier):Transform(){ - unidentified_name=newName; - std::stringstream ss(""); - ss<unidentified_name<name<actions.size(); j++) if(!armature->actions[j].name.compare(ss.str())) return j; @@ -4768,7 +4768,7 @@ void wiRenderer::SetShadowPropsCube(int resolution, int count) desc.MiscFlags = RESOURCE_MISC_TEXTURECUBE; GetDevice()->CreateTexture2D(&desc, nullptr, &Light::shadowMapArray_Cube); } -void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) +void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID, uint32_t layerMask) { if (wireRender) return; @@ -4782,6 +4782,8 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) GetDevice()->EventBegin("ShadowMap Render", threadID); wiProfiler::GetInstance().BeginRange("Shadow Rendering", wiProfiler::DOMAIN_GPU, threadID); + const bool all_layers = layerMask == 0xFFFFFFFF; // this can avoid the recursive call per object : GetLayerMask() + const FrameCulling& culling = frameCullings[getCamera()]; const CulledList& culledLights = culling.culledLights; @@ -4870,13 +4872,16 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) { continue; } - if (object->IsCastingShadow()) + if (all_layers || (layerMask & object->GetLayerMask())) { - culledRenderer[object->mesh].push_front(object); - - if (object->GetRenderTypes() & RENDERTYPE_TRANSPARENT || object->GetRenderTypes() & RENDERTYPE_WATER) + if (object->IsCastingShadow()) { - transparentShadowsRequested = true; + culledRenderer[object->mesh].push_front(object); + + if (object->GetRenderTypes() & RENDERTYPE_TRANSPARENT || object->GetRenderTypes() & RENDERTYPE_WATER) + { + transparentShadowsRequested = true; + } } } } @@ -4926,13 +4931,16 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) for (Cullable* x : culledObjects) { Object* object = (Object*)x; - if (object->IsCastingShadow()) + if (all_layers || (layerMask & object->GetLayerMask())) { - culledRenderer[object->mesh].push_front(object); - - if (object->GetRenderTypes() & RENDERTYPE_TRANSPARENT || object->GetRenderTypes() & RENDERTYPE_WATER) + if (object->IsCastingShadow()) { - transparentShadowsRequested = true; + culledRenderer[object->mesh].push_front(object); + + if (object->GetRenderTypes() & RENDERTYPE_TRANSPARENT || object->GetRenderTypes() & RENDERTYPE_WATER) + { + transparentShadowsRequested = true; + } } } } @@ -4982,9 +4990,13 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) for (Cullable* x : culledObjects) { Object* object = (Object*)x; - if (object->IsCastingShadow()) + + if (all_layers || (layerMask & object->GetLayerMask())) { - culledRenderer[object->mesh].push_front(object); + if (object->IsCastingShadow()) + { + culledRenderer[object->mesh].push_front(object); + } } } if (!culledRenderer.empty()) @@ -5029,7 +5041,7 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) } void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culledRenderer, SHADERTYPE shaderType, UINT renderTypeFlags, GRAPHICSTHREAD threadID, - bool tessellation, bool occlusionCulling) + bool tessellation, bool occlusionCulling, uint32_t layerMask) { // Intensive section, refactor and optimize! @@ -5063,6 +5075,8 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle shaderType == SHADERTYPE_DEPTHONLY || shaderType == SHADERTYPE_VOXELIZE; + const bool all_layers = layerMask == 0xFFFFFFFF; // this can avoid the recursive call per object : GetLayerMask() + GraphicsPSO* impostorRequest = GetImpostorPSO(shaderType); // Render impostors: @@ -5091,30 +5105,33 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle if (occlusionCulling && instance->IsOccluded()) continue; - const float impostorThreshold = instance->bounds.getRadius(); - float dist = wiMath::Distance(eye, instance->bounds.getCenter()); - float dither = instance->transparency; - dither = wiMath::SmoothStep(1.0f, dither, wiMath::Clamp((dist - mesh->impostorDistance) / impostorThreshold, 0, 1)); - if (dither > 1.0f - FLT_EPSILON) - continue; - - XMMATRIX boxMat = mesh->aabb.getAsBoxMatrix(); - - XMStoreFloat4x4(&tempMat, boxMat*XMLoadFloat4x4(&instance->world)); - - if (advancedVBRequest) + if (all_layers || (layerMask & instance->GetLayerMask())) { - ((volatile InstBuf*)instances)[k].instance.Create(tempMat, dither, instance->color); + const float impostorThreshold = instance->bounds.getRadius(); + float dist = wiMath::Distance(eye, instance->bounds.getCenter()); + float dither = instance->transparency; + dither = wiMath::SmoothStep(1.0f, dither, wiMath::Clamp((dist - mesh->impostorDistance) / impostorThreshold, 0, 1)); + if (dither > 1.0f - FLT_EPSILON) + continue; - XMStoreFloat4x4(&tempMat, boxMat*XMLoadFloat4x4(&instance->worldPrev)); - ((volatile InstBuf*)instances)[k].instancePrev.Create(tempMat); - } - else - { - ((volatile Instance*)instances)[k].Create(tempMat, dither, instance->color); - } + XMMATRIX boxMat = mesh->aabb.getAsBoxMatrix(); - ++k; + XMStoreFloat4x4(&tempMat, boxMat*XMLoadFloat4x4(&instance->world)); + + if (advancedVBRequest) + { + ((volatile InstBuf*)instances)[k].instance.Create(tempMat, dither, instance->color); + + XMStoreFloat4x4(&tempMat, boxMat*XMLoadFloat4x4(&instance->worldPrev)); + ((volatile InstBuf*)instances)[k].instancePrev.Create(tempMat); + } + else + { + ((volatile Instance*)instances)[k].Create(tempMat, dither, instance->color); + } + + ++k; + } } device->InvalidateBufferAccess(dynamicVertexBufferPool, threadID); @@ -5222,41 +5239,44 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle if (occlusionCulling && instance->IsOccluded()) continue; - float dither = instance->transparency; - if (impostorRequest != nullptr) + if (all_layers || (layerMask & instance->GetLayerMask())) { - // fade out to impostor... - const float impostorThreshold = instance->bounds.getRadius(); - float dist = wiMath::Distance(eye, instance->bounds.getCenter()); - if (mesh->hasImpostor()) - dither = wiMath::SmoothStep(dither, 1.0f, wiMath::Clamp((dist - impostorThreshold - mesh->impostorDistance) / impostorThreshold, 0, 1)); - } - if (dither > 1.0f - FLT_EPSILON) - continue; + float dither = instance->transparency; + if (impostorRequest != nullptr) + { + // fade out to impostor... + const float impostorThreshold = instance->bounds.getRadius(); + float dist = wiMath::Distance(eye, instance->bounds.getCenter()); + if (mesh->hasImpostor()) + dither = wiMath::SmoothStep(dither, 1.0f, wiMath::Clamp((dist - impostorThreshold - mesh->impostorDistance) / impostorThreshold, 0, 1)); + } + if (dither > 1.0f - FLT_EPSILON) + continue; - forceAlphaTestForDithering = forceAlphaTestForDithering || (dither > 0); - - if (mesh->softBody) - tempMat = __identityMat; - else - tempMat = instance->world; - - if (advancedVBRequest || tessellatorRequested) - { - ((volatile InstBuf*)instances)[k].instance.Create(tempMat, dither, instance->color); + forceAlphaTestForDithering = forceAlphaTestForDithering || (dither > 0); if (mesh->softBody) tempMat = __identityMat; else - tempMat = instance->worldPrev; - ((volatile InstBuf*)instances)[k].instancePrev.Create(tempMat); + tempMat = instance->world; + + if (advancedVBRequest || tessellatorRequested) + { + ((volatile InstBuf*)instances)[k].instance.Create(tempMat, dither, instance->color); + + if (mesh->softBody) + tempMat = __identityMat; + else + tempMat = instance->worldPrev; + ((volatile InstBuf*)instances)[k].instancePrev.Create(tempMat); + } + else + { + ((volatile Instance*)instances)[k].Create(tempMat, dither, instance->color); + } + + ++k; } - else - { - ((volatile Instance*)instances)[k].Create(tempMat, dither, instance->color); - } - - ++k; } device->InvalidateBufferAccess(dynamicVertexBufferPool, threadID); @@ -5449,7 +5469,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle } } -void wiRenderer::DrawWorld(Camera* camera, bool tessellation, GRAPHICSTHREAD threadID, SHADERTYPE shaderType, bool grass, bool occlusionCulling) +void wiRenderer::DrawWorld(Camera* camera, bool tessellation, GRAPHICSTHREAD threadID, SHADERTYPE shaderType, bool grass, bool occlusionCulling, uint32_t layerMask) { const FrameCulling& culling = frameCullings[camera]; @@ -5477,14 +5497,14 @@ void wiRenderer::DrawWorld(Camera* camera, bool tessellation, GRAPHICSTHREAD thr if (!culledRenderer.empty() || (grass && culling.culledHairParticleSystems.empty())) { - RenderMeshes(camera->translation, culledRenderer, shaderType, RENDERTYPE_OPAQUE, threadID, tessellation, GetOcclusionCullingEnabled() && occlusionCulling); + RenderMeshes(camera->translation, culledRenderer, shaderType, RENDERTYPE_OPAQUE, threadID, tessellation, GetOcclusionCullingEnabled() && occlusionCulling, layerMask); } GetDevice()->EventEnd(threadID); } -void wiRenderer::DrawWorldTransparent(Camera* camera, SHADERTYPE shaderType, GRAPHICSTHREAD threadID, bool grass, bool occlusionCulling) +void wiRenderer::DrawWorldTransparent(Camera* camera, SHADERTYPE shaderType, GRAPHICSTHREAD threadID, bool grass, bool occlusionCulling, uint32_t layerMask) { const FrameCulling& culling = frameCullings[camera]; @@ -5513,7 +5533,7 @@ void wiRenderer::DrawWorldTransparent(Camera* camera, SHADERTYPE shaderType, GRA if (!culledRenderer.empty()) { - RenderMeshes(camera->translation, culledRenderer, shaderType, RENDERTYPE_TRANSPARENT | RENDERTYPE_WATER, threadID, false, GetOcclusionCullingEnabled() && occlusionCulling); + RenderMeshes(camera->translation, culledRenderer, shaderType, RENDERTYPE_TRANSPARENT | RENDERTYPE_WATER, threadID, false, GetOcclusionCullingEnabled() && occlusionCulling, layerMask); } GetDevice()->EventEnd(threadID); @@ -6881,8 +6901,8 @@ void wiRenderer::RayIntersectMeshes(const RAY& ray, const CulledList& culledObje return; } - XMVECTOR& rayOrigin = XMLoadFloat3(&ray.origin); - XMVECTOR& rayDirection = XMVector3Normalize(XMLoadFloat3(&ray.direction)); + const XMVECTOR rayOrigin = XMLoadFloat3(&ray.origin); + const XMVECTOR rayDirection = XMVector3Normalize(XMLoadFloat3(&ray.direction)); // pre allocate helper vector array: static size_t _arraySize = 10000; @@ -6892,7 +6912,7 @@ void wiRenderer::RayIntersectMeshes(const RAY& ray, const CulledList& culledObje { Object* object = (Object*)culled; - uint32_t objectLayerMask = object->GetLayerMask(); + const uint32_t objectLayerMask = object->GetLayerMask(); if (objectLayerMask & layerMask) { @@ -6918,11 +6938,11 @@ void wiRenderer::RayIntersectMeshes(const RAY& ray, const CulledList& culledObje _vertices = (XMVECTOR*)_mm_malloc(sizeof(XMVECTOR)*_arraySize, 16); } - XMMATRIX objectMat = object->getMatrix(); - XMMATRIX objectMat_Inverse = XMMatrixInverse(nullptr, objectMat); + const XMMATRIX objectMat = object->getMatrix(); + const XMMATRIX objectMat_Inverse = XMMatrixInverse(nullptr, objectMat); - XMVECTOR rayOrigin_local = XMVector3Transform(rayOrigin, objectMat_Inverse); - XMVECTOR rayDirection_local = XMVector3Normalize(XMVector3TransformNormal(rayDirection, objectMat_Inverse)); + const XMVECTOR rayOrigin_local = XMVector3Transform(rayOrigin, objectMat_Inverse); + const XMVECTOR rayDirection_local = XMVector3Normalize(XMVector3TransformNormal(rayDirection, objectMat_Inverse)); Mesh::Vertex_FULL _tmpvert; @@ -7043,15 +7063,12 @@ void wiRenderer::CalculateVertexAO(Object* object) //mesh->calculatedAO = true; } -Model* wiRenderer::LoadModel(const std::string& fileName, const XMMATRIX& transform, const std::string& ident) +Model* wiRenderer::LoadModel(const std::string& fileName, const XMMATRIX& transform) { static int unique_identifier = 0; - stringstream idss(""); - idss<<"_"<LoadFromDisk(fileName, idss.str()); + model->LoadFromDisk(fileName); model->transform(transform); @@ -7397,7 +7414,15 @@ void wiRenderer::AddModel(Model* model) void wiRenderer::Add(Object* value) { - GetScene().GetWorldNode()->Add(value); + if (value->parentModel == nullptr) + { + GetScene().GetWorldNode()->Add(value); + } + else + { + value->parentModel->Add(value); + } + if (value->parent == nullptr) { value->attachTo(GetScene().GetWorldNode()); @@ -7416,7 +7441,15 @@ void wiRenderer::Add(Object* value) } void wiRenderer::Add(Light* value) { - GetScene().GetWorldNode()->Add(value); + if (value->parentModel == nullptr) + { + GetScene().GetWorldNode()->Add(value); + } + else + { + value->parentModel->Add(value); + } + if (value->parent == nullptr) { value->attachTo(GetScene().GetWorldNode()); @@ -7435,7 +7468,15 @@ void wiRenderer::Add(Light* value) } void wiRenderer::Add(ForceField* value) { - GetScene().GetWorldNode()->Add(value); + if (value->parentModel == nullptr) + { + GetScene().GetWorldNode()->Add(value); + } + else + { + value->parentModel->Add(value); + } + if (value->parent == nullptr) { value->attachTo(GetScene().GetWorldNode()); @@ -7443,7 +7484,15 @@ void wiRenderer::Add(ForceField* value) } void wiRenderer::Add(Camera* value) { - GetScene().GetWorldNode()->Add(value); + if (value->parentModel == nullptr) + { + GetScene().GetWorldNode()->Add(value); + } + else + { + value->parentModel->Add(value); + } + if (value->parent == nullptr) { value->attachTo(GetScene().GetWorldNode()); @@ -7457,6 +7506,7 @@ void wiRenderer::Remove(Object* value) for (auto& x : GetScene().models) { x->objects.erase(value); + value->parentModel = nullptr; } spTree->Remove(value); value->detach(); @@ -7469,6 +7519,7 @@ void wiRenderer::Remove(Light* value) for (auto& x : GetScene().models) { x->lights.erase(value); + value->parentModel = nullptr; } spTree_lights->Remove(value); value->detach(); @@ -7481,6 +7532,7 @@ void wiRenderer::Remove(Decal* value) for (auto& x : GetScene().models) { x->decals.erase(value); + value->parentModel = nullptr; } value->detach(); } @@ -7492,6 +7544,7 @@ void wiRenderer::Remove(EnvironmentProbe* value) for (auto& x : GetScene().models) { x->environmentProbes.remove(value); + value->parentModel = nullptr; } value->detach(); } @@ -7503,6 +7556,7 @@ void wiRenderer::Remove(ForceField* value) for (auto& x : GetScene().models) { x->forces.erase(value); + value->parentModel = nullptr; } value->detach(); } @@ -7514,6 +7568,7 @@ void wiRenderer::Remove(Camera* value) for (auto& x : GetScene().models) { x->cameras.remove(value); + value->parentModel = nullptr; } value->detach(); } diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index 2193bf44c..ce7f40eb8 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -459,12 +459,13 @@ public: static void UpdateGBuffer(wiGraphicsTypes::Texture2D* slot0, wiGraphicsTypes::Texture2D* slot1, wiGraphicsTypes::Texture2D* slot2, wiGraphicsTypes::Texture2D* slot3, wiGraphicsTypes::Texture2D* slot4, GRAPHICSTHREAD threadID); static void UpdateDepthBuffer(wiGraphicsTypes::Texture2D* depth, wiGraphicsTypes::Texture2D* linearDepth, GRAPHICSTHREAD threadID); - static void RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culledRenderer, SHADERTYPE shaderType, UINT renderTypeFlags, GRAPHICSTHREAD threadID, bool tessellation = false, bool occlusionCulling = false); + static void RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culledRenderer, SHADERTYPE shaderType, UINT renderTypeFlags, GRAPHICSTHREAD threadID, + bool tessellation = false, bool occlusionCulling = false, uint32_t layerMask = 0xFFFFFFFF); static void DrawSky(GRAPHICSTHREAD threadID); static void DrawSun(GRAPHICSTHREAD threadID); - static void DrawWorld(Camera* camera, bool tessellation, GRAPHICSTHREAD threadID, SHADERTYPE shaderType, bool grass, bool occlusionCulling); - static void DrawForShadowMap(GRAPHICSTHREAD threadID); - static void DrawWorldTransparent(Camera* camera, SHADERTYPE shaderType, GRAPHICSTHREAD threadID, bool grass, bool occlusionCulling); + static void DrawWorld(Camera* camera, bool tessellation, GRAPHICSTHREAD threadID, SHADERTYPE shaderType, bool grass, bool occlusionCulling, uint32_t layerMask = 0xFFFFFFFF); + static void DrawForShadowMap(GRAPHICSTHREAD threadID, uint32_t layerMask = 0xFFFFFFFF); + static void DrawWorldTransparent(Camera* camera, SHADERTYPE shaderType, GRAPHICSTHREAD threadID, bool grass, bool occlusionCulling, uint32_t layerMask = 0xFFFFFFFF); void DrawDebugSpheres(Camera* camera, GRAPHICSTHREAD threadID); static void DrawDebugBoneLines(Camera* camera, GRAPHICSTHREAD threadID); static void DrawDebugLines(Camera* camera, GRAPHICSTHREAD threadID); @@ -519,7 +520,6 @@ public: static int getVisibleObjectCount(){return visibleCount;} static void resetVisibleObjectCount(){visibleCount=0;} - static void FinishLoading(); static wiSPTree* spTree; static wiSPTree* spTree_lights; @@ -609,7 +609,7 @@ public: static void SetOceanEnabled(bool enabled, const wiOceanParameter& params); static wiOcean* GetOcean() { return ocean; } - static Model* LoadModel(const std::string& fileName, const XMMATRIX& transform = XMMatrixIdentity(), const std::string& ident = "common"); + static Model* LoadModel(const std::string& fileName, const XMMATRIX& transform = XMMatrixIdentity()); static void LoadWorldInfo(const std::string& fileName); static void LoadDefaultLighting(); diff --git a/WickedEngine/wiRenderer_BindLua.cpp b/WickedEngine/wiRenderer_BindLua.cpp index 9b0295c75..e9584dfb0 100644 --- a/WickedEngine/wiRenderer_BindLua.cpp +++ b/WickedEngine/wiRenderer_BindLua.cpp @@ -326,31 +326,26 @@ namespace wiRenderer_BindLua if (argc > 0) { string fileName = wiLua::SGetString(L, 1); - string identifier = "common"; XMMATRIX transform = XMMatrixIdentity(); if (argc > 1) { - identifier = wiLua::SGetString(L, 2); - if (argc > 2) + Matrix_BindLua* matrix = Luna::lightcheck(L, 2); + if (matrix != nullptr) { - Matrix_BindLua* matrix = Luna::lightcheck(L, 3); - if (matrix != nullptr) - { - transform = matrix->matrix; - } - else - { - wiLua::SError(L, "LoadModel(string fileName, opt string identifier, opt Matrix transform) argument is not a matrix!"); - } + transform = matrix->matrix; + } + else + { + wiLua::SError(L, "LoadModel(string fileName, opt Matrix transform) argument is not a matrix!"); } } - Model* model = wiRenderer::LoadModel(fileName, transform, identifier); + Model* model = wiRenderer::LoadModel(fileName, transform); Luna::push(L, new Model_BindLua(model)); return 1; } else { - wiLua::SError(L, "LoadModel(string fileName, opt string identifier, opt Matrix transform) not enough arguments!"); + wiLua::SError(L, "LoadModel(string fileName, opt Matrix transform) not enough arguments!"); } return 0; } @@ -368,6 +363,30 @@ namespace wiRenderer_BindLua } return 0; } + int DuplicateInstance(lua_State* L) + { + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Object_BindLua* x = Luna::lightcheck(L, 1); + if (x != nullptr) + { + Object* o = new Object(*x->object); + wiRenderer::Add(o); + Luna::push(L, new Object_BindLua(o)); + return 1; + } + else + { + wiLua::SError(L, "DuplicateInstance(Object object) argument type mismatch!"); + } + } + else + { + wiLua::SError(L, "DuplicateInstance(Object object) not enough arguments!"); + } + return 0; + } int SetEnvironmentMap(lua_State* L) { int argc = wiLua::SGetArgCount(L); @@ -734,6 +753,7 @@ namespace wiRenderer_BindLua wiLua::GetGlobal()->RegisterFunc("LoadModel", LoadModel); wiLua::GetGlobal()->RegisterFunc("LoadWorldInfo", LoadWorldInfo); + wiLua::GetGlobal()->RegisterFunc("DuplicateInstance", DuplicateInstance); wiLua::GetGlobal()->RegisterFunc("SetEnvironmentMap", SetEnvironmentMap); wiLua::GetGlobal()->RegisterFunc("SetColorGrading", SetColorGrading); wiLua::GetGlobal()->RegisterFunc("HairParticleSettings", HairParticleSettings); diff --git a/WickedEngine/wiTransform.cpp b/WickedEngine/wiTransform.cpp index 182e03a08..46a822bdc 100644 --- a/WickedEngine/wiTransform.cpp +++ b/WickedEngine/wiTransform.cpp @@ -308,7 +308,7 @@ Transform* Transform::GetRoot() } return this; } -uint32_t Transform::GetLayerMask() +uint32_t Transform::GetLayerMask() const { if (parent != nullptr) { diff --git a/WickedEngine/wiTransform.h b/WickedEngine/wiTransform.h index 6ba317a3f..6edefa912 100644 --- a/WickedEngine/wiTransform.h +++ b/WickedEngine/wiTransform.h @@ -19,9 +19,9 @@ public: Node(); void SetLayerMask(uint32_t value) { layerMask = value; } - virtual uint32_t GetLayerMask() { return layerMask; } + virtual uint32_t GetLayerMask() const { return layerMask; } - uint64_t GetID() { return ID; } + uint64_t GetID() const { return ID; } void SetID(uint64_t newID) { ID = newID; } static const uint64_t INVALID_ID = UINT64_MAX; @@ -79,7 +79,7 @@ struct Transform : public Node // Get the root of the tree Transform* GetRoot(); // Layer mask with parent hierarchy masking - virtual uint32_t GetLayerMask() override; + virtual uint32_t GetLayerMask() const override; void Serialize(wiArchive& archive); }; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 56d117f6b..ec50b93f8 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 17; // minor bug fixes, alterations, refactors, updates - const int revision = 30; + const int revision = 31; long GetVersion() diff --git a/scripts/character_controller_tps.lua b/scripts/character_controller_tps.lua index cfa633ad3..e15b17e30 100644 --- a/scripts/character_controller_tps.lua +++ b/scripts/character_controller_tps.lua @@ -32,9 +32,8 @@ characterController = { }, state = STAND, - Load = function(self,fileName,id,objectname,armaturename) - self.id = id - local model = LoadModel(fileName,id) + Load = function(self,fileName,objectname,armaturename) + local model = LoadModel(fileName) model.SetLayerMask(self.layerMask) self.skeleton = GetArmature(armaturename) end, @@ -255,7 +254,7 @@ runProcess(function() --ClearWorld() --LoadModel("../models/Misc/scene.wimf") - player:Load("../models/girl/girl.wimf","player","omino_common","Armature_common") + player:Load("../models/girl/girl.wimf","omino_common","Armature_common") player:Reset() --player:Reposition(Vector(0,4,-20)) camera:Reset() diff --git a/scripts/dungeon_generator.lua b/scripts/dungeon_generator.lua index bb1cd8a00..08e8fd873 100644 --- a/scripts/dungeon_generator.lua +++ b/scripts/dungeon_generator.lua @@ -54,20 +54,18 @@ dungeon={ end if place then - LoadModel(modelpath .. "dungeon/end/end",tag,exitTransforms[i]) + LoadModel(modelpath .. "dungeon/end/end",exitTransforms[i]) end end end -- Place the start piece of the dungeon - LoadModel(modelpath .. "dungeon/start/start","segment",scalingMat) + LoadModel(modelpath .. "dungeon/start/start",scalingMat) LoadWorldInfo("dungeon/start/","start.wiw") CheckSegmentCanBePlaced(AABB(Vector(-1,0,-2),Vector(1,2,0))) -- Create physical dungeon segments recursively local function GenerateDungeon(i, count, pos, rotY) - -- tag is a unique identifier for each segment - local tag = "segment"..math.floor(pos.GetX())..math.floor(pos.GetY())..math.floor(pos.GetZ()) local rotMat = matrix.RotationY(rotY) local transformMat = matrix.Multiply( rotMat, matrix.Multiply( matrix.Translation(pos), scalingMat ) ) @@ -83,21 +81,21 @@ dungeon={ local select2 = math.random(0, 6) if(select2 < 1) then --left turn if CheckSegmentCanBePlaced(AABB(Vector(-1,0,0),Vector(1,2,2)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/turnleft/turnleft",tag,transformMat) + LoadModel(modelpath .. "dungeon/turnleft/turnleft",transformMat) GenerateDungeon(i+1,count,pos:Add(Vector(-1,0,1).Transform(rotMat)),rotY-0.5*math.pi) else GenerateDungeon(i+1,count,pos,rotY) end elseif(select2 < 2) then --right turn if CheckSegmentCanBePlaced(AABB(Vector(-1,0,0),Vector(1,2,2)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/turnright/turnright",tag,transformMat) + LoadModel(modelpath .. "dungeon/turnright/turnright",transformMat) GenerateDungeon(i+1,count,pos:Add(Vector(1,0,1).Transform(rotMat)),rotY+0.5*math.pi) else GenerateDungeon(i+1,count,pos,rotY) end elseif(select2 < 3) then --t-junction if CheckSegmentCanBePlaced(AABB(Vector(-1,0,0),Vector(1,2,2)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/tjunction/tjunction",tag,transformMat) + LoadModel(modelpath .. "dungeon/tjunction/tjunction",transformMat) -- right GenerateDungeon(i+1,count,pos:Add(Vector(1,0,1).Transform(rotMat)),rotY+0.5*math.pi) -- left @@ -107,7 +105,7 @@ dungeon={ end elseif(select2 < 4) then --cross-junction if CheckSegmentCanBePlaced(AABB(Vector(-1,0,0),Vector(1,2,2)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/crossjunction/crossjunction",tag,transformMat) + LoadModel(modelpath .. "dungeon/crossjunction/crossjunction",transformMat) -- right GenerateDungeon(i+1,count,pos:Add(Vector(1,0,1).Transform(rotMat)),rotY+0.5*math.pi) -- left @@ -119,7 +117,7 @@ dungeon={ end else --straight block if CheckSegmentCanBePlaced(AABB(Vector(-1,0,0),Vector(1,2,2)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/block/block",tag,transformMat) + LoadModel(modelpath .. "dungeon/block/block",transformMat) GenerateDungeon(i+1,count,pos:Add(Vector(0,0,2).Transform(rotMat)),rotY) else GenerateDungeon(i+1,count,pos,rotY) @@ -129,28 +127,28 @@ dungeon={ local select2 = math.random(0, 100) if( select2 < 20 ) then --small room left if CheckSegmentCanBePlaced(AABB(Vector(-5,0,0),Vector(1,2,6)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/smallroomleft/smallroomleft",tag,transformMat ) + LoadModel(modelpath .. "dungeon/smallroomleft/smallroomleft",transformMat ) GenerateDungeon(i+1,count,pos:Add(Vector(-5,0,5).Transform(rotMat)),rotY-0.5*math.pi) else GenerateDungeon(i+1,count,pos,rotY) end elseif( select2 < 30 ) then --odd corridor if CheckSegmentCanBePlaced(AABB(Vector(-1,0,0),Vector(3,2,8)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/oddcorridor/oddcorridor",tag,transformMat ) + LoadModel(modelpath .. "dungeon/oddcorridor/oddcorridor",transformMat ) GenerateDungeon(i+1,count,pos:Add(Vector(2,0,8).Transform(rotMat)),rotY) else GenerateDungeon(i+1,count,pos,rotY) end elseif( select2 < 60 ) then --up corridor if CheckSegmentCanBePlaced(AABB(Vector(-1,0,0),Vector(1,4,6)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/upcorridor/upcorridor",tag,transformMat ) + LoadModel(modelpath .. "dungeon/upcorridor/upcorridor",transformMat ) GenerateDungeon(i+1,count,pos:Add(Vector(0,2,6).Transform(rotMat)),rotY) else GenerateDungeon(i+1,count,pos,rotY) end else --corridor if CheckSegmentCanBePlaced(AABB(Vector(-1,0,0),Vector(1,2,6)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/corridor/corridor",tag,transformMat ) + LoadModel(modelpath .. "dungeon/corridor/corridor",transformMat ) GenerateDungeon(i+1,count,pos:Add(Vector(0,0,6).Transform(rotMat)),rotY) else GenerateDungeon(i+1,count,pos,rotY) @@ -158,7 +156,7 @@ dungeon={ end else -- rare pieces if CheckSegmentCanBePlaced(AABB(Vector(-4,0,0),Vector(4,8,8)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/room/room",tag,transformMat ) + LoadModel(modelpath .. "dungeon/room/room",transformMat ) -- right GenerateDungeon(i+1,count,pos:Add(Vector(4,0,4).Transform(rotMat)),rotY + 0.5*math.pi) -- left