//! Adds a standard data block (type: point set declaration) to the chain of all data blocks. //! Returns the total # of data blocks in the data block chain. size_t U3DFileWriter::addStandardBlock_PointSetDeclaration(const mlU3D::PointSetGenerator& pointSetGenerator) { U3DDataBlockWriter PointSetDeclarationBlock; PointSetDeclarationBlock.blockType = mlU3D::BLOCKTYPE_POINTSETDECLARATION; PointSetDeclarationBlock.writeString(pointSetGenerator.resourceName); // Write Point Set Name (9.6.2.1.1) PointSetDeclarationBlock.writeU32(mlU3D::ReservedZero); // Write Chain Index (9.6.2.1.1) (shall be zero) PointSetDeclarationBlock.writeU32(mlU3D::ReservedZero); // Write Point Set Description - Point Set Reserved (9.6.2.1.3.1) (shall be zero) PointSetDeclarationBlock.writeU32(pointSetGenerator.pointCount); // Write Point Set Description - Point Count (9.6.2.1.3.2) (# of points) PointSetDeclarationBlock.writeU32(pointSetGenerator.pointCount); // Write Point Set Description - Position Count (9.6.2.1.3.3) (# of positions - equals # of points) PointSetDeclarationBlock.writeU32(pointSetGenerator.normalCount); // Write Point Set Description - Normal Count (9.6.2.1.3.4) (# of normals) PointSetDeclarationBlock.writeU32(pointSetGenerator.diffuseColorCount); // Write Point Set Description - Diffuse Color Count (9.6.2.1.3.5) PointSetDeclarationBlock.writeU32(pointSetGenerator.specularColorCount); // Write Point Set Description - Specular Color Count (9.6.2.1.3.6) PointSetDeclarationBlock.writeU32(pointSetGenerator.textureCoordCount); // Write Point Set Description - Texture Coord Count (9.6.2.1.3.7) PointSetDeclarationBlock.writeU32(0x00000001); // Write Point Set Description - Shading Count (9.6.2.1.3.8) PointSetDeclarationBlock.writeU32(pointSetGenerator.shadingAttributes); // Write Point Set Description - Shading Description - Shading Attributes (9.6.1.1.3.9.1) PointSetDeclarationBlock.writeU32(0x00000000); // Write Point Set Description - Shading Description - Texture Layer Count (9.6.1.1.3.9.2) //PointSetDeclarationBlock.writeU32(0x00000000); // Write Point Set Description - Shading Description - Texture Coord Dimensions (9.6.1.1.3.9.3) - only if Texture Layer Count > 0 PointSetDeclarationBlock.writeU32(0x00000000); // Write Point Set Description - Shading Description - Original Shading ID (9.6.1.1.3.9.4) PointSetDeclarationBlock.writeU32(0x000003E8); // Write Resource Description - Quality Factors - Position Quality Factor (9.6.1.1.5.1.1) [UNUSED BY ACROBAT] PointSetDeclarationBlock.writeU32(0x000003E8); // Write Resource Description - Quality Factors - Normal Quality Factor (9.6.1.1.5.1.2) [UNUSED BY ACROBAT] PointSetDeclarationBlock.writeU32(0x000003E8); // Write Resource Description - Quality Factors - Texture Coord Quality Factor (9.6.1.1.5.1.3) [UNUSED BY ACROBAT] PointSetDeclarationBlock.writeF32(1.f / mlU3D::Quant_Position); // Write Resource Description - Inverse Quantization - Position Inverse Quant (9.6.1.1.5.2.1) PointSetDeclarationBlock.writeF32(1.f / mlU3D::Quant_Normal); // Write Resource Description - Inverse Quantization - Normal Inverse Quant (9.6.1.1.5.2.2) PointSetDeclarationBlock.writeF32(1.f / mlU3D::Quant_TextureCoord); // Write Resource Description - Inverse Quantization - Texture Coord Inverse Quant (9.6.1.1.5.2.3) PointSetDeclarationBlock.writeF32(1.f / mlU3D::Quant_DiffuseColor); // Write Resource Description - Inverse Quantization - Diffuse Color Inverse Quant (9.6.1.1.5.2.4) PointSetDeclarationBlock.writeF32(1.f / mlU3D::Quant_SpecularColor); // Write Resource Description - Inverse Quantization - Specular Color Inverse Quant (9.6.1.1.5.2.5) PointSetDeclarationBlock.writeU32(mlU3D::ReservedZero); // Write Resource Description - Resource Parameters - Reserved Point Set Parameter 1 (9.6.2.1.4.3.1) (shall be zero) PointSetDeclarationBlock.writeU32(mlU3D::ReservedZero); // Write Resource Description - Resource Parameters - Reserved Point Set Parameter 2 (9.6.2.1.4.3.2) (shall be zero) PointSetDeclarationBlock.writeU32(mlU3D::ReservedZero); // Write Resource Description - Resource Parameters - Reserved Point Set Parameter 3 (9.6.2.1.4.3.3) (shall be zero) PointSetDeclarationBlock.writeU32(0x00000000); // Write Skeleton Description - Bone Count (9.6.2.1.5) (shall be zero since skeltons are not supported by this version) [UNUSED BY ACROBAT] return addDataBlock(PointSetDeclarationBlock); }
//! Adds a standard data block (type: material resource) to the chain of all data blocks. //! Returns the total # of data blocks in the data block chain. size_t U3DFileWriter::addStandardBlock_MaterialResource(const mlU3D::MaterialResource& materialResource) { U3DDataBlockWriter MaterialResourceBlock; MaterialResourceBlock.blockType = mlU3D::BLOCKTYPE_MATERIALRESOURCE; MaterialResourceBlock.writeString(materialResource.resourceName); // Write Material Resource Name (9.8.4.1) MaterialResourceBlock.writeU32(mlU3D::MATERIALRESOURCEATTRIBUTES_ALL); // Write Material Attributes (9.8.4.2) [UNUSED BY ACROBAT] MaterialResourceBlock.writeF32(materialResource.ambientColor[0]); // Ambient Color - Red (9.8.4.3.1) MaterialResourceBlock.writeF32(materialResource.ambientColor[1]); // Ambient Color - Green (9.8.4.3.2) MaterialResourceBlock.writeF32(materialResource.ambientColor[2]); // Ambient Color - Blue (9.8.4.3.3) MaterialResourceBlock.writeF32(materialResource.diffuseColor[0]); // Diffuse Color - Red (9.8.4.4.1) MaterialResourceBlock.writeF32(materialResource.diffuseColor[1]); // Diffuse Color - Green (9.8.4.4.2) MaterialResourceBlock.writeF32(materialResource.diffuseColor[2]); // Diffuse Color - Blue (9.8.4.4.3) MaterialResourceBlock.writeF32(materialResource.specularColor[0]); // Specular Color - Red (9.8.4.5.1) MaterialResourceBlock.writeF32(materialResource.specularColor[1]); // Specular Color - Green (9.8.4.5.2) MaterialResourceBlock.writeF32(materialResource.specularColor[2]); // Specular Color - Blue (9.8.4.5.3) MaterialResourceBlock.writeF32(materialResource.emissiveColor[0]); // Emissive Color - Red (9.8.4.6.1) MaterialResourceBlock.writeF32(materialResource.emissiveColor[1]); // Emissive Color - Green (9.8.4.6.2) MaterialResourceBlock.writeF32(materialResource.emissiveColor[2]); // Emissive Color - Blue (9.8.4.6 MaterialResourceBlock.writeF32(materialResource.reflectivity); // Write Reflectivity (9.8.4.7) MaterialResourceBlock.writeF32(materialResource.diffuseColor[3]); // Write Opacity (9.8.4.8) return addDataBlock(MaterialResourceBlock); }
//! Adds a standard data block (type: material resource) to the chain of all data blocks. //! Returns the total # of data blocks in the data block chain. size_t U3DFileWriter::addStandardBlock_MaterialResourceWithDefaultLight(const std::string& materialResourceName) { U3DDataBlockWriter MaterialResourceBlock; MaterialResourceBlock.blockType = mlU3D::BLOCKTYPE_MATERIALRESOURCE; MaterialResourceBlock.writeString(materialResourceName); // Write Material Resource Name (9.8.4.1) MaterialResourceBlock.writeU32(mlU3D::MATERIALRESOURCEATTRIBUTES_ALL); // Write Material Attributes (9.8.4.2) MaterialResourceBlock.writeF32(1.0f); // Ambient Color - Red (9.8.4.3.1) MaterialResourceBlock.writeF32(1.0f); // Ambient Color - Green (9.8.4.3.2) MaterialResourceBlock.writeF32(1.0f); // Ambient Color - Blue (9.8.4.3.3) MaterialResourceBlock.writeF32(0.65f); // Diffuse Color - Red (9.8.4.4.1) MaterialResourceBlock.writeF32(0.65f); // Diffuse Color - Green (9.8.4.4.2) MaterialResourceBlock.writeF32(0.65f); // Diffuse Color - Blue (9.8.4.4.3) MaterialResourceBlock.writeF32(0.75f); // Specular Color - Red (9.8.4.5.1) MaterialResourceBlock.writeF32(0.75f); // Specular Color - Green (9.8.4.5.2) MaterialResourceBlock.writeF32(0.75f); // Specular Color - Blue (9.8.4.5.3) MaterialResourceBlock.writeF32(0.0f); // Emissive Color - Red (9.8.4.6.1) MaterialResourceBlock.writeF32(0.0f); // Emissive Color - Green (9.8.4.6.2) MaterialResourceBlock.writeF32(0.0f); // Emissive Color - Blue (9.8.4.6 MaterialResourceBlock.writeF32(0.5f); // Write Reflectivity (9.8.4.7) MaterialResourceBlock.writeF32(1.0f); // Write Opacity (9.8.4.8) return addDataBlock(MaterialResourceBlock); }
//! Adds a standard data block (type: material resource) to the chain of all data blocks. //! Returns the total # of data blocks in the data block chain. size_t U3DFileWriter::addStandardBlock_MaterialResource(const U3DObjectInfoStruct& objectInfo) { U3DDataBlockWriter MaterialResourceBlock; MaterialResourceBlock.blockType = U3D_BLOCKTYPE_MATERIALRESOURCE; MaterialResourceBlock.writeString(objectInfo.MaterialName); // Write Material Resource Name (9.8.4.1) MaterialResourceBlock.writeU32(U3D_MATERIALRESOURCEATTRIBUTES_ALL); // Write Material Attributes (9.8.4.2) [UNUSED BY ACROBAT] MaterialResourceBlock.writeF32(objectInfo.AmbientColor[0]); // Ambient Color - Red (9.8.4.3.1) MaterialResourceBlock.writeF32(objectInfo.AmbientColor[1]); // Ambient Color - Green (9.8.4.3.2) MaterialResourceBlock.writeF32(objectInfo.AmbientColor[2]); // Ambient Color - Blue (9.8.4.3.3) MaterialResourceBlock.writeF32(objectInfo.DiffuseColor[0]); // Diffuse Color - Red (9.8.4.4.1) MaterialResourceBlock.writeF32(objectInfo.DiffuseColor[1]); // Diffuse Color - Green (9.8.4.4.2) MaterialResourceBlock.writeF32(objectInfo.DiffuseColor[2]); // Diffuse Color - Blue (9.8.4.4.3) MaterialResourceBlock.writeF32(objectInfo.SpecularColor[0]); // Specular Color - Red (9.8.4.5.1) MaterialResourceBlock.writeF32(objectInfo.SpecularColor[1]); // Specular Color - Green (9.8.4.5.2) MaterialResourceBlock.writeF32(objectInfo.SpecularColor[2]); // Specular Color - Blue (9.8.4.5.3) MaterialResourceBlock.writeF32(objectInfo.EmissiveColor[0]); // Emissive Color - Red (9.8.4.6.1) MaterialResourceBlock.writeF32(objectInfo.EmissiveColor[1]); // Emissive Color - Green (9.8.4.6.2) MaterialResourceBlock.writeF32(objectInfo.EmissiveColor[2]); // Emissive Color - Blue (9.8.4.6 MaterialResourceBlock.writeF32(0.5f); // Write Reflectivity (9.8.4.7) MaterialResourceBlock.writeF32(objectInfo.DiffuseColor[3]); // Write Opacity (9.8.4.8) return addDataBlock(MaterialResourceBlock); }
//! Write parent node data to the respective position of a (child) node block. (private) void U3DFileWriter::_writeParentNodeData(U3DDataBlockWriter& dataBlock, const std::string& parentNodeName) { dataBlock.writeU32(0x00000001); // Write Parent Node Count (9.5.1.2.1) dataBlock.writeString(parentNodeName); // Write empty Parent Node Name (9.5.1.2.2) dataBlock.writeIdentityMatrix(); // Write Parent Node Transform Matrix (9.5.1.2.3) (identity matrix) }
U3DDataBlockWriter U3DSave::_createCLODBaseMeshContinuationBlock(WEMTrianglePatch* meshPatch, mlU3D::CLODMeshGenerator& meshGenerator) const { mlU3D::ColorMap baseDiffuseColorsMap; float progressStart = 0.2f; float progressEnd = 0.9f; float progressRangeforAllMeshes = progressEnd - progressStart; // 0.7 float progressIntervalForOneWEMPatch = progressRangeforAllMeshes / _inU3DObject->meshes.size(); float progressStartForThisMesh = progressStart + progressIntervalForOneWEMPatch * meshGenerator.meshNumber; _progressFld->setFloatValue(progressStartForThisMesh); _statusFld->setStringValue("Assembling data for Mesh: " + meshGenerator.resourceName + "."); U3DDataBlockWriter thisCLODBaseMeshContinuationBlock; thisCLODBaseMeshContinuationBlock.blockType = mlU3D::BLOCKTYPE_CLODBASEMESHCONTINUATION; thisCLODBaseMeshContinuationBlock.writeString(meshGenerator.resourceName); // Write Mesh Name (9.6.1.2.1) thisCLODBaseMeshContinuationBlock.writeU32(mlU3D::ReservedZero); // Write Chain Index (9.6.1.2.2) (shall be zero) thisCLODBaseMeshContinuationBlock.writeU32(meshGenerator.faceCount); // Write Base Mesh Description - Face Count (9.6.1.2.3.1) (# of faces) thisCLODBaseMeshContinuationBlock.writeU32(meshGenerator.vertexCount); // Write Base Mesh Description - Position Count (9.6.1.2.3.2) (# of vertices) thisCLODBaseMeshContinuationBlock.writeU32(meshGenerator.normalCount); // Write Base Mesh Description - Normal Count (9.6.1.2.3.3) (# of normals) thisCLODBaseMeshContinuationBlock.writeU32(meshGenerator.diffuseColorCount); // Write Base Mesh Description - Diffuse Color Count (9.6.1.2.3.4) thisCLODBaseMeshContinuationBlock.writeU32(meshGenerator.specularColorCount); // Write Base Mesh Description - Specular Color Count (9.6.1.2.3.5) thisCLODBaseMeshContinuationBlock.writeU32(0x00000001); // Write Base Mesh Description - Texture Coord Count (9.6.1.2.3.6) // Write all vertex positions (in U3D, vertices are called "positions") for (MLuint32 thisVertex = 0; thisVertex < meshGenerator.vertexCount; thisVertex++) { Vector3 wemPosition = meshPatch->getNodeAt(thisVertex)->getPosition(); thisCLODBaseMeshContinuationBlock.writeF32(wemPosition[0]); // Write Base Position - X (9.6.1.2.4.1.1) thisCLODBaseMeshContinuationBlock.writeF32(wemPosition[1]); // Write Base Position - Y (9.6.1.2.4.1.2) thisCLODBaseMeshContinuationBlock.writeF32(wemPosition[2]); // Write Base Position - Z (9.6.1.2.4.1.3) } for (MLuint32 thisNormal = 0; thisNormal < meshGenerator.normalCount; thisNormal++) { Vector3 nodeNormal = meshPatch->getNodeAt(thisNormal)->getNormal(); thisCLODBaseMeshContinuationBlock.writeF32(nodeNormal[0]); // Write Base Normal - X (9.6.1.2.4.2.1) thisCLODBaseMeshContinuationBlock.writeF32(nodeNormal[1]); // Write Base Normal - Y (9.6.1.2.4.2.2) thisCLODBaseMeshContinuationBlock.writeF32(nodeNormal[2]); // Write Base Normal - Z (9.6.1.2.4.2.3) } if (meshGenerator.diffuseColorCount > 0) { baseDiffuseColorsMap = _writeVertexColors(meshPatch, thisCLODBaseMeshContinuationBlock); // Write all Base Diffuse Colors (9.6.1.2.4.3) } for (MLuint32 thisSpecularColor = 0; thisSpecularColor < meshGenerator.specularColorCount; thisSpecularColor++) { thisCLODBaseMeshContinuationBlock.writeF32Color(_inU3DObject->defaultValues.defaultMaterialSpecularColor, 1.0f); // Write Base Specular Color (9.6.1.2.4.4) } // Write Write Base Texture Coord (9.6.1.2.4.5) thisCLODBaseMeshContinuationBlock.writeF32(0.0f); // Write Base Texture Coord U (9.6.1.2.4.5.1) thisCLODBaseMeshContinuationBlock.writeF32(0.0f); // Write Base Texture Coord V (9.6.1.2.4.5.2) thisCLODBaseMeshContinuationBlock.writeF32(0.0f); // Write Base Texture Coord S (9.6.1.2.4.5.3) thisCLODBaseMeshContinuationBlock.writeF32(0.0f); // Write Base Texture Coord T (9.6.1.2.4.5.4) for (MLuint32 thisFace = 0; thisFace < meshGenerator.faceCount; thisFace++) { thisCLODBaseMeshContinuationBlock.writeCompressedU32(mlU3D::Context_cShading, 0); // Write Shading ID (9.6.1.2.4.6.1) WEMFace* wemFace = meshPatch->getFaceAt(thisFace); for (MLuint thisNode = 0; thisNode < 3; thisNode++) { WEMNode* thisWEMNode = wemFace->getNodeAt(static_cast<unsigned int>(thisNode)); const MLuint32 VertexIndex = thisWEMNode->getEntryNumber(); const Vector4 thisWEMNodeColor = thisWEMNode->getColor(); MLuint32 NormalIndex = VertexIndex; // Write Base Corner Info - Base Position Index (9.6.1.2.4.6.2.1) thisCLODBaseMeshContinuationBlock.writeCompressedU32(mlU3D::Context_StaticFull + meshGenerator.vertexCount, VertexIndex); // Write Base Corner Info - Base Normal Index (9.6.1.2.4.6.2.2) if (meshGenerator.normalCount > 0) { thisCLODBaseMeshContinuationBlock.writeCompressedU32(mlU3D::Context_StaticFull + meshGenerator.normalCount, NormalIndex); } // Write Base Corner Info - Base Diffuse Color Index (9.6.1.2.4.6.2.3) if (meshGenerator.diffuseColorCount > 0) { MLuint32 diffuseColorIndex = baseDiffuseColorsMap[thisWEMNodeColor]; thisCLODBaseMeshContinuationBlock.writeCompressedU32(mlU3D::Context_StaticFull + meshGenerator.diffuseColorCount, diffuseColorIndex); } // Write Base Corner Info - Base Specular Color Index (9.6.1.2.4.6.2.4) if (meshGenerator.specularColorCount > 0) { thisCLODBaseMeshContinuationBlock.writeCompressedU32(mlU3D::Context_StaticFull + meshGenerator.specularColorCount, 0); } // Write Base Corner Info - Base Texture Coord Index (9.6.1.2.4.6.2.5) //thisCLODBaseMeshContinuationBlock.writeCompressedU32(U3D_StaticFull+1, 0); // No texture layers } if (0 == (thisFace % 100)) // Set progress field every 100 faces to save GUI update cost { float progressFldThisFaceValue = (progressIntervalForOneWEMPatch / meshGenerator.faceCount) * (thisFace + 1); float progressFldValue = progressStartForThisMesh + progressFldThisFaceValue; _progressFld->setFloatValue(progressFldValue); } } return thisCLODBaseMeshContinuationBlock; }
ML_START_NAMESPACE //*********************************************************************************** U3DDataBlockWriter U3DSave::_createPointSetContinuationBlock(mlU3D::PointSetGenerator &pointSetGenerator) const { MLuint8 signsXYZ; MLuint32 diffX; MLuint32 diffY; MLuint32 diffZ; _statusFld->setStringValue("Assembling data for PointSet: " + pointSetGenerator.resourceName + "."); U3DDataBlockWriter thisPointSetContinuationBlock; thisPointSetContinuationBlock.blockType = mlU3D::BLOCKTYPE_POINTSETCONTINUATION; thisPointSetContinuationBlock.writeString(pointSetGenerator.resourceName); // Write Point Set Name (9.6.2.2.1) thisPointSetContinuationBlock.writeU32(mlU3D::ReservedZero); // Write Chain Index (9.6.2.2.2) (shall be zero) thisPointSetContinuationBlock.writeU32(0x00000000); // Write Point Resolution Range - Start Resolution (9.6.2.2.3.1) thisPointSetContinuationBlock.writeU32(pointSetGenerator.pointCount); // Write Point Resolution Range - End Resolution (9.6.2.2.3.2) (# of points) for (MLuint32 currentPosition = 0; currentPosition < pointSetGenerator.pointCount; currentPosition++) { MLint32 splitPositionIndex = currentPosition - 1; if (0 == currentPosition) // Special case for first position! // No split position and no diff - instead the position itself is written { thisPointSetContinuationBlock.writeCompressedU32(mlU3D::Context_StaticFull + 0x00000001, 0); // Write Split Position Index (9.6.2.2.4.1) } else { thisPointSetContinuationBlock.writeCompressedU32(mlU3D::Context_StaticFull + currentPosition, splitPositionIndex); // Write Split Position Index (9.6.2.2.4.1) } // Write New Position Info (9.6.2.2.4.2) mlU3D::PositionStruct currentPositionData = pointSetGenerator.positions[currentPosition]; mlU3D::PositionStruct predictedPositionData; if (splitPositionIndex >= 0) { predictedPositionData = pointSetGenerator.positions[splitPositionIndex]; } Vector3 positionDifferenceVec3 = currentPositionData.position - predictedPositionData.position; mlU3D::U3DTools::quantizePosition(positionDifferenceVec3, signsXYZ, diffX, diffY, diffZ); thisPointSetContinuationBlock.writeCompressedU8(mlU3D::Context_cPosDiffSign, signsXYZ); // Write New Position Info - Position Difference Signs (9.6.1.3.4.10.1) thisPointSetContinuationBlock.writeCompressedU32(mlU3D::Context_cPosDiffX, diffX); // Write New Position Info - Position Difference X (9.6.1.3.4.10.2) thisPointSetContinuationBlock.writeCompressedU32(mlU3D::Context_cPosDiffY, diffY); // Write New Position Info - Position Difference Y (9.6.1.3.4.10.3) thisPointSetContinuationBlock.writeCompressedU32(mlU3D::Context_cPosDiffZ, diffZ); // Write New Position Info - Position Difference Z (9.6.1.3.4.10.4) MLuint32 newPointCount = 1; // Always add 1 new point in this version MLuint32 newNormalCount = ((pointSetGenerator.normalCount > 0) ? newPointCount : 0); // Should be zero -> no normals in this version thisPointSetContinuationBlock.writeCompressedU32(mlU3D::Context_cNormlCnt, newNormalCount); // Write Point Description - New Normal Count (9.6.2.2.4.3) - always 1 normal per point // Write New Normal Info (9.6.2.2.4.4) [UNUSED BY ACROBAT] for (MLuint32 newNormalIndex = 0; newNormalIndex < newNormalCount; newNormalIndex++) { //Vector3 currentNormalVec3; currentNormalVec3.x = 0; currentNormalVec3.y = 0; currentNormalVec3.z = 0; //Vector3 predictedNormalVec3 = currentNormalVec3; // Normals are always 0,0,0 in this version Vector3 normalDifferenceVec3;// = currentNormalVec3 - predictedNormalVec3; mlU3D::U3DTools::quantizeNormal(normalDifferenceVec3, signsXYZ, diffX, diffY, diffZ); // Write normal at line start thisPointSetContinuationBlock.writeCompressedU8(mlU3D::Context_cDiffNormalSign, signsXYZ); // Write Normal Difference Signs (9.6.2.2.4.4.1) thisPointSetContinuationBlock.writeCompressedU32(mlU3D::Context_cDiffNormalX, diffX); // Write Normal Difference X (9.6.2.2.4.4.2) thisPointSetContinuationBlock.writeCompressedU32(mlU3D::Context_cDiffNormalY, diffY); // Write Normal Difference Y (9.6.2.2.4.4.3) thisPointSetContinuationBlock.writeCompressedU32(mlU3D::Context_cDiffNormalZ, diffZ); // Write Normal Difference Z (9.6.2.2.4.4.4) } thisPointSetContinuationBlock.writeCompressedU32(mlU3D::Context_cPointCnt_cLineCnt_cFaceCnt, newPointCount); // Write Point Description - New Point Count (9.6.2.2.4.5) // Write New Point Info (9.6.2.2.4.6) for (MLuint32 newPointInfoNumber = 0; newPointInfoNumber < newPointCount; newPointInfoNumber++) { thisPointSetContinuationBlock.writeCompressedU32(mlU3D::Context_cShading, 0x00000000); // Write Shading ID (9.6.2.2.4.6.1) thisPointSetContinuationBlock.writeCompressedU32(mlU3D::Context_cNormlIdx, newPointInfoNumber); // Write Normal Local Index (9.6.2.2.4.6.2) - Must be written although no normals are used at all in this version! // Write no New Point Diffuse Color Coords (9.6.2.2.4.6.3) since it is not supported by this version // Write no New Point Specular Color Coords (9.6.2.2.4.6.4) since it is not supported by this version [UNUSED BY ACROBAT] // Write no New Point Texture Coords (9.6.2.2.4.6.5) since it is not supported by this version [UNUSED BY ACROBAT] } } // for (MLuint32 currentPosition = 0... return thisPointSetContinuationBlock; }
U3DDataBlockWriter U3DSave::_createLineSetContinuationBlock(mlU3D::LineSetGenerator &lineSetGenerator) const { MLuint8 signsXYZ; MLuint32 diffX; MLuint32 diffY; MLuint32 diffZ; _statusFld->setStringValue("Assembling data for LineSet: " + lineSetGenerator.resourceName + "."); U3DDataBlockWriter thisLineSetContinuationBlock; thisLineSetContinuationBlock.blockType = mlU3D::BLOCKTYPE_LINESETCONTINUATION; thisLineSetContinuationBlock.writeString(lineSetGenerator.resourceName); // Write Line Set Name (9.6.3.2.1) thisLineSetContinuationBlock.writeU32(mlU3D::ReservedZero); // Write Chain Index (9.6.3.2.2) (shall be zero) thisLineSetContinuationBlock.writeU32(0x00000000); // Write Point Resolution Range - Start Resolution (9.6.3.2.3.1) thisLineSetContinuationBlock.writeU32(lineSetGenerator.pointCount); // Write Point Resolution Range - End Resolution (9.6.3.2.3.2) (# of points) for (MLuint32 currentPosition = 0; currentPosition < lineSetGenerator.pointCount; currentPosition++) { if (0 == currentPosition) // Special case for first position! // No split position and no diff - instead the position itself is written { mlU3D::PositionStruct startPosition = lineSetGenerator.positions[currentPosition]; mlU3D::U3DTools::quantizePosition(startPosition.position, signsXYZ, diffX, diffY, diffZ); thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_StaticFull + 1, 0); // Write Line Description - Split Position Index (9.6.3.2.4.1) - for first entry with special value 0 and special context "r1" instead of "r0" thisLineSetContinuationBlock.writeCompressedU8(mlU3D::Context_cPosDiffSign, signsXYZ); // Write Line Description - New Position Info - Position Difference Signs (9.6.1.3.4.10.1) thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_cPosDiffX, diffX); // Write Line Description - New Position Info - Position Difference X (9.6.1.3.4.10.2) thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_cPosDiffY, diffY); // Write Line Description - New Position Info - Position Difference Y (9.6.1.3.4.10.3) thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_cPosDiffZ, diffZ); // Write Line Description - New Position Info - Position Difference Z (9.6.1.3.4.10.4) thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_cNormlCnt, 0); // Write Line Description - New Normal Count (9.6.3.2.4.3) thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_cPointCnt_cLineCnt_cFaceCnt, 0); // Write Line Description - New Line Count (9.6.3.2.4.5) } else { MLuint32 splitPosition = currentPosition - 1; mlU3D::PositionStruct currentPositionData = lineSetGenerator.positions[currentPosition]; mlU3D::PositionStruct predictedPositionData = lineSetGenerator.positions[splitPosition]; Vector3 positionDifferenceVec3 = currentPositionData.position - predictedPositionData.position; mlU3D::U3DTools::quantizePosition(positionDifferenceVec3, signsXYZ, diffX, diffY, diffZ); thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_StaticFull + currentPosition, splitPosition); // Write Line Description - Split Position Index (9.6.3.2.4.1) thisLineSetContinuationBlock.writeCompressedU8(mlU3D::Context_cPosDiffSign, signsXYZ); // Write Line Description - New Position Info - Position Difference Signs (9.6.1.3.4.10.1) thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_cPosDiffX, diffX); // Write Line Description - New Position Info - Position Difference X (9.6.1.3.4.10.2) thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_cPosDiffY, diffY); // Write Line Description - New Position Info - Position Difference Y (9.6.1.3.4.10.3) thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_cPosDiffZ, diffZ); // Write Line Description - New Position Info - Position Difference Z (9.6.1.3.4.10.4) mlU3D::LinesVector newLines = mlU3D::U3DMarkerListTools::getNewLinesFromAllLines(lineSetGenerator.lines, currentPosition); MLuint32 newLineCount = (MLuint32)newLines.size(); MLuint32 newNormalCount = (MLuint32)((lineSetGenerator.normalCount > 0) ? newLineCount : 0); // Should be zero -> no normals in this version thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_cNormlCnt, newNormalCount * 2); // Write Line Description - New Normal Count (9.6.2.2.4.3) - always 2 normals per line // Write New Normal Info (9.6.3.2.4.4) [UNUSED BY ACROBAT] for (MLuint32 newNormalIndex = 0; newNormalIndex < newNormalCount; newNormalIndex++) { //Vector3 currentNormalVec3; currentNormalVec3.x = 0; currentNormalVec3.y = 0; currentNormalVec3.z = 0; //Vector3 predictedNormalVec3 = currentNormalVec3; // Normals are always 0,0,0 in this version Vector3 normalDifferenceVec3;// = currentNormalVec3 - predictedNormalVec3; mlU3D::U3DTools::quantizeNormal(normalDifferenceVec3, signsXYZ, diffX, diffY, diffZ); // Write normal at line start thisLineSetContinuationBlock.writeCompressedU8(mlU3D::Context_cDiffNormalSign, signsXYZ); // Write Normal Difference Signs (9.6.2.2.4.4.1) thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_cDiffNormalX, diffX); // Write Normal Difference X (9.6.2.2.4.4.2) thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_cDiffNormalY, diffY); // Write Normal Difference Y (9.6.2.2.4.4.3) thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_cDiffNormalZ, diffZ); // Write Normal Difference Z (9.6.2.2.4.4.4) // Write normal at line end thisLineSetContinuationBlock.writeCompressedU8(mlU3D::Context_cDiffNormalSign, signsXYZ); // Write Normal Difference Signs (9.6.2.2.4.4.1) thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_cDiffNormalX, diffX); // Write Normal Difference X (9.6.2.2.4.4.2) thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_cDiffNormalY, diffY); // Write Normal Difference Y (9.6.2.2.4.4.3) thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_cDiffNormalZ, diffZ); // Write Normal Difference Z (9.6.2.2.4.4.4) } thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_cPointCnt_cLineCnt_cFaceCnt, newLineCount); // Write Point Description - New Line Count (9.6.3.2.4.5) // Write New Line Info (9.6.3.2.4.6) for (MLuint32 newLineInfoNumber = 0; newLineInfoNumber < newLineCount; newLineInfoNumber++) { MLuint32 startPosition = newLines[newLineInfoNumber].startIndex; thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_cShading, 0x00000000); // Write Shading ID (9.6.3.2.4.6.1) thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_StaticFull + currentPosition, startPosition); // Write First Position Index (9.6.3.2.4.6.2) for (MLuint32 j = 0; j<2; j++) { MLuint32 normalLocalIndex = ((newNormalCount > 0) ? 2 * newLineInfoNumber + j : 0); // newLineNumber shall always be be 0, so normalLocalIndex is 0 or 1 thisLineSetContinuationBlock.writeCompressedU32(mlU3D::Context_cNormlIdx, normalLocalIndex); // Write Normal Local Index (9.6.3.2.4.6.3) [UNUSED BY ACROBAT] // Write no New Line Diffuse Color Coords (9.6.3.2.4.6.4) since it is not supported by this version // Write no New Line Specular Color Coords (9.6.3.2.4.6.5) since it is not supported by this version [UNUSED BY ACROBAT] // Write no New Line Texture Coords (9.6.3.2.4.6.6) since it is not supported by this version [UNUSED BY ACROBAT] } } } // if (0 == currentPosition)... } // for (MLuint32 currentPosition... return thisLineSetContinuationBlock; }