Browse Source

Exporter additions

Panagiotis Christopoulos Charitos 11 years ago
parent
commit
8a8faa5485
7 changed files with 147 additions and 169 deletions
  1. 36 6
      src/script/Math.cpp
  2. 21 3
      src/script/Math.xml
  3. 47 0
      src/script/Scene.cpp
  4. 3 0
      src/script/Scene.xml
  5. 1 1
      thirdparty
  6. 39 15
      tools/scene/Exporter.cpp
  7. 0 144
      tools/scene/ExporterMesh.cpp

+ 36 - 6
src/script/Math.cpp

@@ -38,7 +38,14 @@ static inline int pwrapVec2Ctor(lua_State* l)
 	void* voidp;
 	void* voidp;
 	(void)voidp;
 	(void)voidp;
 	
 	
-	LuaBinder::checkArgsCount(l, 0);
+	LuaBinder::checkArgsCount(l, 2);
+	
+	// Pop arguments
+	F32 arg0;
+	if(LuaBinder::checkNumber(l, 1, arg0)) return -1;
+	
+	F32 arg1;
+	if(LuaBinder::checkNumber(l, 2, arg1)) return -1;
 	
 	
 	// Create user data
 	// Create user data
 	void* inst = LuaBinder::luaAlloc(l, sizeof(Vec2));
 	void* inst = LuaBinder::luaAlloc(l, sizeof(Vec2));
@@ -48,7 +55,7 @@ static inline int pwrapVec2Ctor(lua_State* l)
 		return -1;
 		return -1;
 	}
 	}
 	
 	
-	::new(inst) Vec2();
+	::new(inst) Vec2(arg0, arg1);
 	
 	
 	voidp = lua_newuserdata(l, sizeof(UserData));
 	voidp = lua_newuserdata(l, sizeof(UserData));
 	ud = static_cast<UserData*>(voidp);
 	ud = static_cast<UserData*>(voidp);
@@ -849,7 +856,17 @@ static inline int pwrapVec3Ctor(lua_State* l)
 	void* voidp;
 	void* voidp;
 	(void)voidp;
 	(void)voidp;
 	
 	
-	LuaBinder::checkArgsCount(l, 0);
+	LuaBinder::checkArgsCount(l, 3);
+	
+	// Pop arguments
+	F32 arg0;
+	if(LuaBinder::checkNumber(l, 1, arg0)) return -1;
+	
+	F32 arg1;
+	if(LuaBinder::checkNumber(l, 2, arg1)) return -1;
+	
+	F32 arg2;
+	if(LuaBinder::checkNumber(l, 3, arg2)) return -1;
 	
 	
 	// Create user data
 	// Create user data
 	void* inst = LuaBinder::luaAlloc(l, sizeof(Vec3));
 	void* inst = LuaBinder::luaAlloc(l, sizeof(Vec3));
@@ -859,7 +876,7 @@ static inline int pwrapVec3Ctor(lua_State* l)
 		return -1;
 		return -1;
 	}
 	}
 	
 	
-	::new(inst) Vec3();
+	::new(inst) Vec3(arg0, arg1, arg2);
 	
 	
 	voidp = lua_newuserdata(l, sizeof(UserData));
 	voidp = lua_newuserdata(l, sizeof(UserData));
 	ud = static_cast<UserData*>(voidp);
 	ud = static_cast<UserData*>(voidp);
@@ -1736,7 +1753,20 @@ static inline int pwrapVec4Ctor(lua_State* l)
 	void* voidp;
 	void* voidp;
 	(void)voidp;
 	(void)voidp;
 	
 	
-	LuaBinder::checkArgsCount(l, 0);
+	LuaBinder::checkArgsCount(l, 4);
+	
+	// Pop arguments
+	F32 arg0;
+	if(LuaBinder::checkNumber(l, 1, arg0)) return -1;
+	
+	F32 arg1;
+	if(LuaBinder::checkNumber(l, 2, arg1)) return -1;
+	
+	F32 arg2;
+	if(LuaBinder::checkNumber(l, 3, arg2)) return -1;
+	
+	F32 arg3;
+	if(LuaBinder::checkNumber(l, 4, arg3)) return -1;
 	
 	
 	// Create user data
 	// Create user data
 	void* inst = LuaBinder::luaAlloc(l, sizeof(Vec4));
 	void* inst = LuaBinder::luaAlloc(l, sizeof(Vec4));
