2
0
Эх сурвалжийг харах

Bug fixes in instansing and other

Panagiotis Christopoulos Charitos 12 жил өмнө
parent
commit
a4244ae07a

+ 15 - 0
include/anki/Config.h.cmake

@@ -107,6 +107,21 @@
 // Scene config
 #define ANKI_SCENE_OPTIMAL_SCENE_NODES_COUNT 1024
 
+/// 1MB
+#define ANKI_SCENE_ALLOCATOR_SIZE 0x100000 
+
+// 512K
+#define ANKI_SCENE_FRAME_ALLOCATOR_SIZE 0x80000
+
+/// @{
+/// Used to optimize the initial vectors of VisibilityTestResults
+#define ANKI_FRUSTUMABLE_AVERAGE_VISIBLE_RENDERABLES_COUNT 16
+#define ANKI_FRUSTUMABLE_AVERAGE_VISIBLE_LIGHTS_COUNT 8
+/// @}
+
+/// If true then we can place spatials in a thread-safe way
+#define ANKI_CFG_OCTREE_THREAD_SAFE 1
+
 // Some compiler struff
 #if defined(__GNUC__)
 #	define ANKI_LIKELY(x) __builtin_expect((x), 1)

+ 0 - 27
include/anki/scene/Common.h

@@ -7,33 +7,6 @@
 
 namespace anki {
 
-/// @addtogroup config 
-/// @{
-/// @addtogroup config_scene Scene configuration constants
-/// @{
-
-#define ANKI_CFG_SCENE_NODES_AVERAGE_COUNT 1024
-
-/// 1MB
-#define ANKI_CFG_SCENE_ALLOCATOR_SIZE 0x100000 
-
-// 512K
-#define ANKI_CFG_SCENE_FRAME_ALLOCATOR_SIZE 0x80000
-
-/// @{
-/// Used to optimize the initial vectors of VisibilityTestResults
-#define ANKI_CFG_FRUSTUMABLE_AVERAGE_VISIBLE_RENDERABLES_COUNT 16
-#define ANKI_CFG_FRUSTUMABLE_AVERAGE_VISIBLE_LIGHTS_COUNT 8
-/// @}
-
-/// If true then we can place spatials in a thread-safe way
-#define ANKI_CFG_OCTREE_THREAD_SAFE 1
-
-#define ANKI_CFG_SCENE_PROFILE 1
-
-/// @}
-/// @}
-
 /// @addtogroup Scene
 /// @{
 

+ 7 - 2
include/anki/scene/SceneGraph.h

@@ -182,8 +182,13 @@ private:
 	template<typename T>
 	void addDict(typename Types<T>::NameToItemMap& d, T* ptr)
 	{
-		ANKI_ASSERT(d.find(ptr->getName()) == d.end()
-			&& "Item with same name already exists");
+		ANKI_ASSERT(ptr && ptr->getName());
+
+		if(d.find(ptr->getName()) != d.end())
+		{
+			throw ANKI_EXCEPTION("Node with the same name already exists: "
+				+ ptr->getName());
+		}
 
 		d[ptr->getName()] = ptr;
 	}

+ 1 - 1
include/anki/scene/SceneNode.h

@@ -159,7 +159,7 @@ protected:
 	} sceneNodeProtected;
 
 private:
-	SceneGraph* scene;
+	SceneGraph* scene = nullptr;
 	SceneString name; ///< A unique name
 };
 /// @}

+ 2 - 2
include/anki/scene/Visibility.h

