Esempio n. 1
0
static int __dcmd
cmd_ofexport( int argc, char **argv )
{
	mol_device_node_t *root = prom_get_root();
	FILE *file;
	
	if( argc!=2 )
		return 1;

	file = fopen( argv[1], "w" );
	if( !file ){
		printm("Could not create file '%s'\n", argv[1] );
		return 0;
	}
	indprint(file, 0, "# *************************\n");	
	indprint(file, 0, "#  Exported OF Device Tree \n");
	indprint(file, 0, "# *************************\n\n");
	export_node( root, file, 0 );
	fclose( file );
	return 0;
}
Esempio n. 2
0
void export_ramen()
{
	bpy::object package = bpy::scope();
	package.attr("__path__") = "_ramen";
	
	export_param();
	export_parameterised();
	export_manipulable();
	export_manipulator();
	export_node();
	export_composition();
	export_anim();
	export_roto();
	export_ui();
	export_image();
	export_python();

	// util modules
	export_gl();

	export_SeExpr();
	export_expressions();
}
Esempio n. 3
0
static void 
export_node( mol_device_node_t *dn, FILE *file, int ind )
{
	p_property_t *pr;
	char **ns, buf[256];
	int i;

	if( !dn )
		return;

	/* drop uninteresting nodes */
	for( ns=&drop_nodes[0]; *ns; ns++ )
		if( !strcmp((char *) node_name(dn), *ns) ) {
			export_node( dn->sibling, file, ind );
			return;
		}
	
	indprint(file, ind, "#\n");
	indprint(file, ind, "# **************** NODE %s ***************\n", node_name(dn) );
	indprint(file, ind, "# %s\n", get_full_name(dn, buf, sizeof(buf)) );
	indprint(file, ind, "#\n");
	indprint(file, ind, "{\n");
	ind += INDENT_VALUE;

	if( dn->unit_string && strlen( dn->unit_string ) )
		indprint(file, ind, "(unit_string %s )\n", dn->unit_string );

	if( (ulong)dn->node > PHANDLE_BASE )
		indprint(file, ind, "(mol_phandle 0x%08x )\n",(ulong)dn->node );
	
	/* properties */
	for( pr=dn->properties; pr; pr=pr->next ) {
		char **dp;

		/* drop uninteresting properties */
		for( dp=&drop_properties[0]; *dp; dp++ )
			if( pr->name && !strcmp(pr->name, *dp) )
				break;
		if( *dp )
			continue;

		/* skip all AAPL properties - probably a side effect of BootX 
		 * (hrm... some AAPL-properties seems to be non-generated)
		 */
		//if( pr->name && !strncmp(pr->name, "AAPL", 4) )
		//	continue;

		indprint(file, ind, "(property %-18s ", pr->name );

		if( !pr->length ) {
			fprintf(file, ")\n");
			continue;
		}

		/* detect likely strings/string arrays */
		for( i=0; i<pr->length ; i++ ) {
			char ch = pr->value[i];
			if( !ch && i && !pr->value[i-1] && i!=pr->length-1 )
				break;
			if( ch && !isgraph(ch) && !isspace(ch) )
				break;
		}
		if( i==pr->length && !pr->value[i-1] ) {
			fprintf(file, "<str>  \t");
			ind += INDENT_VALUE;
			for( i=0; i<pr->length; i += strlen((char *) &pr->value[i]) + 1 ) {
				if( i )
					fprintf(file, ", ");
				if( pr->length > 50 ) {
					fprintf(file, "\n");
					indprint(file, ind, "" );
				}
				fprintf(file, "\"%s\"", &pr->value[i] );
			}
			fprintf(file, " )\n");
			ind -= INDENT_VALUE;
			continue;
		}

		/* print long words */
		if( !(pr->length % 4) ) {
			int nw = 4;
			if( !(pr->length % (4*5)) )
				nw=5;
			else if( !(pr->length % (4*6)) )
				nw = 6;
			else if( (pr->length % (4*4)) )
				nw=2;
			fprintf(file, "<word> \t" );
			ind += INDENT_VALUE;
			for( i=0; i<pr->length; i+=4 ) {
				if( pr->length > 8 && !((i/4)%nw) ) {
					fprintf(file, "\n");
					indprint(file, ind, "");
				}
				fprintf(file, "0x%08lx ",*(ulong*)&pr->value[i] );
			}
			fprintf(file, " )\n" );
			ind -= INDENT_VALUE;
			continue;
		}

		/* assume byte */
		fprintf(file, "<byte> \t" );
		ind += INDENT_VALUE;
		for( i=0; i<pr->length; i++ ) {
			if( !(i%12) && pr->length > 8 ) {
				fprintf(file, "\n");
				indprint(file, ind, "");
			}
			fprintf(file, "0x%02x ", pr->value[i]);
		}
		ind -= INDENT_VALUE;
		fprintf(file, " )\n" );
	}

	if( dn->child ) {
		indprint(file, ind, "\n");
		export_node( dn->child, file, ind );
	}
	ind -= INDENT_VALUE;
	indprint(file, ind, "}\n" );

	export_node( dn->sibling, file, ind );
}
Esempio n. 4
0
File: assiqe.c Progetto: r-lyeh/eve
void export_node(FILE *out, const struct aiScene *scene, const struct aiNode *node,
	struct aiMatrix4x4 mat, char *clean_name)
{
	struct aiMatrix3x3 mat3;
	int i, a, k, t;