@@ -1746,7 +1776,7 @@ static inline int pwrapVec4Ctor(lua_State* l)
 		return -1;
 		return -1;
 	}
 	}
 	
 	
-	::new(inst) Vec4();
+	::new(inst) Vec4(arg0, arg1, arg2, arg3);
 	
 	
 	voidp = lua_newuserdata(l, sizeof(UserData));
 	voidp = lua_newuserdata(l, sizeof(UserData));
 	ud = static_cast<UserData*>(voidp);
 	ud = static_cast<UserData*>(voidp);

+ 21 - 3
src/script/Math.xml

@@ -13,7 +13,12 @@ namespace anki {]]></head>
 
 
 	<classes>
 	<classes>
 		<class name="Vec2">
 		<class name="Vec2">
-			<constructor></constructor>
+			<constructor>
+				<args>
+					<arg>F32</arg>
+					<arg>F32</arg>
+				</args>
+			</constructor>
 			<methods>
 			<methods>
 				<method name="getX">
 				<method name="getX">
 					<overrideCall>F32 ret = (*self).x();</overrideCall>
 					<overrideCall>F32 ret = (*self).x();</overrideCall>
@@ -107,7 +112,13 @@ namespace anki {]]></head>
 			</methods>
 			</methods>
 		</class>
 		</class>
 		<class name="Vec3">
 		<class name="Vec3">
-			<constructor></constructor>
+			<constructor>
+				<args>
+					<arg>F32</arg>
+					<arg>F32</arg>
+					<arg>F32</arg>
+				</args>
+			</constructor>
 			<methods>
 			<methods>
 				<method name="getX">
 				<method name="getX">
 					<overrideCall>F32 ret = (*self).x();</overrideCall>
 					<overrideCall>F32 ret = (*self).x();</overrideCall>
@@ -213,7 +224,14 @@ namespace anki {]]></head>
 			</methods>
 			</methods>
 		</class>
 		</class>
 		<class name="Vec4">
 		<class name="Vec4">
-			<constructor></constructor>
+			<constructor>
+				<args>
+					<arg>F32</arg>
+					<arg>F32</arg>
+					<arg>F32</arg>
+					<arg>F32</arg>
+				</args>
+			</constructor>
 			<methods>
 			<methods>
 				<method name="getX">
 				<method name="getX">
 					<overrideCall>F32 ret = (*self).x();</overrideCall>
 					<overrideCall>F32 ret = (*self).x();</overrideCall>

+ 47 - 0
src/script/Scene.cpp

@@ -1143,6 +1143,52 @@ static int wrapSceneNodegetLightComponent(lua_State* l)
 	return 0;
 	return 0;
 }
 }
 
 
+//==============================================================================
+/// Pre-wrap method SceneNode::tryGetComponent<LensFlareComponent>.
+static inline int pwrapSceneNodegetLensFlareComponent(lua_State* l)
+{
+	UserData* ud;
+	(void)ud;
+	void* voidp;
+	(void)voidp;
+	
+	LuaBinder::checkArgsCount(l, 1);
+	
+	// Get "this" as "self"
+	if(LuaBinder::checkUserData(l, 1, classnameSceneNode, -2220074417980276571, ud)) return -1;
+	SceneNode* self = static_cast<SceneNode*>(ud->m_data);
+	ANKI_ASSERT(self != nullptr);
+	
+	// Call the method
+	LensFlareComponent* ret = self->tryGetComponent<LensFlareComponent>();
+	
+	// Push return value
+	if(ANKI_UNLIKELY(ret == nullptr))
+	{
+		lua_pushstring(l, "Glue code returned nullptr");
+		return -1;
+	}
+	
+	voidp = lua_newuserdata(l, sizeof(UserData));
+	ud = static_cast<UserData*>(voidp);
+	luaL_setmetatable(l, "LensFlareComponent");
+	ud->m_data = static_cast<void*>(ret);
+	ud->m_gc = false;
+	ud->m_sig = -2019248835133422777;
+	
+	return 1;
+}
+
+//==============================================================================
+/// Wrap method SceneNode::tryGetComponent<LensFlareComponent>.
+static int wrapSceneNodegetLensFlareComponent(lua_State* l)
+{
+	int res = pwrapSceneNodegetLensFlareComponent(l);
+	if(res >= 0) return res;
+	lua_error(l);
+	return 0;
+}
+
 //==============================================================================
 //==============================================================================
 /// Wrap class SceneNode.
 /// Wrap class SceneNode.
 static inline void wrapSceneNode(lua_State* l)
 static inline void wrapSceneNode(lua_State* l)
