2 #include <Importer.hpp> 3 #include <Exporter.hpp> 4 #include <postprocess.h> 8 #if COMPILE_CONVEX_DECOMPOSITION 9 #include "NvConvexDecomposition.h" 14 #include "SDL_image.h" 38 #define class eus_class 39 #define throw eus_throw 40 #define export eus_export 41 #define vector eus_vector 42 #define string eus_string 43 #define iostream eus_iostream 44 #define complex eus_complex 50 char modname[] =
"___eus_assimp";
62 #define SIZE_T_MAX (std::numeric_limits<size_t>::max()) 71 case aiPrimitiveType_POINT:
74 case aiPrimitiveType_LINE:
77 case aiPrimitiveType_TRIANGLE:
80 case aiPrimitiveType_POLYGON:
90 name.assign( mesh->mName.data, mesh->mName.length );
92 std::cerr <<
";;" << prefix <<
" Mesh name: " << name << std::endl;
94 std::cerr <<
";;" << prefix <<
" Bones: " << mesh->mNumBones << std::endl;
95 std::cerr <<
";;" << prefix <<
" Faces: " << mesh->mNumFaces << std::endl;
96 std::cerr <<
";;" << prefix <<
" Vertices: " << mesh->mNumVertices << std::endl;
97 std::cerr <<
";;" << prefix <<
" PType: " <<
primitiveType( mesh->mPrimitiveTypes ) << std::endl;
98 std::cerr <<
";;" << prefix <<
" MaterialIndex: " << mesh->mMaterialIndex << std::endl;
102 std::cerr << prefix <<
" trans: " << transform.a1 <<
" " << transform.a2 <<
" " << transform.a3 <<
" " << transform.a4 << std::endl;
103 std::cerr << prefix <<
" " << transform.b1 <<
" " << transform.b2 <<
" " << transform.b3 <<
" " << transform.b4 << std::endl;
104 std::cerr << prefix <<
" " << transform.c1 <<
" " << transform.c2 <<
" " << transform.c3 <<
" " << transform.c4 << std::endl;
105 std::cerr << prefix <<
" " << transform.d1 <<
" " << transform.d2 <<
" " << transform.d3 <<
" " << transform.d4 << std::endl;
111 name.assign (node->mName.C_Str());
113 fprintf (stderr,
"%s Node name(%lX): %s", prefix.c_str(), (
void *)node, name.c_str());
114 std::cerr << std::endl;
115 std::cerr << prefix <<
" Meshes: " << node->mNumMeshes <<
" / ";
116 for (
unsigned int i = 0; i < node->mNumMeshes; i++ ) {
117 std::cerr <<
" " << node->mMeshes[i];
119 std::cerr << std::endl;
122 std::cerr << prefix <<
" Children: " << node->mNumChildren << std::endl;
123 for (
unsigned int i = 0; i < node->mNumChildren; i++ ) {
124 printNode(node->mChildren[i], prefix +
" ");
130 std::cerr <<
";; material: " << idx << std::endl;
136 for (
unsigned int i = 0; i < material->mNumProperties; i++ ) {
137 aiMaterialProperty *mp = material->mProperties[i];
139 kname.assign( mp->mKey.data, mp->mKey.length );
140 std::cerr <<
";; " << kname << std::endl;
145 const aiScene *scene,
const aiNode *node,
const aiMesh *amesh,
146 const aiMatrix4x4 &trans,
int direc) {
147 static int mesh_cntr = -1;
148 pointer ver_mat, nom_mat, indices, tex_cds;
158 nname.assign (node->mName.C_Str());
159 mname.assign (amesh->mName.C_Str());
161 if (nname.empty() && mname.empty()) {
162 nname =
"eusglvertices_" + mesh_cntr;
164 nname = nname +
"_" + mname;
169 vpop (); vpush (lname);
170 lname =
rawcons (ctx, K_NAME, lname);
171 vpop (); vpush (lname);
172 ret =
rawcons (ctx, lname, ret);
180 switch (amesh->mPrimitiveTypes) {
181 case aiPrimitiveType_LINE:
184 case aiPrimitiveType_TRIANGLE:
187 case aiPrimitiveType_POLYGON:
193 ltype =
rawcons (ctx, K_TYPE, ltype);
194 vpop(); vpush (ltype);
195 ret =
rawcons (ctx, ltype, ret);
203 aiMaterial *am = scene->mMaterials[amesh->mMaterialIndex];
205 std::cerr <<
";; material properties: " << am->mNumProperties << std::endl;
209 aiColor4D clr4d( 0.0, 0.0, 0.0, 0.0);
212 ar = am->Get (AI_MATKEY_NAME, s);
213 if (ar == aiReturn_SUCCESS) {
216 std::cerr <<
";; material properties: name: " << str << std::endl;
223 pelem =
rawcons (ctx, K_NAME, pelem);
225 lmaterial =
rawcons (ctx, pelem, lmaterial);
226 vpop(); vpop(); vpop();
227 vpush (lmaterial); lpc++;
229 ar = am->Get (AI_MATKEY_COLOR_AMBIENT, clr4d);
230 if (ar == aiReturn_SUCCESS) {
232 std::cerr <<
";; material properties: AMBIENT: ";
233 std::cerr << clr4d[0] <<
" " << clr4d[1] <<
" " << clr4d[2] <<
" " << clr4d[3] << std::endl;
241 pelem =
rawcons (ctx, K_AMBIENT, pelem);
243 lmaterial =
rawcons (ctx, pelem, lmaterial);
244 vpop(); vpop(); vpop();
245 vpush (lmaterial); lpc++;
247 ar = am->Get (AI_MATKEY_COLOR_DIFFUSE, clr4d);
248 if (ar == aiReturn_SUCCESS) {
250 std::cerr <<
";; material properties: DIFFUSE: ";
251 std::cerr << clr4d[0] <<
" " << clr4d[1] <<
" " << clr4d[2] <<
" " << clr4d[3] << std::endl;
259 pelem =
rawcons (ctx, K_DIFFUSE, pelem);
261 lmaterial =
rawcons (ctx, pelem, lmaterial);
262 vpop(); vpop(); vpop();
263 vpush (lmaterial); lpc++;
265 ar = am->Get (AI_MATKEY_COLOR_SPECULAR, clr4d);
266 if (ar == aiReturn_SUCCESS) {
268 std::cerr <<
";; material properties: SPECULAR: ";
269 std::cerr << clr4d[0] <<
" " << clr4d[1] <<
" " << clr4d[2] <<
" " << clr4d[3] << std::endl;
277 pelem =
rawcons (ctx, K_SPECULAR, pelem);
279 lmaterial =
rawcons (ctx, pelem, lmaterial);
280 vpop(); vpop(); vpop();
281 vpush (lmaterial); lpc++;
283 ar = am->Get (AI_MATKEY_COLOR_EMISSIVE, clr4d);
284 if (ar == aiReturn_SUCCESS) {
286 std::cerr <<
";; material properties: EMISSIVE: ";
287 std::cerr << clr4d[0] <<
" " << clr4d[1] <<
" " << clr4d[2] <<
" " << clr4d[3] << std::endl;
295 pelem =
rawcons (ctx, K_EMISSION, pelem);
297 lmaterial =
rawcons (ctx, pelem, lmaterial);
298 vpop(); vpop(); vpop();
299 vpush (lmaterial); lpc++;
301 ar = am->Get (AI_MATKEY_SHININESS, val);
302 if (ar == aiReturn_SUCCESS) {
304 std::cerr <<
";; material properties: SHININESS: " << val << std::endl;
309 pelem =
rawcons (ctx, K_SHININESS, pelem);
311 lmaterial =
rawcons (ctx, pelem, lmaterial);
313 vpush (lmaterial); lpc++;
315 #if 0 // Do not use transparent?? 316 ar = am->Get (AI_MATKEY_COLOR_TRANSPARENT, clr4d);
317 if (ar == aiReturn_SUCCESS) {
318 std::cerr <<
";; material properties: TRANSPARENT: ";
319 std::cerr << clr4d[0] <<
" " << clr4d[1] <<
" " << clr4d[2] <<
" " << clr4d[3] << std::endl;
326 pelem =
rawcons (ctx, K_TRANSPARENT, pelem);
328 lmaterial =
rawcons (ctx, pelem, lmaterial);
329 vpop(); vpop(); vpop();
330 vpush (lmaterial); lpc++;
333 for (
unsigned int tex_count = 0; tex_count < am->GetTextureCount(aiTextureType_DIFFUSE); tex_count++) {
336 aiTextureMapping mapping;
337 unsigned int uvindex;
340 aiTextureMapMode mapmode;
341 ar = am->GetTexture(aiTextureType_DIFFUSE, tex_count, &fpath,
342 &mapping, &uvindex, &blend, &op, &mapmode);
344 ar = am->GetTexture(aiTextureType_DIFFUSE, tex_count, &fpath);
347 if (ar == AI_SUCCESS) {
353 pelem =
rawcons (ctx, K_FILENAME, pelem);
355 lmaterial =
rawcons (ctx, pelem, lmaterial);
356 vpop(); vpop(); vpop();
357 vpush (lmaterial); lpc++;
359 std::cerr <<
";; material properties: Texture: ";
361 std::cerr <<
"file: " << str << std::endl;
362 std::cerr <<
" / uv_index: " << uvindex << std::endl;
363 std::cerr <<
" / blend: " << blend << std::endl;
364 std::cerr <<
" / Mapping: " << mapping << std::endl;
365 std::cerr <<
" / Op: " << op << std::endl;
366 std::cerr <<
" / Mode: " << mapmode << std::endl;
374 tmp =
rawcons (ctx, K_MATERIAL, tmp);
377 while(lpc-- > 0) vpop();
382 if (!!amesh->mNormals) {
383 nom_mat =
makematrix (ctx, amesh->mNumVertices, 3); vpush (nom_mat); npc++;
386 ver_mat =
makematrix (ctx, amesh->mNumVertices, 3); vpush (ver_mat); npc++;
392 for (
unsigned int f = 0;
f < amesh->mNumFaces;
f++) {
393 icount += amesh->mFaces[
f].mNumIndices;
396 vpush (indices); npc++;
402 for (
unsigned int f = 0;
f < amesh->mNumFaces;
f++) {
403 for(
unsigned int p = 0; p < amesh->mFaces[
f].mNumIndices; p++) {
404 vec[icount++] = amesh->mFaces[
f].mIndices[p];
413 tmp =
rawcons (ctx, K_INDICES, tmp);
421 if (amesh->HasTextureCoords(texcount)) {
424 for (
unsigned int v = 0;
v < amesh->mNumVertices;
v++) {
425 *tex_vec++ = amesh->mTextureCoords[texcount][
v].x;
426 *tex_vec++ = (1.0 - amesh->mTextureCoords[texcount][
v].y);
433 tmp =
rawcons (ctx, K_TEXCOORDS, tmp);
441 int vcount=0, ncount=0;
442 for (
unsigned int i = 0; i < amesh->mNumVertices; ++i) {
445 trans.DecomposeNoScaling(rot, pos);
446 aiVector3D tvec (amesh->mVertices[i]);
451 ver_vec[vcount++] = - tvec.z;
452 ver_vec[vcount++] = tvec.y;
453 ver_vec[vcount++] = tvec.x;
456 ver_vec[vcount++] = tvec.x;
457 ver_vec[vcount++] = - tvec.z;
458 ver_vec[vcount++] = tvec.y;
461 ver_vec[vcount++] = tvec.x;
462 ver_vec[vcount++] = tvec.y;
463 ver_vec[vcount++] = tvec.z;
466 ver_vec[vcount++] = tvec.z;
467 ver_vec[vcount++] = tvec.y;
468 ver_vec[vcount++] = - tvec.x;
471 ver_vec[vcount++] = tvec.x;
472 ver_vec[vcount++] = tvec.z;
473 ver_vec[vcount++] = - tvec.y;
478 aiVector3D tnom = rot.Rotate (amesh->mNormals[i]);
481 nom_vec[ncount++] = - tnom.z;
482 nom_vec[ncount++] = tnom.y;
483 nom_vec[ncount++] = tnom.x;
486 nom_vec[ncount++] = tnom.x;
487 nom_vec[ncount++] = - tnom.z;
488 nom_vec[ncount++] = tnom.y;
491 nom_vec[ncount++] = tnom.x;
492 nom_vec[ncount++] = tnom.y;
493 nom_vec[ncount++] = tnom.z;
496 nom_vec[ncount++] = tnom.z;
497 nom_vec[ncount++] = tnom.y;
498 nom_vec[ncount++] = - tnom.x;
501 nom_vec[ncount++] = tnom.x;
502 nom_vec[ncount++] = tnom.z;
503 nom_vec[ncount++] = - tnom.y;
513 tmp =
rawcons (ctx, K_NORMALS , tmp);
523 tmp =
rawcons (ctx, K_VERTICES , tmp);
529 for (;npc > 0; npc--) vpop();
535 const aiScene *scene,
const aiNode *node,
536 const aiMatrix4x4 &parent_world_trans,
int direc,
537 std::vector<pointer> &mesh_info) {
538 aiMatrix4x4 node_world_trans = parent_world_trans * node->mTransformation;
540 fprintf (stderr,
"node : %lX\n", (
void *)node);
543 if (node->mNumMeshes > 0 && node->mMeshes !=
NULL) {
544 for (
unsigned int n = 0;
n < node->mNumMeshes;
n++) {
545 aiMesh *am = scene->mMeshes[node->mMeshes[
n]];
547 fprintf (stderr,
" mesh: %d", node->mMeshes[
n]);
548 std::cerr <<
";; mesh = " << (
void *)am << std::endl;
552 mesh_info.push_back (ret);
556 fprintf(stderr,
"\n");
557 std::cerr <<
" children: " << node->mNumChildren << std::endl;
559 for (
unsigned int c = 0; c < node->mNumChildren; c++) {
561 scene, node->mChildren[c],
562 node_world_trans, direc, mesh_info);
579 Assimp::Importer importer;
583 importer.SetPropertyBool(AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION,
true, &existing);
585 fprintf(stderr,
";; OverWrite : Ignore UP_DIRECTION", existing);
588 unsigned int post_proc = (aiProcess_Triangulate | aiProcess_SortByPType);
589 bool recalc_normal =
false;
590 char *dumpfile =
NULL;
594 post_proc = ckintval(argv[2]);
596 if((post_proc & aiProcess_GenNormals) ||
597 (post_proc & aiProcess_GenSmoothNormals)) {
598 recalc_normal =
true;
599 if((post_proc & aiProcess_GenNormals) &&
600 (post_proc & aiProcess_GenSmoothNormals)) {
601 post_proc &= ~aiProcess_GenNormals;
606 direction = ckintval(argv[3]);
609 if (argv[4] !=
NIL) {
614 const aiScene* raw_scene = importer.ReadFile ((
char *)
get_string(argv[0]), 0);
618 std::cerr <<
";; " << str << std::endl;
622 std::cerr <<
";; Num meshes(raw): " << raw_scene->mNumMeshes << std::endl;
626 std::cerr <<
";; Recalc_normal" << std::endl;
628 for (
unsigned int m = 0; m < raw_scene->mNumMeshes; m++) {
629 aiMesh *
a = raw_scene->mMeshes[m];
630 if (!!a->mNormals) { a->mNormals =
NULL; }
634 const aiScene* scene = importer.ApplyPostProcessing (post_proc);
637 std::cerr <<
";; " << str << std::endl;
641 std::cerr <<
";; Num meshes: " << scene->mNumMeshes << std::endl;
648 aiMatrix4x4 world_trans;
649 std::vector<pointer> mesh_info;
651 scene->mRootNode, world_trans, direction, mesh_info);
653 std::cerr <<
";; mesh size: " << mesh_info.size() << std::endl;
655 for (std::vector<pointer>::reverse_iterator rit = mesh_info.rbegin();
656 rit != mesh_info.rend(); rit++) {
658 lst =
rawcons (ctx, *rit, lst);
666 outf.assign (dumpfile);
668 const std::string::size_type
s = outf.find_last_of(
'.');
669 if (s != std::string::npos) {
670 outext = outf.substr (s+1);
672 std::cerr <<
";; Can not find extention: " << outf << std::endl;
675 Assimp::Exporter exporter;
677 for(
size_t i = 0,
end = exporter.GetExportFormatCount(); i <
end; ++i) {
678 const aiExportFormatDesc*
const e = exporter.GetExportFormatDescription(i);
679 if (outext == e->id) {
681 }
else if (outext == e->fileExtension) {
687 for(
size_t i = 0, end = exporter.GetExportFormatCount(); i < end; ++i) {
688 const aiExportFormatDesc*
const e = exporter.GetExportFormatDescription(i);
689 if (outext == e->fileExtension) {
696 const aiExportFormatDesc*
const e = exporter.GetExportFormatDescription(outfi);
698 fprintf (stderr,
";; use file format: %s\n", e->id);
700 aiReturn ret = exporter.Export (scene, e->id, outf);
717 char *dumpfile =
NULL;
724 while (islist(a)) {list_len++; a=ccdr(a);}
726 if (list_len <= 0)
return NIL;
727 bool has_materials =
false;
728 pointer ltype, linfo, lvertices, lnormals, ltexcoords, lindices;
729 pointer mtype, minfo, mvertices, mnormals, mtexcoords, mindices;
736 ltexcoords = argv[5];
742 direction =
intval(argv[13]);
746 aiScene *pScene = (aiScene *) malloc(
sizeof (aiScene));
747 memset((
void *)pScene, 0,
sizeof (aiScene));
748 pScene->mPrivate = malloc(
sizeof (
void *) * 2);
751 pScene->mNumMeshes = list_len;
752 pScene->mMeshes =
new aiMesh*[list_len];
755 pScene->mRootNode =
new aiNode();
756 pScene->mRootNode->mNumMeshes = list_len;
757 pScene->mRootNode->mMeshes =
new unsigned int[list_len];
758 pScene->mRootNode->mName.Set(
"eus_glvertices");
761 pScene->mNumMaterials = list_len;
762 pScene->mMaterials =
new aiMaterial*[list_len];
763 has_materials =
true;
765 pScene->mNumMaterials = 1;
766 pScene->mMaterials =
new aiMaterial*[1];
767 has_materials =
false;
769 aiMaterial* pcMat =
new aiMaterial();
770 aiString
s; s.Set (AI_DEFAULT_MATERIAL_NAME);
771 pcMat->AddProperty (&s, AI_MATKEY_NAME);
772 aiColor4D clrDiffuse(0.8
f, 0.8
f, 0.8
f, 1.0
f);
773 pcMat->AddProperty (&clrDiffuse, 1, AI_MATKEY_COLOR_DIFFUSE);
774 pcMat->AddProperty (&clrDiffuse, 1, AI_MATKEY_COLOR_SPECULAR);
775 clrDiffuse = aiColor4D (0.2
f, 0.2
f, 0.2
f, 1.0
f);
776 pcMat->AddProperty (&clrDiffuse, 1, AI_MATKEY_COLOR_AMBIENT);
778 pScene->mMaterials[0] = pcMat;
781 for (
int i = 0; i < list_len; i++) {
782 mtype = ccar (ltype);
783 minfo = ccar (linfo);
784 mvertices = ccar (lvertices);
785 mnormals = ccar (lnormals);
786 mtexcoords = ccar (ltexcoords);
787 mindices = ccar (lindices);
789 ltype = ccdr (ltype);
790 linfo = ccdr (linfo);
791 lvertices = ccdr (lvertices);
792 lnormals = ccdr (lnormals);
793 ltexcoords = ccdr (ltexcoords);
794 lindices = ccdr (lindices);
796 pScene->mRootNode->mMeshes[i] = i;
797 aiMesh* pMesh = pScene->mMeshes[i] =
new aiMesh();
799 if (!has_materials) {
800 pMesh->mMaterialIndex = 0;
802 pMesh->mMaterialIndex = i;
804 aiMaterial* pcMat =
new aiMaterial();
805 std::ostringstream oss;
806 oss <<
"eusassimp_mat_" << i;
807 aiString
s; s.Set (oss.str());
808 pcMat->AddProperty(&s, AI_MATKEY_NAME);
810 for (
int el = 0; el < 7; el++) {
813 minfo = ccdr (minfo);
814 aiColor4D clr4d (0.0
f, 0.0
f, 0.0
f, 1.0
f);
819 clr4d[j] = melem->
c.
fvec.
fv[j];
822 pcMat->AddProperty(&clr4d, 1, AI_MATKEY_COLOR_AMBIENT);
828 clr4d[j] = melem->
c.
fvec.
fv[j];
831 pcMat->AddProperty(&clr4d, 1, AI_MATKEY_COLOR_DIFFUSE);
837 clr4d[j] = melem->
c.
fvec.
fv[j];
840 pcMat->AddProperty(&clr4d, 1, AI_MATKEY_COLOR_SPECULAR);
846 clr4d[j] = melem->
c.
fvec.
fv[j];
849 pcMat->AddProperty(&clr4d, 1, AI_MATKEY_COLOR_EMISSIVE);
854 float val =
fltval (melem);
855 pcMat->AddProperty(&val, 1, AI_MATKEY_SHININESS);
861 float val = isflt (melem) ?
fltval (melem) : (float)
intval (melem);
863 for(
int j = 0; j < 4; j++) {
868 clr4d[j] = melem->
c.
fvec.
fv[j];
872 pcMat->AddProperty(&clr4d, 1, AI_MATKEY_COLOR_TRANSPARENT);
877 if (isstring(melem)) {
879 aiString s; s.Set ((
const char *)(melem->
c.
str.
chars));
880 pcMat->AddProperty(&s, AI_MATKEY_TEXTURE_DIFFUSE(0));
886 pScene->mMaterials[i] = pcMat;
889 if (mvertices ==
NIL) { }
892 pMesh->mNumVertices = size / 3;
893 pMesh->mVertices =
new aiVector3D [pMesh->mNumVertices];
894 for (
unsigned int k = 0; k < pMesh->mNumVertices; k++) {
895 pMesh->mVertices[k].x = scale * *fv++;
896 pMesh->mVertices[k].y = scale * *fv++;
897 pMesh->mVertices[k].z = scale * *fv++;
900 if (mnormals !=
NIL) {
903 if (size / 3 != pMesh->mNumVertices) { }
904 pMesh->mNormals =
new aiVector3D [pMesh->mNumVertices];
905 for (
unsigned int k = 0; k < pMesh->mNumVertices; k++) {
906 pMesh->mNormals[k].x = *fv++;
907 pMesh->mNormals[k].y = *fv++;
908 pMesh->mNormals[k].z = *fv++;
912 if (mtexcoords !=
NIL) {
913 printf(
";; add texture coords\n");
916 if (size / 2 != pMesh->mNumVertices) { }
918 pMesh->mTextureCoords[0] =
new aiVector3D [pMesh->mNumVertices];
919 for (
unsigned int k = 0; k < pMesh->mNumVertices; k++) {
920 pMesh->mTextureCoords[0][k].x = *fv++;
921 pMesh->mTextureCoords[0][k].y = (1.0 - *fv++);
925 unsigned int verts_per_face =
intval(mtype);
926 if (mindices !=
NIL) {
927 if (verts_per_face != 4 && verts_per_face != 3) {
933 pMesh->mNumFaces = idlen / verts_per_face;
935 pMesh->mFaces =
new aiFace[pMesh->mNumFaces];
936 for (
unsigned int f = 0;
f < pMesh->mNumFaces;
f++) {
937 aiFace&
face = pMesh->mFaces[
f];
938 face.mNumIndices = verts_per_face;
939 face.mIndices =
new unsigned int[verts_per_face];
940 for (
unsigned int o = 0; o < verts_per_face; o++) {
941 face.mIndices[o] = *iv++;
947 if (verts_per_face != 4 && verts_per_face != 3) { }
948 pMesh->mNumFaces = pMesh->mNumVertices / verts_per_face;
949 pMesh->mFaces =
new aiFace[pMesh->mNumFaces];
950 for (
unsigned int f = 0, p = 0;
f < pMesh->mNumFaces;
f++) {
951 aiFace&
face = pMesh->mFaces[
f];
952 face.mNumIndices = verts_per_face;
953 face.mIndices =
new unsigned int[verts_per_face];
954 for (
unsigned int o = 0; o < verts_per_face; o++, p++) {
955 face.mIndices[o] = p;
963 outf.assign (dumpfile);
965 const std::string::size_type
s = outf.find_last_of(
'.');
966 if (s != std::string::npos) {
967 outext = outf.substr (s+1);
969 std::cerr <<
";; Can not find extention: " << outf << std::endl;
973 Assimp::Exporter exporter;
975 for(
size_t i = 0,
end = exporter.GetExportFormatCount(); i <
end; ++i) {
976 const aiExportFormatDesc*
const e = exporter.GetExportFormatDescription(i);
977 if (outext == e->id) {
979 }
else if (outext == e->fileExtension) {
985 for(
size_t i = 0, end = exporter.GetExportFormatCount(); i < end; ++i) {
986 const aiExportFormatDesc*
const e = exporter.GetExportFormatDescription(i);
987 if (outext == e->fileExtension) {
993 const aiExportFormatDesc*
const e = exporter.GetExportFormatDescription(outfi);
994 aiReturn ret = exporter.Export (pScene, e->id, outf);
1007 int verts_per_face = 3;
1012 #if COMPILE_CONVEX_DECOMPOSITION 1015 NxF32 skinWidth = 0;
1016 NxU32 decompositionDepth = 4;
1017 NxU32 maxHullVertices = 64;
1018 NxF32 concavityThresholdPercent = 0.1f;
1019 NxF32 mergeThresholdPercent = 20;
1020 NxF32 volumeSplitThresholdPercent = 2;
1026 decompositionDepth = ckintval(argv[3]);
1029 maxHullVertices = ckintval(argv[4]);
1032 concavityThresholdPercent =
ckfltval(argv[5]);
1035 mergeThresholdPercent =
ckfltval(argv[6]);
1038 volumeSplitThresholdPercent =
ckfltval(argv[7]);
1044 while (islist (a)) {list_len++; a=ccdr(a);}
1047 CONVEX_DECOMPOSITION::iConvexDecomposition *ic = CONVEX_DECOMPOSITION::createConvexDecomposition();
1050 for (
int i = 0; i < list_len; i++) {
1051 pointer mvertices = ccar (lvertices);
1052 pointer mindices = ccar (lindices);
1054 lvertices = ccdr (lvertices);
1055 lindices = ccdr (lindices);
1057 if (mvertices ==
NIL) { }
1061 if (mindices !=
NIL) {
1064 for (
unsigned int f = 0;
f < idlen / verts_per_face;
f++) {
1084 ic->addTriangle (p1, p2, p3);
1087 int step = (3 * verts_per_face);
1088 for (
unsigned int f = 0;
f < size / step;
f++) {
1093 p1[0] = fv[
f * step + 0];
1094 p1[1] = fv[
f * step + 1];
1095 p1[2] = fv[
f * step + 2];
1097 p2[0] = fv[
f * step + 3];
1098 p2[1] = fv[
f * step + 4];
1099 p2[2] = fv[
f * step + 5];
1101 p3[0] = fv[
f * step + 6];
1102 p3[1] = fv[
f * step + 7];
1103 p3[2] = fv[
f * step + 8];
1105 ic->addTriangle (p1, p2, p3);
1116 bool useInitialIslandGeneration =
true;
1117 bool useIslandGeneration =
false;
1118 bool useBackgroundThreads =
false;
1120 ic->computeConvexDecomposition (skinWidth,
1123 concavityThresholdPercent,
1124 mergeThresholdPercent,
1125 volumeSplitThresholdPercent,
1126 useInitialIslandGeneration,
1127 useIslandGeneration,
1128 useBackgroundThreads);
1130 while ( !ic->isComputeComplete() ) {
1132 fprintf (stderr,
"Computing the convex decomposition in a background thread.\r\n");
1139 NxU32 hullCount = ic->getHullCount();
1141 fprintf (stderr,
"Convex Decomposition produced %d hulls.\r\n", hullCount );
1143 for (NxU32 i = 0; i < hullCount; i++) {
1149 std::ostringstream oss;
1150 oss <<
"convex_" << i;
1154 vpop (); vpush (lname);
1155 lname =
rawcons (ctx, K_NAME, lname);
1156 vpop (); vpush (lname);
1157 tmpret =
rawcons (ctx, lname, tmpret);
1159 vpush (tmpret); npc++;
1166 ltype =
rawcons (ctx, K_TYPE, ltype);
1167 vpop(); vpush (ltype);
1168 tmpret =
rawcons (ctx, ltype, tmpret);
1170 vpush (tmpret); npc++;
1173 CONVEX_DECOMPOSITION::ConvexHullResult
result;
1174 ic->getConvexHullResult(i, result);
1181 vpush (indices); npc++;
1183 for (NxU32 i = 0; i < result.mVcount * 3; i++) {
1184 ver_vec[i] = result.mVertices[i];
1186 for (NxU32 i = 0; i < result.mTcount * 3; i++) {
1187 vec[i] = result.mIndices[i];
1194 tmp =
rawcons (ctx, K_INDICES, tmp);
1195 tmpret =
rawcons (ctx, tmp, tmpret);
1197 vpush (tmpret); npc++;
1204 tmp =
rawcons (ctx, K_VERTICES , tmp);
1205 tmpret =
rawcons (ctx, tmp, tmpret);
1207 vpush (tmpret); npc++;
1211 ret =
rawcons (ctx, tmpret, ret);
1212 for (;npc > 0; npc--) vpop();
1216 CONVEX_DECOMPOSITION::releaseConvexDecomposition(ic);
1219 fprintf(stderr,
";;This program have not been compiled with convex decomposition");
1231 Assimp::Importer importer;
1232 const aiScene* scene = importer.ReadFile((
char *)
get_string(argv[0]),
1233 aiProcess_Triangulate |
1234 aiProcess_JoinIdenticalVertices |
1235 aiProcess_SortByPType);
1239 std::cerr <<
";; " << str << std::endl;
1244 std::cerr <<
";; scene->NumAnimations " << scene->mNumAnimations << std::endl;
1247 std::cerr <<
";; scene->mNumCameras " << scene->mNumCameras << std::endl;
1250 std::cerr <<
";; scene->mNumLights " << scene->mNumLights << std::endl;
1253 std::cerr <<
";; scene->mNumMaterials " << scene->mNumMaterials << std::endl;
1254 for (
unsigned int i = 0; i < scene->mNumMaterials; i++) {
1259 std::cerr <<
";; scene->mNumTextures " << scene->mNumTextures << std::endl;
1262 std::cerr <<
";; scene->mFlags " << scene->mFlags << std::endl;
1264 std::cerr <<
";; scene->mNumMeshes " << scene->mNumMeshes << std::endl;
1267 for (
unsigned int i = 0; i < scene->mNumMeshes; i++ ) {
1283 SDL_Surface *sf = IMG_Load((
char *)
get_string(argv[0]));
1286 int byteperpixel = sf->format->BytesPerPixel;
1287 pointer img_buffer =
makestring ((
char *)sf->pixels, sf->h * sf->w * byteperpixel);
1290 if (!!(sf->format)) {
1291 printf(
"fmt:%0X, byte/pixel %d, MASK(RGBA): %08X %08X %08X %08X\n",
1294 sf->format->BytesPerPixel,
1300 printf(
"width: %d, height: %d, pitch: %d, pixels: %lX\n",
1306 if (!!(sf->format)) {
1307 if (sf->format->BytesPerPixel == 3) {
1308 if ( sf->format->Rmask != 0x000000FF ||
1309 sf->format->Gmask != 0x0000FF00 ||
1310 sf->format->Bmask != 0x00FF0000 ) {
1317 for (
int i = 0; i < 4; i++) {
1318 if ( mask == sf->format->Rmask ) {
1324 for (
int i = 0; i < 4; i++) {
1325 if ( mask == sf->format->Gmask ) {
1331 for (
int i = 0; i < 4; i++) {
1332 if ( mask == sf->format->Bmask ) {
1338 fprintf(stderr,
";; fmt:%0X, byte/pixel %d, MASK(RGBA): %08X %08X %08X %08X -> %d %d %d\n",
1341 sf->format->BytesPerPixel,
1345 sf->format->Amask, rm, gm, bm);
1346 fprintf(stderr,
";; width: %d, height: %d, pitch: %d, pixels: %lX\n",
1352 unsigned char *src_ptr = (
unsigned char *)sf->pixels;
1353 unsigned char *dst_ptr = (
unsigned char *)img_buffer->
c.
str.
chars;
1354 for (
int i = 0; i < sf->w * sf->h; i++) {
1355 dst_ptr[0] = src_ptr[rm];
1356 dst_ptr[1] = src_ptr[gm];
1357 dst_ptr[2] = src_ptr[bm];
1358 dst_ptr += 3; src_ptr += 3;
1362 if (sf->format->BytesPerPixel == 4) {
1363 if ( sf->format->Rmask != 0x000000FF ||
1364 sf->format->Gmask != 0x0000FF00 ||
1365 sf->format->Bmask != 0x00FF0000 ||
1366 sf->format->Amask != 0xFF000000 ) {
1374 for (
int i = 0; i < 4; i++) {
1375 if ( mask == sf->format->Rmask ) {
1381 for (
int i = 0; i < 4; i++) {
1382 if ( mask == sf->format->Gmask ) {
1388 for (
int i = 0; i < 4; i++) {
1389 if ( mask == sf->format->Bmask ) {
1395 for (
int i = 0; i < 4; i++) {
1396 if ( mask == sf->format->Amask ) {
1402 fprintf(stderr,
";; fmt:%0X, byte/pixel %d, MASK(RGBA): %08X %08X %08X %08X -> %d %d %d %d\n",
1405 sf->format->BytesPerPixel,
1409 sf->format->Amask, rm, gm, bm, am);
1410 fprintf(stderr,
";; width: %d, height: %d, pitch: %d, pixels: %lX\n",
1416 unsigned char *src_ptr = (
unsigned char *)sf->pixels;
1417 unsigned char *dst_ptr = (
unsigned char *)img_buffer->
c.
str.
chars;
1418 for (
int i = 0; i < sf->w * sf->h; i++) {
1419 dst_ptr[0] = src_ptr[rm];
1420 dst_ptr[1] = src_ptr[gm];
1421 dst_ptr[2] = src_ptr[bm];
1422 dst_ptr[3] = src_ptr[am];
1423 dst_ptr += 4; src_ptr += 4;
1431 vpop(); vpush (ptr);
1432 ptr =
rawcons (ctx, K_VERTICES, ptr);
1433 vpop(); vpush (ptr);
1434 ret =
rawcons (ctx, ptr, ret);
1440 ptr =
rawcons (ctx, K_TYPE, ptr);
1441 vpop(); vpush (ptr);
1442 ret =
rawcons (ctx, ptr, ret);
1448 ptr =
rawcons (ctx, K_HEIGHT, ptr);
1449 vpop(); vpush (ptr);
1450 ret =
rawcons (ctx, ptr, ret);
1456 ptr =
rawcons (ctx, K_WIDTH, ptr);
1457 vpop(); vpush (ptr);
1458 ret =
rawcons (ctx, ptr, ret);
1476 defun(ctx,
"C-ASSIMP-LOAD-IMAGE", argv[0], (
pointer (*)())ASSIMP_LOAD_IMAGE,
NULL);
1497 K_TRANSPARENCY =
defkeyword(ctx,
"TRANSPARENCY");
pointer rawcons(context *, pointer, pointer)
pointer makeint(eusinteger_t v)
static pointer store_mesh_info(register context *ctx, eusfloat_t base_scl, const aiScene *scene, const aiNode *node, const aiMesh *amesh, const aiMatrix4x4 &trans, int direc)
static pointer K_SHININESS
memset(serverAddr, 0, sizeof(*serverAddr))
static pointer K_TRIANGLES
pointer GET_MESHES(register context *ctx, int n, pointer *argv)
void register_eus_assimp()
pointer ASSIMP_DESCRIBE(register context *ctx, int n, pointer *argv)
static void register_all_nodes(register context *ctx, eusfloat_t base_scl, const aiScene *scene, const aiNode *node, const aiMatrix4x4 &parent_world_trans, int direc, std::vector< pointer > &mesh_info)
pointer defkeyword(context *, char *)
static pointer K_SPECULAR
pointer makevector(pointer, int)
pointer DUMP_GL_VERTICES(register context *ctx, int n, pointer *argv)
void add_module_initializer(char *, pointer(*)())
pointer CONVEX_DECOMP_GL_VERTICES(register context *ctx, int n, pointer *argv)
ROS_INFO ROS_ERROR int pointer * argv
static pointer K_MATERIAL
static void printMesh(aiMesh *mesh, std::string prefix)
face(linetab, int mi, int m, int r, int n)
pointer ___eus_assimp(register context *ctx, int n, pointer *argv, pointer env)
pointer error(enum errorcode ec,...) pointer error(va_alist) va_dcl
static void printMaterial(aiMaterial *material, unsigned int idx)
pointer defun(context *, char *, pointer, pointer(*)(), char *)
pointer makematrix(context *, int, int)
static std::string primitiveType(unsigned int tp)
static void printTransform(aiMatrix4x4 &transform, std::string prefix)
static pointer K_EMISSION
pointer makestring(char *, int)
static pointer K_TEXCOORDS
static void printNode(aiNode *node, std::string prefix)
static pointer K_FILENAME
static pointer K_TRANSPARENCY
eusinteger_t intval(pointer p)
static pointer K_VERTICES