goat3d

diff converters/ass2goat/src/main.c @ 57:76d0f55f9d5f

mesh and animation saving looks done...
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 23 Jan 2014 03:57:15 +0200
parents ca549434dc95
children
line diff
     1.1 --- a/converters/ass2goat/src/main.c	Thu Jan 23 02:50:54 2014 +0200
     1.2 +++ b/converters/ass2goat/src/main.c	Thu Jan 23 03:57:15 2014 +0200
     1.3 @@ -13,6 +13,7 @@
     1.4  int convert(const char *infname);
     1.5  int convert_anim(const char *infname);
     1.6  void process_material(struct goat3d_material *mtl, struct aiMaterial *aimtl);
     1.7 +void process_mesh(struct goat3d *goat, struct goat3d_mesh *mesh, struct aiMesh *aimesh);
     1.8  void process_node(struct goat3d *goat, struct goat3d_node *parent, struct aiNode *ainode);
     1.9  int process_anim(struct goat3d *goat, struct aiAnimation *aianim);
    1.10  static int output_filename(char *buf, int bufsz, const char *fname, const char *suffix);
    1.11 @@ -101,6 +102,14 @@
    1.12  		goat3d_add_mtl(goat, mat);
    1.13  	}
    1.14  
    1.15 +	for(i=0; i<(int)aiscn->mNumMeshes; i++) {
    1.16 +		struct aiMesh *aimesh = aiscn->mMeshes[i];
    1.17 +		struct goat3d_mesh *mesh = goat3d_create_mesh();
    1.18 +
    1.19 +		process_mesh(goat, mesh, aimesh);
    1.20 +		goat3d_add_mesh(goat, mesh);
    1.21 +	}
    1.22 +
    1.23  	for(i=0; i<(int)aiscn->mRootNode->mNumChildren; i++) {
    1.24  		process_node(goat, 0, aiscn->mRootNode->mChildren[i]);
    1.25  	}
    1.26 @@ -195,11 +204,60 @@
    1.27  		goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_REFLECTION, aistr.data);
    1.28  	}
    1.29  	if(aiGetMaterialString(aimtl, AI_MATKEY_TEXTURE_OPACITY(0), &aistr) == aiReturn_SUCCESS) {
    1.30 -		// TODO this is semantically inverted... maybe add an alpha attribute?
    1.31 +		/* TODO this is semantically inverted... maybe add an alpha attribute? */
    1.32  		goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_TRANSMISSION, aistr.data);
    1.33  	}
    1.34  }
    1.35  
    1.36 +void process_mesh(struct goat3d *goat, struct goat3d_mesh *mesh, struct aiMesh *aimesh)
    1.37 +{
    1.38 +	int i, num_verts, num_faces;
    1.39 +	struct goat3d_material *mtl;
    1.40 +
    1.41 +	if(aimesh->mName.length > 0) {
    1.42 +		goat3d_set_mesh_name(mesh, aimesh->mName.data);
    1.43 +	}
    1.44 +
    1.45 +	if((mtl = goat3d_get_mtl(goat, aimesh->mMaterialIndex))) {
    1.46 +		goat3d_set_mesh_mtl(mesh, mtl);
    1.47 +	}
    1.48 +
    1.49 +	num_verts = aimesh->mNumVertices;
    1.50 +	num_faces = aimesh->mNumFaces;
    1.51 +
    1.52 +	for(i=0; i<num_verts; i++) {
    1.53 +		struct aiVector3D *v;
    1.54 +		struct aiColor4D *col;
    1.55 +
    1.56 +		v = aimesh->mVertices + i;
    1.57 +		goat3d_add_mesh_attrib3f(mesh, GOAT3D_MESH_ATTR_VERTEX, v->x, v->y, v->z);
    1.58 +
    1.59 +		if(aimesh->mNormals) {
    1.60 +			v = aimesh->mNormals + i;
    1.61 +			goat3d_add_mesh_attrib3f(mesh, GOAT3D_MESH_ATTR_NORMAL, v->x, v->y, v->z);
    1.62 +		}
    1.63 +		if(aimesh->mTangents) {
    1.64 +			v = aimesh->mTangents + i;
    1.65 +			goat3d_add_mesh_attrib3f(mesh, GOAT3D_MESH_ATTR_TANGENT, v->x, v->y, v->z);
    1.66 +		}
    1.67 +		if(aimesh->mTextureCoords[0]) {
    1.68 +			v = aimesh->mTextureCoords[0] + i;
    1.69 +			goat3d_add_mesh_attrib2f(mesh, GOAT3D_MESH_ATTR_TEXCOORD, v->x, v->y);
    1.70 +		}
    1.71 +		if(aimesh->mColors[0]) {
    1.72 +			col = aimesh->mColors[0] + i;
    1.73 +			goat3d_add_mesh_attrib4f(mesh, GOAT3D_MESH_ATTR_COLOR, col->r, col->g, col->b, col->a);
    1.74 +		}
    1.75 +		/* TODO: add bones */
    1.76 +	}
    1.77 +
    1.78 +	for(i=0; i<num_faces; i++) {
    1.79 +		struct aiFace *face = aimesh->mFaces + i;
    1.80 +
    1.81 +		goat3d_add_mesh_face(mesh, face->mIndices[0], face->mIndices[1], face->mIndices[2]);
    1.82 +	}
    1.83 +}
    1.84 +
    1.85  void process_node(struct goat3d *goat, struct goat3d_node *parent, struct aiNode *ainode)
    1.86  {
    1.87  	int i;