@@ -1152,6 +1198,7 @@ static inline void wrapSceneNode(lua_State* l)
 	LuaBinder::pushLuaCFuncMethod(l, "addChild", wrapSceneNodeaddChild);
 	LuaBinder::pushLuaCFuncMethod(l, "addChild", wrapSceneNodeaddChild);
 	LuaBinder::pushLuaCFuncMethod(l, "getMoveComponent", wrapSceneNodegetMoveComponent);
 	LuaBinder::pushLuaCFuncMethod(l, "getMoveComponent", wrapSceneNodegetMoveComponent);
 	LuaBinder::pushLuaCFuncMethod(l, "getLightComponent", wrapSceneNodegetLightComponent);
 	LuaBinder::pushLuaCFuncMethod(l, "getLightComponent", wrapSceneNodegetLightComponent);
+	LuaBinder::pushLuaCFuncMethod(l, "getLensFlareComponent", wrapSceneNodegetLensFlareComponent);
 	lua_settop(l, 0);
 	lua_settop(l, 0);
 }
 }
 
 

+ 3 - 0
src/script/Scene.xml

@@ -161,6 +161,9 @@ static SceneGraph* getSceneGraph(lua_State* l)
 				<method name="tryGetComponent&lt;LightComponent&gt;" alias="getLightComponent">
 				<method name="tryGetComponent&lt;LightComponent&gt;" alias="getLightComponent">
 					<return>LightComponent*</return>
 					<return>LightComponent*</return>
 				</method>
 				</method>
+				<method name="tryGetComponent&lt;LensFlareComponent&gt;" alias="getLensFlareComponent">
+					<return>LensFlareComponent*</return>
+				</method>
 			</methods>
 			</methods>
 		</class>
 		</class>
 		<class name="ModelNode">
 		<class name="ModelNode">

+ 1 - 1
thirdparty

@@ -1 +1 @@
-Subproject commit f29f77fc44ed665e968c6db25c83c9e4ff21184d
+Subproject commit 823029c11b604fd9221391791d8efd177574a627

+ 39 - 15
tools/scene/Exporter.cpp