	aiMultiplyMatrix4(&mat, &node->mTransformation);
	mat3.a1 = mat.a1; mat3.a2 = mat.a2; mat3.a3 = mat.a3;
	mat3.b1 = mat.b1; mat3.b2 = mat.b2; mat3.b3 = mat.b3;
	mat3.c1 = mat.c1; mat3.c2 = mat.c2; mat3.c3 = mat.c3;

	if (!strstr(node->mName.data, "$ColladaAutoName$"))
		clean_name = clean_node_name((char*)node->mName.data);

	if (only_one_node && strcmp(clean_name, only_one_node))
		goto skip_mesh;

	for (i = 0; i < node->mNumMeshes; i++) {
		struct aiMesh *mesh = scene->mMeshes[node->mMeshes[i]];
		struct aiMaterial *material = scene->mMaterials[mesh->mMaterialIndex];

		if (mesh->mNumBones == 0 && dobone && !dorigid) {
			if (verbose)
				fprintf(stderr, "skipping rigid mesh %d in node %s (no bones)\n", i, clean_name);
			continue;
		}

		fprintf(stderr, "exporting mesh %s[%d]: %d vertices, %d faces\n",
				clean_name, i, mesh->mNumVertices, mesh->mNumFaces);

		fprintf(out, "\n");
		fprintf(out, "mesh \"%s\"\n", clean_name);
		fprintf(out, "material \"%s\"\n", find_material(material));

		struct vb *vb = (struct vb*) malloc(mesh->mNumVertices * sizeof(*vb));
		memset(vb, 0, mesh->mNumVertices * sizeof(*vb));

		// A rigidly animated node -- insert fake blend index/weights
		if (mesh->mNumBones == 0 && dobone) {
			a = find_bone((char*)node->mName.data);
			if (verbose)
				fprintf(stderr, "\trigid bone %d for mesh in node %s (no bones)\n", bonelist[a].number, node->mName.data);
			for (k = 0; k < mesh->mNumVertices; k++) {
				vb[k].b[0] = bonelist[a].number;
				vb[k].w[0] = 1;
				vb[k].n = 1;
			}
		}

		// Assemble blend index/weight array
		for (k = 0; k < mesh->mNumBones; k++) {
			struct aiBone *bone = mesh->mBones[k];
			a = find_bone(bone->mName.data);
			for (t = 0; t < bone->mNumWeights; t++) {
				struct aiVertexWeight *w = mesh->mBones[k]->mWeights + t;
				int idx = w->mVertexId;
				if (vb[idx].n < MAXBLEND) {
					vb[idx].b[vb[idx].n] = bonelist[a].number;
					vb[idx].w[vb[idx].n] = w->mWeight;
					vb[idx].n++;
				}
			}
		}

		for (k = 0; k < mesh->mNumVertices; k++) {
			struct aiVector3D vp = mesh->mVertices[k];
			if (!dobone)
				aiTransformVecByMatrix4(&vp, &mat);
			fprintf(out, "vp %.9g %.9g %.9g\n", vp.x, vp.y, vp.z);
			if (mesh->mNormals) {
				struct aiVector3D vn = mesh->mNormals[k];
				if (!dobone)
					aiTransformVecByMatrix3(&vn, &mat3);
				fprintf(out, "vn %.9g %.9g %.9g\n", vn.x, vn.y, vn.z);
			}

			if (mesh->mTextureCoords[0]) {
				float u = mesh->mTextureCoords[0][k].x;
				float v = 1 - mesh->mTextureCoords[0][k].y;
				fprintf(out, "vt %.9g %.9g\n", u, v);
			}
			for (t = 1; t <= MAX_UVMAP; t++) {
				if (mesh->mTextureCoords[t]) {
					float u = mesh->mTextureCoords[t][k].x;
					float v = 1 - mesh->mTextureCoords[t][k].y;
					fprintf(out, "v%d %.9g %.9g\n", FIRST_UVMAP+t-1, u, v);
				}
			}

			if (mesh->mColors[0]) {
				float r = mesh->mColors[0][k].r; r = floorf(r * 255) / 255;
				float g = mesh->mColors[0][k].g; g = floorf(g * 255) / 255;
				float b = mesh->mColors[0][k].b; b = floorf(b * 255) / 255;
				float a = mesh->mColors[0][k].a; a = floorf(a * 255) / 255;
				fprintf(out, "vc %.9g %.9g %.9g %.9g\n", r, g, b, a);
			}
			for (t = 1; t <= MAX_COL; t++) {
				if (mesh->mColors[t]) {
					float r = mesh->mColors[t][k].r; r = floorf(r * 255) / 255;
					float g = mesh->mColors[t][k].g; g = floorf(g * 255) / 255;
					float b = mesh->mColors[t][k].b; b = floorf(b * 255) / 255;
					float a = mesh->mColors[t][k].a; a = floorf(a * 255) / 255;
					fprintf(out, "v%d %.9g %.9g %.9g %.9g\n", FIRST_COL+t-1, r, g, b, a);
				}
			}

			if (dobone) {
				fprintf(out, "vb");
				for (t = 0; t < vb[k].n; t++) {
					fprintf(out, " %d %.9g", vb[k].b[t], vb[k].w[t]);
				}
				fprintf(out, "\n");
			}
		}

		for (k = 0; k < mesh->mNumFaces; k++) {
			struct aiFace *face = mesh->mFaces + k;
			if (face->mNumIndices == 3) {
				if (doflip)
					fprintf(out, "fm %d %d %d\n", face->mIndices[2], face->mIndices[1], face->mIndices[0]);
				else
					fprintf(out, "fm %d %d %d\n", face->mIndices[0], face->mIndices[1], face->mIndices[2]);
			} else if (face->mNumIndices == 4) {
				if (doflip)
					fprintf(out, "fm %d %d %d %d\n", face->mIndices[3], face->mIndices[2], face->mIndices[1], face->mIndices[0]);
				else
					fprintf(out, "fm %d %d %d %d\n", face->mIndices[0], face->mIndices[1], face->mIndices[2], face->mIndices[3]);
			} else if (face->mNumIndices > 4) {
				fprintf(stderr, "n-gon (%d) in mesh!\n", face->mNumIndices);
				int i1 = face->mIndices[0];
				int i2 = face->mIndices[1];
				for (a = 2; a < face->mNumIndices; a++) {
					int i3 = face->mIndices[a];
					if (doflip)
						fprintf(out, "fm %d %d %d\n", i3, i2, i1);
					else
						fprintf(out, "fm %d %d %d\n", i1, i2, i3);
					i2 = i3;
				}
			} else {
				fprintf(stderr, "skipping point/line primitive\n");
			}
		}

		free(vb);
	}

skip_mesh:

