![]() |
#1 |
Senior Member
Professional user
Join Date: Jan 2008
Posts: 109
|
![]()
re: making an import/export plugin
Anyone know how to make an import/export plugin to a specific game format (.gmt format) for ISI & SimBin racing games? Is there a tutorial or example that could be followed?? |
![]() |
![]() |
![]() |
#2 |
Senior Member
Professional user
Join Date: Mar 2005
Location: Phoenix, AZ
Posts: 917
|
![]()
I don't know anything about the .gmt format off the top of my head, but here's a simple example of a generic AC3D exporter you can look at. It doesn't actually do anything, but it shows how to walk the hierarchy and get a list of all the meshes. There are some notes in there about how to extract the triangles, textures and materials. If you knew what data you needed to write out, you might be able to do something similar to create your exporter.
Code:
/****************************************************************************/ /****************************************************************************/ /* */ /* exportskeleton.cpp, AC3D export plug-in */ /* (c) Copyright TFPSoft, LLC. All rights reserved. */ /* */ /* LANGUAGE: C/C++ */ /* PLATFORM: <generic> */ /* EXTENDED LIBS\SDKS: AC3D SDK */ /* CREATED: 6/19/2009 */ /* AUTHOR: Lisa Carter */ /* LAST MODIFIED: 6/19/2009 */ /* */ /* DESCRIPTION: */ /* This plug-in extracts joint \ skeleton information from an */ /* AC3D model and then writes the information to a plain text file. */ /* There is no known program at the time of writing that will read */ /* such a file; this code is solely for demonstration purposes. */ /* */ /* LICENSE: */ /* */ /* Permission to use, copy, modify, merge, distribute, and sell this */ /* software and its documentation for any purpose is hereby granted */ /* without fee, provided that */ /* */ /* (i) the above copyright notices and this permission notice appear */ /* in all copies or substantial portions of the program source code */ /* and related documentation, and */ /* */ /* (ii) the name of TFPSoft, LLC. may not be used in any advertising or */ /* publicity relating to the software without the specific, prior */ /* written permission of TFPSoft, LLC. */ /* */ /* (iii) modified distributions must be clearly indicated, and must */ /* not be misrepresented as being the original software. Authors who */ /* modify the software are fully responsible for those modifications. */ /* */ /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */ /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */ /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */ /* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */ /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */ /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */ /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND */ /* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */ /* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */ /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY */ /* OF SUCH DAMAGE. */ /* */ /****************************************************************************/ /****************************************************************************/ /*------------------------------------------------------------------------- Includes and Pragmas ---------------------------------------------------------------------------*/ #include "ac_plugin.h" #include <stdio.h> #include <math.h> #include <stdlib.h> #include <stdio.h> /*------------------------------------------------------------------------- Skeleton Joint ---------------------------------------------------------------------------*/ typedef struct EXPORTSKELETON_JOINT { char name[1024]; Point3 position; int index; EXPORTSKELETON_JOINT *parent; } _EXPORTSKELETON_JOINT; /*--------------------------------------------------------------------------- Extracts the joints from a model to a linked list. Parameters: ACObject *object - object to extract joint information from EXPORTSKELETON_JOINT *jointParent - parent of this joint int &index - index counter for determining the current joint number List **listJoint - list to hold extracted joints Returns: EXPORTSKELETON_JOINT* pointer to newly created joint, or NULL if none ---------------------------------------------------------------------------*/ static EXPORTSKELETON_JOINT *exportskeleton_extractjoints(ACObject *object, EXPORTSKELETON_JOINT *jointParent, int &index, List **listJoint) { EXPORTSKELETON_JOINT *joint = NULL; // only extract data from meshes; skip groups and lights if ( ac_object_get_type(object) == OBJECT_NORMAL ) { // allocate a new joint joint = (EXPORTSKELETON_JOINT *)malloc(sizeof(EXPORTSKELETON_JOINT)); if ( joint == NULL ) { message_dialog("Out of memory"); return NULL; } memset(joint, 0, sizeof(EXPORTSKELETON_JOINT)); // get the joint parent joint->parent = jointParent; // get the joint position joint->position = *(ac_object_get_centre(object)); // set the joint index joint->index = index; index++; // get the joint name memset(joint->name, 0, sizeof(joint->name)); if ( ac_object_get_name(object) != NULL ) { strncpy(joint->name, ac_object_get_name(object), sizeof(joint->name) - 1); } // add the joint to our joint list list_add_item(listJoint, joint); // set the newly created joint as the new parent jointParent = joint; // if you wanted to, you could extract vertex and material information here... // to get the triangles use: ac_object_get_triangle_surfaces // to get the material use: ac_palette_get_material // to get material properties use: ac_entity_get_rgb_value with "ambient", "diffuse", "specular", "emissive", "transparency", "shininess" // to get the texture use: ac_object_get_texture_index and texture_id_to_name } // process child objects List *listChildren = ac_object_get_childrenlist(object); if ( listChildren != NULL ) { EXPORTSKELETON_JOINT *jointFirst = NULL; List *listPosition = NULL; list_for_each(listChildren, listPosition) { EXPORTSKELETON_JOINT *jointNew = exportskeleton_extractjoints((ACObject *)(listPosition->data), jointParent, index, listJoint); // if we find a valid joint, make it the parent of all its siblings if ( jointNew != NULL && jointFirst == NULL ) { jointFirst = jointNew; jointParent = jointNew; } } } // return the newly created joint return joint; } /*--------------------------------------------------------------------------- Exports the skeleton from an AC3D model to a text file. Parameters: char *fileName - file name to export to ACObject *top - root object to export Returns: TRUE if success, FALSE if failure ---------------------------------------------------------------------------*/ static Boolean exportskeleton_save(char *fileName, ACObject *top) { // extract the joint information List *listJoint = NULL; int numberOfJoints = 0; exportskeleton_extractjoints(top, NULL, numberOfJoints, &listJoint); // open the file FILE *fileOut = fopen(fileName, "wt"); if ( fileOut == NULL ) { message_dialog("Could not open file %s.", fileName); list_free_all(&listJoint); return false; } // write overview information fprintf(fileOut, "Total Number of Joints: %d\n\n", numberOfJoints); // write each joint if ( numberOfJoints > 0 ) { List *listPosition = NULL; list_for_each(listJoint, listPosition) { EXPORTSKELETON_JOINT *joint = (EXPORTSKELETON_JOINT *)(listPosition->data); fprintf(fileOut, "Joint Number: %d\n", joint->index); fprintf(fileOut, "Name: \"%s\"\n", joint->name); fprintf(fileOut, "Has Parent: %d\n", (joint->parent != NULL)); if ( joint->parent == NULL ) { fprintf(fileOut, "Child Of: (-1) \"WORLD\"\n"); } else { fprintf(fileOut, "Child Of: (%d) \"%s\"\n", joint->parent->index, joint->parent->name); } fprintf(fileOut, "Position in World Space: %f, %f, %f\n", joint->position.x, joint->position.y, joint->position.z); fprintf(fileOut, "Local to Parent Transformation Matrix:\n"); if ( joint->parent == NULL ) { // joint has no parent, use local transform fprintf(fileOut, "1.0, 0.0, 0.0, 0.0\n"); fprintf(fileOut, "0.0, 1.0, 0.0, 0.0\n"); fprintf(fileOut, "0.0, 0.0, 1.0, 0.0\n"); fprintf(fileOut, "%f, %f, %f, 1.0\n", joint->position.x, joint->position.y, joint->position.z); } else { // get the transformation relative to the parent space fprintf(fileOut, "1.0, 0.0, 0.0, 0.0\n"); fprintf(fileOut, "0.0, 1.0, 0.0, 0.0\n"); fprintf(fileOut, "0.0, 0.0, 1.0, 0.0\n"); fprintf(fileOut, "%f, %f, %f, 1.0\n", joint->position.x - joint->parent->position.x, joint->position.y - joint->parent->position.y, joint->position.z - joint->parent->position.z); } fprintf(fileOut, "\n"); } } // close the file fclose(fileOut); // free the joint list list_free_all(&listJoint); // status display_message("Done."); // success return true; } /*--------------------------------------------------------------------------- Called on Plugin Initialization, Required by AC3D Parameters: <none> Returns: 0 for success, -1 if failed ---------------------------------------------------------------------------*/ AC3D_PLUGIN_FUNC int AC3DPluginInit(AC3DPluginInitData *d) { // register file exporter ac_register_file_exporter("SKELETON", ".txt", "Skeleton ASCII", exportskeleton_save, "plugin, version 1.0, TFPSoft, LLC"); // return success return 0; } /*--------------------------------------------------------------------------- Called on Plugin Exit, Required by AC3D Parameters: <none> Returns: 0 for success, -1 if failed ---------------------------------------------------------------------------*/ AC3D_PLUGIN_FUNC int AC3DPluginExit() { // return success return 0; } /*--------------------------------------------------------------------------- Returns Author Information, Required by AC3D Parameters: <none> Returns: static string containing version and author information ---------------------------------------------------------------------------*/ AC3D_PLUGIN_FUNC char *AC3DPluginAbout() { return ("Skeleton Export Plugin - Version 1.0\nExports joint information to a plain text file, using the AC3D hierarchy to form the skeleton."); } |
![]() |
![]() |
![]() |
#3 |
Member
Expert member
Join Date: Nov 2010
Posts: 71
|
![]()
I'm interested in delving into making my own plugins....
What do I do with the text example posted here? |
![]() |
![]() |
![]() |
#4 |
Administrator
Professional user
Join Date: Jun 2003
Posts: 4,541
|
![]() |
![]() |
![]() |
![]() |
Thread Tools | |
Display Modes | |
|
|