MCPcopy Create free account
hub / github.com/KhronosGroup/OpenCOLLADA / _writeGeometry_lib3ds

Method _writeGeometry_lib3ds

dae23ds_lib3ds/src/DAE23dsWriter.cpp:584–682  ·  view source on GitHub ↗

--------------------------------------------------------------------

Source from the content-addressed store, hash-verified

582 }
583 //--------------------------------------------------------------------
584 void Writer::_writeGeometry_lib3ds(const COLLADAFW::Geometry* geometry)
585 {
586
587
588 Lib3dsMesh *_3dsmesh = lib3ds_mesh_new(geometry->getName().c_str());
589 _3dsmeshMap.insert(std::make_pair(geometry->getUniqueId(), _3dsmesh));
590 lib3ds_file_insert_mesh(_3dsfile, _3dsmesh, -1);
591 {
592 COLLADAFW::Mesh *mesh = (COLLADAFW::Mesh*)geometry;
593 //values
594 const COLLADAFW::MeshVertexData &positions = mesh->getPositions();
595 const COLLADAFW::MeshVertexData &uvs = mesh->getUVCoords();
596 //index
597 const COLLADAFW::MeshPrimitiveArray &primitives = mesh->getMeshPrimitives();
598
599 // vertex
600 lib3ds_mesh_resize_vertices(_3dsmesh, positions.getValuesCount()/3, 1, 0);
601 //_Log("positions.getValuesCount()="<<positions.getValuesCount());
602 {
603 //position
604 if(COLLADAFW::FloatOrDoubleArray::DATA_TYPE_FLOAT==positions.getType())
605 {
606 const COLLADAFW::FloatArray* pos = positions.getFloatValues();
607 _Log("FloatArray pos count="<<pos->getCount());
608 for (size_t i = 0; i < positions.getValuesCount()/3; ++i)
609 {
610 _3dsmesh->vertices[i][0] = (*pos)[3*i+0];
611 _3dsmesh->vertices[i][1] = (*pos)[3*i+1];
612 _3dsmesh->vertices[i][2] = (*pos)[3*i+2];
613 }
614 }else if(COLLADAFW::FloatOrDoubleArray::DATA_TYPE_DOUBLE==positions.getType()){
615 const COLLADAFW::DoubleArray* pos = positions.getDoubleValues();
616 _Log("DoubleArray pos count="<<pos->getCount());
617 for (size_t i = 0; i < positions.getValuesCount()/3; ++i)
618 {
619 _3dsmesh->vertices[i][0] = (float)(*pos)[3*i+0];
620 _3dsmesh->vertices[i][1] = (float)(*pos)[3*i+1];
621 _3dsmesh->vertices[i][2] = (float)(*pos)[3*i+2];
622 }
623 }
624 //uv
625 // NOTE: the number of uv pair is more than vertex number in most cases,
626 // but the number of uv pair in lib3ds is equal to the vertex number,
627 // so we have to truncate the number of uv pair to the vertex number to avoid buffer overflow.
628 // This is a limitation of lib3ds.
629 const size_t UVLEN = min(positions.getValuesCount()/3, uvs.getValuesCount()/2);
630 //const size_t UVLEN = uvs.getValuesCount()/2;
631 _Log("UVLEN ="<< UVLEN<<",min("<<positions.getValuesCount()/3<<","<< uvs.getValuesCount()/2<<")");
632 if(COLLADAFW::FloatOrDoubleArray::DATA_TYPE_FLOAT==uvs.getType())
633 {
634 const COLLADAFW::FloatArray* uv = uvs.getFloatValues();
635
636 _Log("FloatArray uv count="<<uv->getCount());
637 for (size_t i = 0; i < UVLEN/*uvs.getValuesCount()/2*/; ++i)
638 {
639 _3dsmesh->texcos[i][0] = (*uv)[2*i+0];
640 _3dsmesh->texcos[i][1] = (*uv)[2*i+1];
641 //_Log("uv<"<<_3dsmesh->texcos[i][0]<<","<<_3dsmesh->texcos[i][1]<<">");

Callers

nothing calls this directly

Calls 15

lib3ds_mesh_newFunction · 0.85
lib3ds_file_insert_meshFunction · 0.85
lib3ds_mesh_resize_facesFunction · 0.85
c_strMethod · 0.80
getUniqueIdMethod · 0.80
getPositionsMethod · 0.80
getValuesCountMethod · 0.80
getFloatValuesMethod · 0.80
getDoubleValuesMethod · 0.80
getPrimitiveTypeMethod · 0.80
minFunction · 0.50

Tested by

no test coverage detected