@@ -131,11 +131,9 @@ void Exporter::writeNodeTransform(
 	pos[1] = m[1][3];
 	pos[1] = m[1][3];
 	pos[2] = m[2][3];
 	pos[2] = m[2][3];
 
 
-	file << "pos = Vec4.new()\n";
-	file << "pos:setAll(" << pos[0] << ", " << pos[1] << ", " << pos[2] 
-		<< ", 0)\n";
 	file << node 
 	file << node 
-		<< ":getSceneNodeBase():getMoveComponent():setLocalOrigin(pos)\n";
+		<< ":getSceneNodeBase():getMoveComponent():setLocalOrigin(Vec4.new(" 
+		<< pos[0] << ", " << pos[1] << ", " << pos[2] << ", 0))\n";
 
 
 	file << "rot = Mat3x4.new()\n";
 	file << "rot = Mat3x4.new()\n";
 	file << "rot:setAll(";
 	file << "rot:setAll(";
@@ -620,21 +618,17 @@ void Exporter::exportLight(const aiLight& light)
 	file << "lcomp = node:getSceneNodeBase():getLightComponent()\n";
 	file << "lcomp = node:getSceneNodeBase():getLightComponent()\n";
 
 
 	// Colors
 	// Colors
-	file << "col = Vec4.new()\n"
-		<< "col:setAll("
+	file << "lcomp:setDiffuseColor(Vec4.new("
 		<< light.mColorDiffuse[0] << ", " 
 		<< light.mColorDiffuse[0] << ", " 
 		<< light.mColorDiffuse[1] << ", " 
 		<< light.mColorDiffuse[1] << ", " 
 		<< light.mColorDiffuse[2] << ", " 
 		<< light.mColorDiffuse[2] << ", " 
-		<< "1)\n"
-		<< "lcomp:setDiffuseColor(col)\n" ;
+		<< "1))\n";
 
 
-	file << "col = Vec4.new()\n"
-		<< "col:setAll("
+	file << "lcomp:setSpecularColor(Vec4.new("
 		<< light.mColorSpecular[0] << ", " 
 		<< light.mColorSpecular[0] << ", " 
 		<< light.mColorSpecular[1] << ", " 
 		<< light.mColorSpecular[1] << ", " 
 		<< light.mColorSpecular[2] << ", " 
 		<< light.mColorSpecular[2] << ", " 
-		<< "1)\n"
-		<< "lcomp:setSpecularColor(col)\n" ;
+		<< "1))\n";
 
 
 	// Geometry
 	// Geometry
 	aiVector3D direction(0.0, 0.0, 1.0);
 	aiVector3D direction(0.0, 0.0, 1.0);
@@ -699,6 +693,38 @@ void Exporter::exportLight(const aiLight& light)
 	{
 	{
 		file << "node:loadLensFlare(\"" << light.mLensFlare << "\")\n";
 		file << "node:loadLensFlare(\"" << light.mLensFlare << "\")\n";
 	}
 	}
+
+	bool lfCompRetrieved = false;
+
+	if(light.mLensFlareFirstSpriteSize != aiVector3D(0, 0, 0))
+	{
+		if(!lfCompRetrieved)
+		{
+			file << "lfcomp = node:getSceneNodeBase():"
+				<< "getLensFlareComponent()\n";
+			lfCompRetrieved = true;
+		}
+
+		file << "lfcomp:setFirstFlareSize(Vec2.new(" 
+			<< light.mLensFlareFirstSpriteSize[0] << ", " 
+			<< light.mLensFlareFirstSpriteSize[1] << "))\n";
+	}
+
+	if(light.mLensFlareColor != aiColor4D(0, 0, 0, 0))
+	{
+		if(!lfCompRetrieved)
+		{
+			file << "lfcomp = node:getSceneNodeBase():"
+				<< "getLensFlareComponent()\n";
+			lfCompRetrieved = true;
+		}
+
+		file << "lfcomp:setColorMultiplier(Vec4.new(" 
+			<< light.mLensFlareColor.r << ", " 
+			<< light.mLensFlareColor.g << ", " 
+			<< light.mLensFlareColor.b << ", " 
+			<< light.mLensFlareColor.a << "))\n";
+	}
 }
 }
 
 
 //==============================================================================
 //==============================================================================
@@ -905,12 +931,10 @@ void Exporter::exportAll()
 	std::ofstream& file = m_sceneFile;
 	std::ofstream& file = m_sceneFile;
 
 
 	file << "local scene = getSceneGraph()\n"
 	file << "local scene = getSceneGraph()\n"
-		<< "local pos\n"
 		<< "local rot\n"
 		<< "local rot\n"
 		<< "local node\n"
 		<< "local node\n"
 		<< "local inst\n"
 		<< "local inst\n"
-		<< "local lcomp\n"
-		<< "local col\n";
+		<< "local lcomp\n";
 
 
 	//
 	//
 	// Get all node/model data
 	// Get all node/model data

+ 0 - 144
tools/scene/ExporterMesh.cpp

