void Material::writeBinary(FILE* file) { write(id, file); write(diffuse.value, 3, file); write(ambient.value, 3, file); write(emissive.value, 3, file); write(opacity.value,file); write(specular.value, 3, file); write(shininess.value,file); unsigned int size = textures.size(); write(size, file); for(auto itr = textures.begin(); itr != textures.end(); itr++) { write((*itr)->id, file); write((*itr)->path, file); write((*itr)->uvTranslation, 2, file); write((*itr)->uvScale, 2, file); std::string wrapModeU=getWrapModeUseString((*itr)->wrapModeU); std::string wrapModeV=getWrapModeUseString((*itr)->wrapModeV); std::string type= getTextureUseString((*itr)->usage); write(type,file); write(wrapModeU,file); write(wrapModeV,file); } }
void Material::Texture::serialize(json::BaseJSONWriter &writer) const { writer << json::obj; writer << "id" = id; writer << "filename" = path; if (uvTranslation[0] != 0.f || uvTranslation[1] != 0.f) writer << "uvtranslation" = uvTranslation; if (uvScale[0] != 1.f || uvScale[1] != 1.f) writer << "uvscaling" = uvScale; writer << "type" = getTextureUseString(usage); writer << json::end; }
void G3djWriter::writeMaterial(G3djMaterial* material){ writer->openObject(); writer->writeStringPair("id", material->getId().c_str()); writer->nextValue(true); writer->writeStringPair("type", getMaterialTypeString(material->getMaterialType())); writer->nextValue(true); writer->openArray("diffuse", false); writer->writeFloat(material->getDiffuse().x); writer->nextValue(false); writer->writeFloat(material->getDiffuse().y); writer->nextValue(false); writer->writeFloat(material->getDiffuse().z); writer->closeArray(false); writer->nextValue(true); writer->openArray("ambient", false); writer->writeFloat(material->getAmbient().x); writer->nextValue(false); writer->writeFloat(material->getAmbient().y); writer->nextValue(false); writer->writeFloat(material->getAmbient().z); writer->closeArray(false); writer->nextValue(true); writer->openArray("emissive", false); writer->writeFloat(material->getEmissive().x); writer->nextValue(false); writer->writeFloat(material->getEmissive().y); writer->nextValue(false); writer->writeFloat(material->getEmissive().z); writer->closeArray(false); writer->nextValue(true); writer->writeFloatPair("opacity", material->getOpacity()); if(material->getMaterialType() == PHONG){ writer->nextValue(true); writer->openArray("specular", false); writer->writeFloat(material->getSpecular().x); writer->nextValue(false); writer->writeFloat(material->getSpecular().y); writer->nextValue(false); writer->writeFloat(material->getSpecular().z); writer->closeArray(false); writer->nextValue(true); writer->writeFloatPair("shininess", material->getShininess()); } if(material->getTextureCount() > 0){ writer->nextValue(true); writer->openArray("textures", true); for(int i=0; i<material->getTextureCount(); i++){ Texture* texture = material->getTexture(i); if(i>0) writer->nextValue(true); writer->openObject(); writer->writeStringPair("id", texture->getId()); writer->nextValue(true); writer->writeStringPair("filename", texture->getRelativePath()); writer->nextValue(true); writer->openArray("uvtranslation", false); writer->writeFloat(texture->uvTranslation.x); writer->nextValue(false); writer->writeFloat(texture->uvTranslation.y); writer->closeArray(false); writer->nextValue(true); writer->openArray("uvscaling", false); writer->writeFloat(texture->uvScale.x); writer->nextValue(false); writer->writeFloat(texture->uvScale.y); writer->closeArray(false); writer->nextValue(true); writer->writeStringPair("type", getTextureUseString(texture->textureUse)); writer->closeObject(); } writer->closeArray(); } writer->closeObject(); }