	for (i = 0; i < node->mNumChildren; i++)
		export_node(out, scene, node->mChildren[i], mat, clean_name);
}
Esempio n. 5
0
File: assiqe.c Progetto: r-lyeh/eve
int main(int argc, char **argv)
{
	FILE *file;
	const struct aiScene *scene;
	char *p;
	int c;

	char *output = NULL;
	char *input = NULL;
	int onlyanim = 0;
	int onlymesh = 0;

	while ((c = getopt(argc, argv, "AHMPSabflmn:o:rvxsu:")) != -1) {
		switch (c) {
		case 'A': save_all_bones++; break;
		case 'H': dohips = 1; break;
		case 'M': list_all_meshes = 1; break;
		case 'P': list_all_positions = 1; break;
		case 'S': dostatic = 1; break;
		case 'a': onlyanim = 1; break;
		case 'm': onlymesh = 1; break;
		case 'n': only_one_node = optarg++; break;
		case 'b': need_to_bake_skin = 1; break;
		case 'o': output = optarg++; break;
		case 'f': doflip = 0; break;
		case 'r': dorigid = 1; break;
		case 'l': dolowprec = 1; break;
		case 'v': verbose++; break;
		case 'x': doaxis = 1; break;
		case 's': dounscale = 1; break;
		case 'u': untaglist[numuntags++] = optarg++; break;
		default: usage(); break;
		}
	}

	if (optind == argc)
		usage();

	input = argv[optind++];

	p = strrchr(input, '/');
	if (!p) p = strrchr(input, '\\');
	if (!p) p = input; else p++;
	strcpy(basename, p);
	p = strrchr(basename, '.');
	if (p) *p = 0;

	numtags = argc - optind;
	taglist = argv + optind;

	/* Read input file and post process */

	int flags = 0;
	flags |= aiProcess_JoinIdenticalVertices;
	flags |= aiProcess_GenSmoothNormals;
	flags |= aiProcess_GenUVCoords;
	flags |= aiProcess_TransformUVCoords;
	flags |= aiProcess_LimitBoneWeights;
	//flags |= aiProcess_FindInvalidData;
	flags |= aiProcess_ImproveCacheLocality;
	//flags |= aiProcess_RemoveRedundantMaterials;
	//flags |= aiProcess_OptimizeMeshes;

	fprintf(stderr, "loading %s\n", input);
	scene = aiImportFile(input, flags);
	if (!scene) {
		fprintf(stderr, "cannot import '%s': %s\n", input, aiGetErrorString());
		exit(1);
	}

	if (scene->mNumAnimations > 0) doanim = 1;
	if (onlymesh) { domesh = 1; doanim = 0; }
	if (onlyanim) { domesh = 0; doanim = 1; }

	if (getenv("DOANIM")) doanim = 1;

	// Convert to Z-UP coordinate system
	aiMultiplyMatrix4(&scene->mRootNode->mTransformation, &yup_to_zup);

	// Build a list of bones and compute the bind pose matrices.
	if (build_bone_list(scene) > 0)
		dobone = 1;

	if (dostatic) {
		dobone = 0;
		need_to_bake_skin = 0;
	}

	if (list_all_meshes) {
		export_mesh_list(scene);
		return 0;
	}

	if (list_all_positions) {
		export_position_list(scene);
		return 0;
	}

	// Mesh is split with incompatible bind matrices, so pick a new
	// bind pose and deform the mesh to fit.
	if (need_to_bake_skin && !onlyanim) {
		apply_initial_frame(); // ditch original bind pose
		bake_scene_skin(scene);
	}

	/*
	 * Export scene as mesh/skeleton/animation
	 */

	if (output) {
		fprintf(stderr, "saving %s\n", output);
		file = fopen(output, "w");
		if (!file) {
			fprintf(stderr, "cannot open output file: '%s'\n", output);
			exit(1);
		}
	} else {
		file = stdout;
	}

	fprintf(file, "# Inter-Quake Export\n");

	if (dobone) {
		export_bone_list(file);
	}

	if (domesh) {
		struct aiMatrix4x4 identity;
		aiIdentityMatrix4(&identity);
		export_custom_vertexarrays(file, scene);
		export_node(file, scene, scene->mRootNode, identity, "SCENE");
	}

	if (dobone) {
		if (doanim) {
			export_animations(file, scene);
		}
	}

	if (output)
		fclose(file);

	aiReleaseImport(scene);

	return 0;
}