@@ -71,9 +71,9 @@ struct VisibilityTestResults
 
 	VisibilityTestResults(const SceneAllocator<U8>& frameAlloc,
 		U32 renderablesReservedSize = 
-		ANKI_CFG_FRUSTUMABLE_AVERAGE_VISIBLE_RENDERABLES_COUNT,
+		ANKI_FRUSTUMABLE_AVERAGE_VISIBLE_RENDERABLES_COUNT,
 		U32 lightsReservedSize =
-		ANKI_CFG_FRUSTUMABLE_AVERAGE_VISIBLE_LIGHTS_COUNT)
+		ANKI_FRUSTUMABLE_AVERAGE_VISIBLE_LIGHTS_COUNT)
 		: renderables(frameAlloc), lights(frameAlloc)
 	{
 		renderables.reserve(renderablesReservedSize);

+ 7 - 5
src/scene/ModelNode.cpp

@@ -44,10 +44,10 @@ void ModelPatchNodeInstance::movableUpdate()
 	ModelPatchNode* modelPatchNode = 
 #if ANKI_DEBUG
 		dynamic_cast<ModelPatchNode*>(parentNode);
-	ANKI_ASSERT(modelPatchNode);
 #else
 		static_cast<ModelPatchNode*>(parentNode);
 #endif
+	ANKI_ASSERT(modelPatchNode);
 
 	ANKI_ASSERT(modelPatchNode->instances.size() > 0);
 	if(this == modelPatchNode->instances.back())
@@ -127,7 +127,7 @@ const Transform* ModelPatchNode::getRenderableWorldTransforms()
 
 		ANKI_ASSERT(transforms.size() == instances.size());
 
-		// Set the transforms
+		// Set the transforms buffer
 		for(U i = 0; i < instances.size(); i++)
 		{
 			transforms[i] = instances[i]->getWorldTransform();
@@ -193,6 +193,10 @@ ModelNode::ModelNode(
 {
 	sceneNodeProtected.movable = this;
 
+	{
+		SceneVector<int> lala(getSceneAllocator());
+	}
+
 	model.load(modelFname);
 
 	patches.reserve(model->getModelPatches().size());
@@ -200,10 +204,8 @@ ModelNode::ModelNode(
 	U i = 0;
 	for(const ModelPatchBase* patch : model->getModelPatches())
 	{
-		std::string name_ = name + std::to_string(i);
-
 		ModelPatchNode* mpn = ANKI_NEW(ModelPatchNode, getSceneAllocator(),
-			name_.c_str(), scene, this,
+			nullptr, scene, this,
 			Movable::MF_IGNORE_LOCAL_TRANSFORM, patch, instances);
 
 		patches.push_back(mpn);

+ 28 - 12
src/scene/SceneGraph.cpp

@@ -97,13 +97,13 @@ struct UpdateSceneNodesJob: ThreadJob
 
 //==============================================================================
 SceneGraph::SceneGraph()
-	:	alloc(ANKI_CFG_SCENE_ALLOCATOR_SIZE),
-		frameAlloc(ANKI_CFG_SCENE_FRAME_ALLOCATOR_SIZE),
+	:	alloc(ANKI_SCENE_ALLOCATOR_SIZE),
+		frameAlloc(ANKI_SCENE_FRAME_ALLOCATOR_SIZE),
 		nodes(alloc),
 		sectorGroup(this),
 		events(this)
 {
-	nodes.reserve(ANKI_CFG_SCENE_NODES_AVERAGE_COUNT);
+	nodes.reserve(ANKI_SCENE_OPTIMAL_SCENE_NODES_COUNT);
 
 	ambientCol = Vec3(0.1, 0.05, 0.05) * 3;
 }
@@ -240,6 +240,10 @@ void SceneGraph::load(const char* filename)
 		{
 			XmlElement el, el1;
 	
+			// <name>
+			el = mdlNodeEl.getChildElement("name");
+			std::string name = el.getText();
+
 			// <model>
 			el = mdlNodeEl.getChildElement("model");
 
@@ -252,23 +256,35 @@ void SceneGraph::load(const char* filename)
 				throw ANKI_EXCEPTION("Too many instances");
 			}
 
-			ModelNode* node = new ModelNode("name", this, nullptr,
+			ModelNode* node = ANKI_NEW(ModelNode, alloc,
+				name.c_str(), this, nullptr,
 				Movable::MF_NONE, el.getText(), instancesCount);
 
 			// <transform>
 			el = mdlNodeEl.getChildElement("transform");
-			node->setLocalTransform(Transform(el.getMat4()));
+			U i = 0;
 
-			U i = instancesCount - 1;
-			if(i > 0)
+			do
 			{
-				do
+				if(i == 0)
 				{
-
-					// Advance
-					el = mdlNodeEl.getNextSiblingElement("transform");
+					node->setLocalTransform(Transform(el.getMat4()));
+				}
+				else
+				{
+					node->setInstanceLocalTransform(i, Transform(el.getMat4()));
 				}
-				while(el && instancesCount > 0);
+
+				// Advance
+				el = el.getNextSiblingElement("transform");
+				++i;
+			}
+			while(el && i < instancesCount);
+
+			if(i != instancesCount)
+			{
+				throw ANKI_EXCEPTION("instancesCount does not match "
+					"with transform");
 			}
 
 			// Advance

+ 9 - 5
src/scene/SceneNode.cpp

@@ -9,7 +9,8 @@ namespace anki {
 //==============================================================================
 SceneNode::SceneNode(const char* name_, SceneGraph* scene_, SceneNode* parent)
 	:	Base(parent, scene_->getAllocator()),
-		scene(scene_)
+		scene(scene_),
+		name(getSceneAllocator())
 {
 	ANKI_ASSERT(scene);
 
@@ -27,11 +28,14 @@ SceneNode::SceneNode(const char* name_, SceneGraph* scene_, SceneNode* parent)
 //==============================================================================
 SceneNode::~SceneNode()
 {
-	scene->unregisterNode(this);
-
-	if(getSpatial() && getSpatial()->octreeNode)
+	if(scene)
 	{
-		getSpatial()->octreeNode->removeSceneNode(this);
+		scene->unregisterNode(this);
+
+		if(getSpatial() && getSpatial()->octreeNode)
+		{
+			getSpatial()->octreeNode->removeSceneNode(this);
+		}
 	}
 }
 

+ 2 - 1
testapp/Main.cpp

@@ -251,7 +251,7 @@ void init()
 		Transform(Vec3(1.0), Mat3(Euler(getPi<F32>() / 2, 0.0, 0.0)), 2.0));
 #endif
 
-#if 1
+#if 0
 	StaticGeometryNode* sponzaModel = new StaticGeometryNode(
 		//"data/maps/sponza/sponza_no_bmeshes.mdl",
 		//"data/maps/sponza/sponza.mdl",
@@ -259,6 +259,7 @@ void init()
 
 	(void)sponzaModel;
 #endif
+	scene.load("data/maps/sponza/master.scene");
 
 	//initPhysics();
 

+ 5 - 5
tools/2anki/Main.cpp

@@ -95,8 +95,8 @@ static void parseConfig(int argc, char** argv, Config& config)
 	static const char* usage = R"(Usage: 2anki in_file out_dir [options]
 Options:
 -rpath <string>   : Append a string to the meshes and materials
+-texrpath         : Append a string to the textures paths
 -flipyz           : Flip y with z (For blender exports)
--texpath          : XXX
 )";
 
 	// Parse config
@@ -110,7 +110,7 @@ Options:
 
 	for(int i = 3; i < argc; i++)
 	{
-		if(strcmp(argv[i], "-texpath") == 0)
+		if(strcmp(argv[i], "-texrpath") == 0)
 		{
 			++i;
 
@@ -829,8 +829,8 @@ static void exportScene(const aiScene& scene, Config& config)
 				<< "<model>\n"
 				<< "\t<modelPatches>\n"
 				<< "\t\t<modelPatch>\n"
-				<< "\t\t\t<model>" << config.outDir << meshName 
-				<< ".mdl</model>\n"
+				<< "\t\t\t<mesh>" << config.outDir << meshName 
+				<< ".mesh</mesh>\n"
 				<< "\t\t\t<material>" << config.outDir << mtlName 
 				<< ".mtl</material>\n"
 				<< "\t\t</modelPatch>\n"
@@ -858,7 +858,7 @@ static void exportScene(const aiScene& scene, Config& config)
 			{
 				for(uint32_t b = 0; b < 4; b++)
 				{
-					file << trf[b][a] << " ";
+					file << trf[a][b] << " ";
 				}
 			}