Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
def write_obj(filepath): out = file(filepath, 'w') sce = bpy.data.scenes.active ob = sce.objects.active mesh = ob.getData(mesh=1) # Anzahl der Vertices in die Datei schreiben out.write (struct.pack('I', GetNumVertices())) # Vertices in die Datei schreiben for vert in mesh.verts: # Positionsvektor in die Datei schreiben out.write(struct.pack('f', vert.co.x)) out.write(struct.pack('f', vert.co.y)) out.write(struct.pack('f', vert.co.z)) # Normalenvektor in die Datei schreiben out.write(struct.pack('f', vert.no.x)) out.write(struct.pack('f', vert.no.y)) out.write(struct.pack('f', vert.no.z)) # Anzahl der Indices in die Datei schreiben out.write (struct.pack('I', GetNumIndices())) #Indices in die Datei schreiben for face in mesh.faces: # 4-ecke durchgehen # Indices in die Datei schreiben out.write (struct.pack('H', face.v[0].index)) out.write (struct.pack('H', face.v[1].index)) out.write (struct.pack('H', face.v[2].index)) out.write (struct.pack('H', face.v[0].index)) out.write (struct.pack('H', face.v[2].index)) out.write (struct.pack('H', face.v[3].index)) out.close() Blender.Window.FileSelector(write_obj, "Export") |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
// Anzahl der Vertices einlesen Model.read (&GLOBALS::NumVertices, sizeof(unsigned int)); // Vertices laden for (unsigned int Vertex=0; Vertex < GLOBALS::NumVertices; ++Vertex) { // Positionsvektor einlesen Model.read (&v.Pos.x, sizeof(float)); Model.read (&v.Pos.z, sizeof(float)); Model.read (&v.Pos.y, sizeof(float)); // Normalenvektor einlesen Model.read (&v.Normal.x, sizeof(float)); Model.read (&v.Normal.z, sizeof(float)); Model.read (&v.Normal.y, sizeof(float)); GLOBALS::VB->SetVertices (&v, 1, Vertex); } // Anzahl der Indices einlesen Model.read (&GLOBALS::NumIndices, sizeof (unsigned int)); // Indices laden for (unsigned int Index=0; Index < GLOBALS::NumIndices; ++Index) { Model.read (&i, sizeof(WORD)); GLOBALS::IB->SetIndices (&i, 1, Index); } |
Werbeanzeige