@@ -190,150 +190,6 @@ void Exporter::exportMesh(
 	const aiMesh& mesh, 
 	const aiMesh& mesh, 
 	const aiMatrix4x4* transform) const
 	const aiMatrix4x4* transform) const
 {
 {
-#if 0
-	std::string name = getMeshName(mesh);
-	std::fstream file;
-	LOGI("Exporting mesh %s", name.c_str());
-
-	uint32_t vertsCount = mesh.mNumVertices;
-
-	// Open file
-	file.open(m_outputDirectory + name + ".ankimesh",
-		std::ios::out | std::ios::binary);
-
-	// Write magic word
-	file.write("ANKIMESH", 8);
-
-	// Write the name
-	uint32_t size = name.size();
-	file.write((char*)&size, sizeof(uint32_t));
-	file.write(&name[0], size);
-
-	// Write positions
-	file.write((char*)&vertsCount, sizeof(uint32_t));
-	for(uint32_t i = 0; i < mesh.mNumVertices; i++)
-	{
-		aiVector3D pos = mesh.mVertices[i];
-
-		// Transform
-		if(transform)
-		{
-			pos = (*transform) * pos;
-		}
-
-		// flip 
-		if(m_flipyz)
-		{
-			static const aiMatrix4x4 toLefthanded(
-				1, 0, 0, 0, 
-				0, 0, 1, 0, 
-				0, -1, 0, 0, 
-				0, 0, 0, 1);
-
-			pos = toLefthanded * pos;
-		}
-
-		for(uint32_t j = 0; j < 3; j++)
-		{
-			file.write((char*)&pos[j], sizeof(float));
-		}
-	}
-
-	// Write the indices
-	file.write((char*)&mesh.mNumFaces, sizeof(uint32_t));
-	for(uint32_t i = 0; i < mesh.mNumFaces; i++)
-	{
-		const aiFace& face = mesh.mFaces[i];
-		
-		if(face.mNumIndices != 3)
-		{
-			ERROR("For some reason the assimp didn't triangulate");
-		}
-
-		for(uint32_t j = 0; j < 3; j++)
-		{
-			uint32_t index = face.mIndices[j];
-			file.write((char*)&index, sizeof(uint32_t));
-		}
-	}
-
-	// Write the tex coords
-	file.write((char*)&vertsCount, sizeof(uint32_t));
-
-	// For all channels
-	for(uint32_t ch = 0; ch < mesh.GetNumUVChannels(); ch++)
-	{
-		if(mesh.mNumUVComponents[ch] != 2)
-		{
-			ERROR("Incorrect number of UV components");
-		}
-
-		// For all tex coords of this channel
-		for(uint32_t i = 0; i < vertsCount; i++)
-		{
-			aiVector3D texCoord = mesh.mTextureCoords[ch][i];
-
-			for(uint32_t j = 0; j < 2; j++)
-			{
-				file.write((char*)&texCoord[j], sizeof(float));
-			}
-		}
-	}
-
-	// Write bone weigths count
-	if(mesh.HasBones())
-	{
-#if 0
-		// Write file
-		file.write((char*)&vertsCount, sizeof(uint32_t));
-
-		// Gather info for each vertex
-		std::vector<Vw> vw;
-		vw.resize(vertsCount);
-		memset(&vw[0], 0, sizeof(Vw) * vertsCount);
-
-		// For all bones
-		for(uint32_t i = 0; i < mesh.mNumBones; i++)
-		{
-			const aiBone& bone = *mesh.mBones[i];
-
-			// for every weights of the bone
-			for(uint32_t j = 0; j < bone.mWeightsCount; j++)
-			{
-				const aiVertexWeight& weigth = bone.mWeights[j];
-
-				// Sanity check
-				if(weight.mVertexId >= vertCount)
-				{
-					ERROR("Out of bounds vert ID");
-				}
-
-				Vm& a = vm[weight.mVertexId];
-
-				// Check out of bounds
-				if(a.bonesCount >= MAX_BONES_PER_VERTEX)
-				{
-					LOGW("Too many bones for vertex %d", weigth.mVertexId);
-					continue;
-				}
-
-				// Write to vertex
-				a.boneIds[a.bonesCount] = i;
-				a.weigths[a.bonesCount] = weigth.mWeigth;
-				++a.bonesCount;
-			}
-
-			// Now write the file
-		}
-#endif
-	}
-	else
-	{
-		uint32_t num = 0;
-		file.write((char*)&num, sizeof(uint32_t));
-	}
-#endif
-
 	std::string name = mesh.mName.C_Str();
 	std::string name = mesh.mName.C_Str();
 	std::fstream file;
 	std::fstream file;
 	LOGI("Exporting mesh %s", name.c_str());
 	LOGI("Exporting mesh %s", name.c_str());