Browse Source

fix 3d model save and load functions

Kolja Strohm 2 years ago
parent
commit
aafec46e9d
3 changed files with 10 additions and 6 deletions
  1. 4 0
      M3Datei.cpp
  2. 1 1
      Mat4.h
  3. 5 5
      ObjFile.cpp

+ 4 - 0
M3Datei.cpp

@@ -310,6 +310,10 @@ bool M3Datei::removeModel( const char* name )
                 removedLength = modelPos->get( i + 1 ) - modelPos->get( i );
                 removedLength = modelPos->get( i + 1 ) - modelPos->get( i );
                 offset += removedLength;
                 offset += removedLength;
             }
             }
+            else
+            {
+                removedLength = d.getSize() - removedPosition;
+            }
         }
         }
     }
     }
     d.setLPosition( startPosition, 0 );
     d.setLPosition( startPosition, 0 );

+ 1 - 1
Mat4.h

@@ -65,7 +65,7 @@ namespace Framework
             result.x = elements[ 0 ][ 0 ] * r.x + elements[ 0 ][ 1 ] * r.y + elements[ 0 ][ 2 ] * r.z + elements[ 0 ][ 3 ];
             result.x = elements[ 0 ][ 0 ] * r.x + elements[ 0 ][ 1 ] * r.y + elements[ 0 ][ 2 ] * r.z + elements[ 0 ][ 3 ];
             result.y = elements[ 1 ][ 0 ] * r.x + elements[ 1 ][ 1 ] * r.y + elements[ 1 ][ 2 ] * r.z + elements[ 1 ][ 3 ];
             result.y = elements[ 1 ][ 0 ] * r.x + elements[ 1 ][ 1 ] * r.y + elements[ 1 ][ 2 ] * r.z + elements[ 1 ][ 3 ];
             result.z = elements[ 2 ][ 0 ] * r.x + elements[ 2 ][ 1 ] * r.y + elements[ 2 ][ 2 ] * r.z + elements[ 2 ][ 3 ];
             result.z = elements[ 2 ][ 0 ] * r.x + elements[ 2 ][ 1 ] * r.y + elements[ 2 ][ 2 ] * r.z + elements[ 2 ][ 3 ];
-            return  result;
+            return result;
         }
         }
 
 
         Vec3< T > mult0( const Vec3< T > &r ) const
         Vec3< T > mult0( const Vec3< T > &r ) const

+ 5 - 5
ObjFile.cpp

@@ -44,7 +44,7 @@ void ObjFile::readModel(Model3DData* zTarget)
 	Text* line = file.leseZeile();
 	Text* line = file.leseZeile();
 	while (line)
 	while (line)
 	{
 	{
-		if (line->positionVon("o "))
+		if (line->positionVon("o ") == 0)
 		{
 		{
 			line->release();
 			line->release();
 			break;;
 			break;;
@@ -80,7 +80,7 @@ void ObjFile::readModel(Model3DData* zTarget)
 		if (line->positionVon("f ") == 0)
 		if (line->positionVon("f ") == 0)
 		{
 		{
 			// only triangulated meshes ares supported
 			// only triangulated meshes ares supported
-			Text* p1 = line->getTeilText(3, line->positionVon(" ", 1));
+			Text* p1 = line->getTeilText(2, line->positionVon(" ", 1));
 			Text* p2 = line->getTeilText(line->positionVon(" ", 1) + 1, line->positionVon(" ", 2));
 			Text* p2 = line->getTeilText(line->positionVon(" ", 1) + 1, line->positionVon(" ", 2));
 			Text* p3 = line->getTeilText(line->positionVon(" ", 2) + 1);
 			Text* p3 = line->getTeilText(line->positionVon(" ", 2) + 1);
 			indices.add(parseIndex(p1));
 			indices.add(parseIndex(p1));
@@ -102,7 +102,7 @@ void ObjFile::readModel(Model3DData* zTarget)
 		current.normal = normals.get(index.z - 1);
 		current.normal = normals.get(index.z - 1);
 		current.knochenId = 0;
 		current.knochenId = 0;
 		int ind = 0;
 		int ind = 0;
-		for (Vertex3D& other : modelData)
+		for (const Vertex3D& other : modelData)
 		{
 		{
 			if (other.pos == current.pos && other.tPos == current.tPos && other.normal == current.normal)
 			if (other.pos == current.pos && other.tPos == current.tPos && other.normal == current.normal)
 				break;
 				break;
@@ -114,7 +114,7 @@ void ObjFile::readModel(Model3DData* zTarget)
 	}
 	}
 	Vertex3D* vertexData = new Vertex3D[modelData.getEintragAnzahl()];
 	Vertex3D* vertexData = new Vertex3D[modelData.getEintragAnzahl()];
 	int ind = 0;
 	int ind = 0;
-	for (Vertex3D& vertex : modelData)
+	for (const Vertex3D& vertex : modelData)
 		vertexData[ind++] = vertex;
 		vertexData[ind++] = vertex;
 	zTarget->setVertecies(vertexData, modelData.getEintragAnzahl());
 	zTarget->setVertecies(vertexData, modelData.getEintragAnzahl());
 	Polygon3D* polygon = new Polygon3D();
 	Polygon3D* polygon = new Polygon3D();
@@ -129,7 +129,7 @@ bool ObjFile::loadModel(const char* name, Model3DData* zTarget)
 	Text* line = file.leseZeile();
 	Text* line = file.leseZeile();
 	while (line)
 	while (line)
 	{
 	{
-		if (line->positionVon("o ") == 0 && line->positionVon(name) == 2 && line->getLength() == textLength(name) + 2)
+		if (line->positionVon("o ") == 0 && line->positionVon(name) == 2 && line->getLength() == textLength(name) + 3)
 		{
 		{
 			readModel(zTarget);
 			readModel(zTarget);
 			line->release();
 			line->release();