Przeglądaj źródła

exporter and IS shadowmap bug

Panagiotis Christopoulos Charitos 12 lat temu
rodzic
commit
fb142da386

+ 30 - 0
include/anki/util/Filesystem.h

@@ -11,6 +11,36 @@ namespace anki {
 /// @addtogroup filesystem
 /// @{
 
+/// XXX
+class File
+{
+public:
+	enum
+	{
+		READ,
+		WRITE,
+		APPEND,
+		BINARY
+	};
+
+	void open(const char* filename, U8 openFlags);
+
+	PtrSize read(void* buff, PtrSize size);
+
+	PtrSize write(void* buff, PtrSize size);
+
+public:
+	enum
+	{
+		C_FILE,
+		ZIP_FILE
+	};
+
+	U8 openFlags; ///< Mainly for assertions
+	void* file = nullptr; ///< A native type
+	U8 fileType;
+};
+
 /// Get file extension
 /// @param[in] filename The file to open
 /// @return nullptr on failure and if the dot is the last character

+ 0 - 7
src/renderer/Is.cpp

@@ -727,13 +727,6 @@ void Is::lightPass()
 	// Sync
 	threadPool.waitForAllJobsToFinish();
 
-	// Write the shadomap IDs
-	for(U i = 0; i < visibleSpotTexLightsCount; i++)
-	{
-		jobs[0].spotTexLights[i].diffuseColorShadowmapId.w() = 
-			(F32)shadowmapLayers[i];
-	}
-
 	// Write the light count for each tile
 	for(U y = 0; y < TILES_Y_COUNT; y++)
 	{

+ 60 - 0
src/util/Filesystem.cpp

@@ -6,6 +6,66 @@
 
 namespace anki {
 
+//==============================================================================
+// File                                                                        =
+//==============================================================================
+
+//==============================================================================
+void File::open(const char* filename, U8 flags)
+{
+	const char* openMode;
+
+	if(flags & READ)
+	{
+		openMode = "r";
+	}
+	else if(flags & WRITE)
+	{
+		openMode = "w";
+	}
+	else if(flags & APPEND)
+	{
+		openMode = "a+";
+	}
+	else
+	{
+		ANKI_ASSERT(0);
+		openMode = nullptr;
+	}
+	openFlags = flags;
+
+	// Open
+	file = (FILE*)fopen(filename, openMode);
+	if(!file)
+	{
+		throw ANKI_EXCEPTION("Failed to open file");
+	}
+	fileType = C_FILE;
+}
+
+//==============================================================================
+PtrSize File::read(void* buff, PtrSize size)
+{
+	ANKI_ASSERT(file);
+	ANKI_ASSERT(buff);
+	PtrSize readSize = 0;
+
+	switch(fileType)
+	{
+	case C_FILE:
+		readSize = fread(buff, 1, size, (FILE*)file);
+		break;
+	case ZIP_FILE:
+		break;
+	}
+
+	return readSize;
+}
+
+//==============================================================================
+// Functions                                                                   =
+//==============================================================================
+
 //==============================================================================
 const char* getFileExtension(const char* filename)
 {

+ 2 - 2
testapp/Main.cpp

@@ -251,11 +251,11 @@ void init()
 		0.7));
 #endif
 
-#if 0
+#if 1
 	StaticGeometryNode* sponzaModel = new StaticGeometryNode(
 		//"data/maps/sponza/sponza_no_bmeshes.mdl",
 		//"data/maps/sponza/sponza.mdl",
-		"data/maps/sponza_test/Mesh_267.mdl",
+		"data/maps/sponza/static_geometry.mdl",
 		"sponza", &scene);
 
 	(void)sponzaModel;

+ 27 - 8
tools/2anki/Main.cpp

@@ -48,6 +48,22 @@ std::string replaceAllString(const std::string& str, const std::string& from,
 	return out;
 }
 
+//==============================================================================
+std::string getFilename(const std::string& path)
+{
+	assert(path);
+
+	std::string out;
+
+	const size_t last = path.find_last_of("/");
+	if(std::string::npos != last)
+	{
+		out.insert(out.end(), path.begin() + last + 1, path.end());
+	}
+
+	return out;
+}
+
 //==============================================================================
 struct Config
 {
@@ -385,7 +401,7 @@ void exportMaterial(const aiScene& scene, const aiMaterial& mtl,
 	aiString path;
 	if(mtl.GetTexture(aiTextureType_DIFFUSE, 0, &path) == AI_SUCCESS)
 	{
-		diffTex = path.C_Str();
+		diffTex = getFilename(path.C_Str());
 	}
 	else
 	{
@@ -397,7 +413,7 @@ void exportMaterial(const aiScene& scene, const aiMaterial& mtl,
 	{	
 		if(mtl.GetTexture(aiTextureType_NORMALS, 0, &path) == AI_SUCCESS)
 		{
-			normTex = path.C_Str();
+			normTex = getFilename(path.C_Str());
 		}
 		else
 		{
@@ -655,12 +671,15 @@ void exportNode(
 
 		exportMaterial(scene, *scene.mMaterials[mesh.mMaterialIndex], config);
 
-		file << "\t<modelPatch>\n";
-		file << "\t\t<mesh>" << config.outDir << name << ".mesh\n";
 		aiString ainame;
 		scene.mMaterials[mesh.mMaterialIndex]->Get(AI_MATKEY_NAME, ainame);
-		file << "\t\t<material>" << ainame.C_Str() << ".mtl\n";
-		file << "\t</modelPatch>\n";
+
+		file << "\t\t<modelPatch>\n"
+			<< "\t\t\t<mesh>" << config.rpath << config.outDir 
+			<< name << ".mesh</mesh>\n"
+			<< "\t\t\t<material>" << config.rpath << ainame.C_Str() 
+			<< ".mtl</material>\n"
+			<< "\t\t</modelPatch>\n";
 	}
 	
 	// Go to children
@@ -689,9 +708,9 @@ void exportScene(const aiScene& scene, const Config& config)
 	std::fstream modelFile;
 	modelFile.open(config.outDir + "static_geometry.mdl", std::ios::out);
 	modelFile << xmlHeader << "\n";
-	modelFile << "<model>\n";
+	modelFile << "<model>\n\t<modelPatches>\n";
 	exportNode(scene, scene.mRootNode, config, modelFile);
-	modelFile << "</model>\n";
+	modelFile << "\t</modelPatches>\n</model>\n";
 
 	// End
 	file << "</scene>\n";