From 138d5b1295676f65e5eacfd958c5e5ba038d2a20 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 16 Dec 2011 01:21:52 +0000 Subject: [PATCH] - added blender scripts for blender 2.5x and 2.6x for g3d import / export --- source/tools/glexemel/g3d_support_b257.py | 729 ++++++++++++++++++++++ source/tools/glexemel/g3d_support_b260.py | 700 +++++++++++++++++++++ 2 files changed, 1429 insertions(+) create mode 100644 source/tools/glexemel/g3d_support_b257.py create mode 100644 source/tools/glexemel/g3d_support_b260.py diff --git a/source/tools/glexemel/g3d_support_b257.py b/source/tools/glexemel/g3d_support_b257.py new file mode 100644 index 00000000..bbabeb60 --- /dev/null +++ b/source/tools/glexemel/g3d_support_b257.py @@ -0,0 +1,729 @@ +########################################################################### +# Glest Model / Texture / UV / Animation Importer and Exporter +# for the Game Glest that u can find http://www.glest.org +# copyright 2005 By Andreas Becker (seltsamuel@yahoo.de) +# +# Updated Jan 2011 by Mark Vejvoda (SoftCoder) to properly import animations +# from G3D into Blender +# +# Started Date: 07 June 2005 Put Public 20 June 2005 +# Ver: 0.01 Beta Exporter ripped off because work in Progress +# Distributed under the GNU PUBLIC LICENSE for www.megaglest.org and glest.org +########################################################################### +#NOTE: +# Copy this Script AND g3d_logo.png into .Blender\scripts +# directory then start inside blender Scripts window +# "Update Menus" after that this Script here is accesible +# as 'Wizards' G3d Fileformat Im/Exporter +#ToDo: +#Exporter Bughunt he will be rejoined next release +#Maybe Integrate UV Painter to Generate UVMaps from Blender Material and procedural Textures +#will be nice to paint wireframe too, so that one can easyly load into Paintprogram and see where to paint +#(Already possible through Blender functions so at the end of the list :-) ) +########################################################################### + +bl_info = { + "name": "MegaGlest G3D Fileformat Import/Exporter", + "description": "Imports and Exports the Glest fileformat V3/V4 (.g3d)", + "author": "Andreas Becker, Mark Vejvoda, William Zheng", + "version": (1,1), + "blender": (2, 5, 7), + "api": 35622, + 'location': 'File > Import-Export', + "warning": '', + "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\ + "Scripts/Import-Export/MegaGlest_G3D", + "tracker_url": "http://projects.blender.org/tracker/index.php?"\ + "func=detail&aid=", + "category": "Import-Export" +} + +""" +Here an explanation of the V4 Format found at www.glest.org +================================ +1. DATA TYPES +================================ +G3D files use the following data types: +uint8: 8 bit unsigned integer +uint16: 16 bit unsigned integer +uint32: 32 bit unsigned integer +float32: 32 bit floating point +================================ +2. OVERALL STRUCTURE +================================ +- File header +- Model header +- Mesh header +- Texture names +- Mesh data +================================ +2. FILE HEADER +================================ +Code: +struct FileHeader{ + uint8 id[3]; + uint8 version; +}; +This header is shared among all the versions of G3D, it identifies this file as a G3D model and provides information of the version. +id: must be "G3D" +version: must be 4, in binary (not '4') +================================ +3. MODEL HEADER +================================ +Code: +struct ModelHeader{ + uint16 meshCount; + uint8 type; +}; +meshCount: number of meshes in this model +type: must be 0 +================================ +4. MESH HEADER +================================ +There is a mesh header for each mesh, there must be "meshCount" headers in a file but they are not consecutive, texture names and mesh data are stored in between. +Code: +struct MeshHeader{ + uint8 name[64]; + uint32 frameCount; + uint32 vertexCount; + uint32 indexCount; + float32 diffuseColor[3]; + float32 specularColor[3]; + float32 specularPower; + float32 opacity; + uint32 properties; + uint32 textures; +}; +name: name of the mesh +frameCount: number of keyframes in this mesh +vertexCount: number of vertices in each frame +indexCount: number of indices in this mesh (the number of triangles is indexCount/3) +diffuseColor: RGB diffuse color +specularColor: RGB specular color (currently unused) +specularPower: specular power (currently unused) +properties: property flags +Code: +enum MeshPropertyFlag{ + mpfTwoSided= 1, + mpfCustomColor= 2, +}; +mpfTwoSided: meshes in this mesh are rendered by both sides, if this flag is not present only "counter clockwise" faces are rendered +mpfCustomColor: alpha in this model is replaced by a custom color, usually the player color +textures: texture flags, only 0x1 is currently used, indicating that there is a diffuse texture in this mesh. +================================ +4. TEXTURE NAMES +================================ +A list of uint8[64] texture name values. One for each texture in the mesh. If there are no textures in the mesh no texture names are present. In practice since Glest only uses 1 texture for each mesh the number of texture names should be 0 or 1. +================================ +5. MESH DATA +================================ +After each mesh header and texture names the mesh data is placed. +vertices: frameCount * vertexCount * 3, float32 values representing the x, y, z vertex coords for all frames +normals: frameCount * vertexCount * 3, float32 values representing the x, y, z normal coords for all frames +texture coords: vertexCount * 2, float32 values representing the s, t tex coords for all frames (only present if the mesh has 1 texture at least) +indices: indexCount, uint32 values representing the indices +""" +########################################################################### +# Importing Structures needed (must later verify if i need them really all) +########################################################################### +import sys, struct, string, types +from types import * +import os +from os import path +from os.path import dirname + +import bpy +from bpy.props import StringProperty +from io_utils import ImportHelper, ExportHelper +import mathutils +import math + +import re +from string import * +from struct import * + + +########################################################################### +# Variables that are better Global to handle +########################################################################### +imported = [] #List of all imported Objects +toexport = [] #List of Objects to export (actually only meshes) +sceneID = None #Points to the active Blender Scene + +########################################################################### +# Declaring Structures of G3D Format +########################################################################### +class G3DHeader: #Read first 4 Bytes of file should be G3D + Versionnumber + binary_format = "<3cB" + def __init__(self, fileID): + temp = fileID.read(struct.calcsize(self.binary_format)) + data = struct.unpack(self.binary_format,temp) + + #print(type(data)); print(repr(data)) + #self.id = bytes(data[0]).decode() + bytes(data[1]).decode() + bytes(data[2]).decode() + self.id = ''.join(item.decode() for item in data[0:3]) + #self.id = data[0:3] + self.version = data[3] + +class G3DModelHeaderv3: #Read Modelheader in V3 there is only the number of Meshes in file + binary_format = "