| Developers > Gmdc Importer / Exporter Interface | ||
| Emily | ||
Member since: 2006-04-17 Posts: 361 | As you might know, SimPE 0.38 features a new Plugin Infrastructure for Gmdc Importers and Exporters. The default SimPE will be installed with an .obj Importer/Expoerter and an .x Exporter. But Developers can extend the capabilities of SimPE with their own Importers/Exporters. Since the Interfaces should be pretty much stable, we decided to publish the API for it. | |
| Emily | ||
Member since: 2006-04-17 Posts: 361 | What you need:
Getting started: After you installed everything you need, you should start a new (Library-)Project in your IDE (=Devel. Environment). Since this File is going to be a SimPE Plugin, you have to add References to some SimPE Files. Those Files are:
Testing your Im/Exporter. You can test Your work directly with SimPe. Just make sure the compiled .dll File ends on .exporter.dll. Then copy that File into the Plugins Directory of SimPE and (re)start SimPE. Now your Exporter should be listed in the FileType DropDown of the Export... Dialog for the Gmdc Plugin View. When you have Referenced all those Files, you are ready to start... | |
| Emily | ||
Member since: 2006-04-17 Posts: 361 | Creating an Exporter: After you have a basic Project, you can start writing your Exporter. Create a new Source File and copy this Code. (You can only use this Code if you develop in c#, for all other Languages, you have to addapt the Code!!!) /*************************************************************************** * Copyright (C) 2005 by Ambertation * * quaxi@ambertation.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ using System; using System.IO; using System.Globalization; using SimPe.Plugin.Gmdc; namespace SimPe.Plugin.Gmdc.Exporter { /// <summary> /// This class provides the functionality to Export Data to the .* FileFormat /// </summary> public class GmdcExportTo3D : AbstractGmdcExporter { /// <summary> /// Constructor /// </summary> /// <param name="gmdc">The Gmdc File the Export is based on</param> /// <param name="groups">The list of Groups you want to export</param> public GmdcExportTo3D(GeometryDataContainer gmdc, GmdcGroups groups) : base(gmdc, groups) {} /// <summary> /// Constructor /// </summary> /// <param name="gmdc">The Gmdc File the Export is based on</param> public GmdcExportTo3D (GeometryDataContainer gmdc) : base(gmdc) {} /// <summary> /// Default Constructor /// </summary> public GmdcExportTo3D () : base() {} /// <summary> /// Returns the suggested File Extension (including the . like .obj or .3ds) /// </summary> public override string FileExtension { get {return ".???";} } /// <summary> /// Returns the File Description (the Name of the exported FileType) /// </summary> public override string FileDescription { get {return "???";} } /// <summary> /// Returns the name of the Author /// </summary> public override string Author { get {return "???";} } /// <summary> /// Called when a new File is started /// </summary> protected override void InitFile() { } /// <summary> /// This is called whenever a Group (=subSet) needs to processed /// </summary> protected override void ProcessGroup() { } /// <summary> /// Called when the export was finished /// </summary> protected override void FinishFile() { } } } This is a basic Stub for your Implementation. You only need to Implement those Methods to get a working Exporter. Prepare your Implemention: First off, give your class an apropriate name. If you write an Exporter for the .gmax Format, you should anme it something like GmdcExportToGmax, so you would replace all occurences of GmdcExportTo3D with GmdcExportTo3D. Next you should return some appropriate Values for FileExtension, FileDescription and Author. This Data is used in the Export File Dialog, to show the List of available Exporters. Implementint: The three Methods InitFile(), ProcessGroup() and FinishFile() are the ones that do the real Export. You can use the writer Member in all thre Methods to write your Data to the output File. They run this way, when an Export should be performed: InitFile() Repeat ProcessGroup() End Repeat FinishFile() So You probably might want to use InitFile() to write some Header informations to the File and FinishFile() for the Footer. You can alos use the to initialize the Data Structures used during the Export. The Key is the ProcessGroup() Method. As it exports the real Data. To be able to perform an Export, it can use the UVCoordinateElement, NormalElement, VertexElement, Group and Link Members from the base class. Here is a short sample of what you would write in to the ProcessGroup() Methode (An Example from the .obj Exporter by Delphy): int id = Link.GetElementNr(VertexElement); for (int i = 0; i < Link.ReferencedSize; i++) { writer.WriteLine("v " + Link.GetValue(id, i).Data[0].ToString("N6", AbstractGmdcExporter.DefaultCulture) + " "+ Link.GetValue(id, i).Data[1].ToString("N6", AbstractGmdcExporter.DefaultCulture) + " "+ Link.GetValue(id, i).Data[2].ToString("N6", AbstractGmdcExporter.DefaultCulture) ); } The call to Link.GetValue(nr, i).Data[1] Returns the i-th Vertex coordinate, form the Element identified by id. This should be all you need to get started writing an Exporter. If you have any Question, post them in this Thread. | |
| Emily | ||
Member since: 2006-04-17 Posts: 361 | Coming soon!!! | |
| skankyboy | ||
Member since: 2005-09-10 Posts: 32 | I know it's an olt thread but if I can get information it will be really helpfull, so I'm creating a 3ds exporter (as I created a obj to 3ds converter with C#, I must be able to create a 3ds exporter for SimPe) so I have a few question : How I toggle between each mesh group (during export process)? How I get the "Axis Order"(XYZ or XZY) in parameter ? Where are the bones and vertices assignement informations (for a smd exporter it will be very usefull) - so the vertex assignement parameter : None, 1 bone per vertex, 3 bones per vertex ? If someone can help me as I saw a lot of people having trouble working with 3ds max on MTS2 forum, I would be happy to help them... | |
| quaxi | ||
Member since: 2006-04-28 Posts: 3154 | You can go through the Groups with a command like this: foreach (GmdcGroup g in Gmdc.Groups){ } But ProcessGroup() is called once for each available group. You can the simply acces the this.Group Property to obtain the Data for the current Group. This Doc, was written befor the AXIS thing was implemented. The AXIS Settings influence a Transformation Matrix you have to apply to each Vector you Export. There are 6 diffrent matrices. You can acces them with the Command Vector3d nu = this.Component.Transform(u); //to transform a Euler Rotation Vector, or UVMappings. Basically all non scalable Vectors Vector3d nn = this.Component.TransformNormal(n); //to Transform a Normal Vector3d nv= this.Component.TransformScaled(v); //to Transform Vertex /*Invers Transformations for the Import */ u = this.Component.InverseTransform(nu); n = this.Component.InverseTransformNormal(nn); v = this.Component.InverseTransformScaled(nv); The available Bones are stored in the this.Gmdc.Joints Property, the Vertex assignement is just a another Block in the Elements Listing, with the BlockType set to JointWeights. You can find that Element from the GRoups section like this: GmdcElement boneelement = this.Link.FindElementType(ElementIdentity.BoneAssignment); Did you have a look at the SourceCode of the OBJ exporter? It may provide some insight on the general behaviour of the exporter classes, the Milkshape Exporter does also support Bones, so that might help in that Field. | |
| quaxi | ||
Member since: 2006-04-28 Posts: 3154 | If you got stuck anywhere, you can allways send me your Code, and I'll have a look at it. You can alyo try to contact me over AIM. Or (of course) post any further Questions here. | |
| skankyboy | ||
Member since: 2005-09-10 Posts: 32 | Thanks Quaxi for your quick answer, So as you said looking in Obj and MilkShape Ascii will be very helpfull too but I don't know where and how get them (I looked in the dll's but there is no code just classes and members). | |
| quaxi | ||
Member since: 2006-04-28 Posts: 3154 | You can download the Source from the Sourceforge CVS-Reporsitory. Or you can Brows the Repository online: http://cvs.sourceforge.net/viewcvs.py/simpe/fullsimpe/SimPe%20GMDC%20Exporter/ | |
| dnicecar | ||
Member since: 2005-11-16 Posts: 2 | Hi, hope this thread is still up. I happens to see that in the Element Section there is BoneAssignment. and It has member as many as the group's vertex count. And each member of it show numbers in format "int32 (byte byte byte byte)". I believe that the bytes means the joints (actually joint index in the Used Joint list) that the vertex is assigned to. so there is up to 4 joints that a vertex can be assigned to. Is what I believe correct? I am a newbie in 3d things and I am currently using Milkshape which I started just after I am into Sims 2 and modthesims2.com lately and eagered to mod things and eventually modding the (body) mesh and wondering why the MS3D ASCII exporter/importer results in NOT a truely original mesh condition (the exported .txt is unmodified at all). I though that BoneAssigment means the vertice - bone(joint) assignment. But in Joint tab in GMDC Plugin view, each Joint has list of vertices shown in the "Joint Section - Vertices". I can also see these in the simpe source Gmdc.Elements[n].data (BoneAssignment) vs. Gmdc.Joints[n].Vertices. I am confused? What is BoneAssignment element used for and what is Joint.Vertices used for. Again, I hope the late post in this thread is still replied Thanks. | |
viewthread, 0, 0, Gmdc-ImporterExporter-Interface