Serializable* ExporterBackend::buildTexture(CSLImage* image, CSIBCPixMap& pixMap) { uint depth = pixMap.GetTotalPixelDepthByte(); // We only handly 32 bit and 24bit textures right now if (depth != 4 && depth != 3) { ZENIC_WARNING("Unsupported pixeldepth (" << pixMap.GetTotalPixelDepthByte() << ") for texture " << image->GetSourceFile() << "skipping"); return 0; } Texture* texture = zenic_new Texture; TextureData* textureData = zenic_new TextureData; textureData->setWidth(u16(pixMap.GetWidth())); textureData->setHeight(u16(pixMap.GetHeight())); textureData->setFlags(TextureData::RGB); DataPtr<u8> imageData; uint imageSize = pixMap.GetWidth() * pixMap.GetHeight() * depth; imageData.allocate(imageSize); memcpy(imageData.objects(), pixMap.GetMap(), imageSize); textureData->setImageData(imageData); texture->setData(textureData); return texture; }
void DotXsiLoader::buildImages(ExporterBackend& backend) { CSLImageLibrary* imageLibrary = m_scene->GetImageLibrary(); if (!imageLibrary) return; CSLImage** imageList = imageLibrary->GetImageList(); int imageCount = imageLibrary->GetImageCount(); m_textures.clear(); for (int i = 0; i < imageCount; ++i) { CSIBCPixMap pixMap; CSLImage* image = imageList[i]; ZENIC_ASSERT(image); char* fileName = image->GetSourceFile(); if (SI_SUCCESS != CSIBCPixMap::Load(fileName, pixMap)) { ZENIC_WARNING("Unable to load file: " << fileName << " not supported format or missing."); continue; } Serializable* texture = backend.buildTexture(image, pixMap); if (texture) { backend.addTexture(image, texture); m_textures.push_back(texture); } } }
void DegenerateMesh::process(CSLXSIMesh* mesh, bool useNormals) { CSLXSIShape* shape = mesh->XSIShape(); // We only handle one set of triangles for now. if (mesh->GetXSITriangleListCount() == 0) { ZENIC_WARNING("No triangles in the object. Can not be tristipped"); return; } CSLXSITriangleList* triangleList = mesh->XSITriangleLists()[0]; uint triCount = (uint)mesh->XSITriangleLists()[0]->GetTriangleCount() * 3; // Positions int* posIndexList = triangleList->GetVertexIndices()->ArrayPtr(); Vector3* posVertexArray = (Vector3*)shape->GetVertexPositionList()->GetAttributeArray()->ArrayPtr(); // Texture Coords int* uvIndexList = 0; Vector2* uvVertexArray = 0; int* normalIndexList = 0; Vector3* normalVertexArray = 0; CSLXSISubComponentAttributeList* componentList = shape->GetFirstTexCoordList(); if (componentList) { uvIndexList = triangleList->GetAttributeByName(componentList->GetName())->ArrayPtr(); uvVertexArray = (Vector2*)componentList->GetAttributeArray()->ArrayPtr(); } componentList = shape->GetFirstNormalList(); if (componentList && useNormals) { normalIndexList = triangleList->GetAttributeByName(componentList->GetName())->ArrayPtr(); normalVertexArray = (Vector3*)componentList->GetAttributeArray()->ArrayPtr(); } // setup the lists m_uniqueVertexList.clear(); m_uniqueVertexList.resize(shape->GetVertexPositionList()->GetCount()); m_indices.clear(); m_indices.reserve(triCount); // intentionally reserved, not resized // generate the stuff for (uint i = 0; i < triCount; ++i) { Vertex vertex; vertex.position = posVertexArray[posIndexList[i]]; if (uvVertexArray) vertex.uv = uvVertexArray[uvIndexList[i]]; if (normalVertexArray) vertex.normal = normalVertexArray[normalIndexList[i]]; u32 index = createOrRetrieveUniqueVertex(posIndexList[i], vertex); m_indices.push_back(index); } }