OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myOffset)
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myLength)
}
+
+// ================================================================
+// Function : WriteToBuffer
+// Purpose :
+// ================================================================
+void Image_Texture::WriteToBuffer()
+{
+ if (this == nullptr || myImagePath.IsEmpty())
+ {
+ return;
+ }
+
+ const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+ std::shared_ptr<std::istream> aFileIn = aFileSystem->OpenIStream(myImagePath, std::ios::in | std::ios::binary);
+ if (aFileIn.get() == nullptr)
+ {
+ Message::SendFail(TCollection_AsciiString("Error: Unable to open file ") + myImagePath + "!");
+ return;
+ }
+
+ int64_t aLength = myLength;
+ if (myOffset == -1 && myLength == -1)
+ {
+ aFileIn->seekg(0, std::ios::end);
+ aLength = aFileIn->tellg();
+ aFileIn->seekg(0, std::ios::beg);
+ }
+ else
+ {
+ aFileIn->seekg(myOffset);
+ }
+ myBuffer = new NCollection_Buffer(NCollection_BaseAllocator::CommonBaseAllocator(), aLength);
+ aFileIn->read((char*)myBuffer->ChangeData(), aLength);
+ myImagePath.Clear();
+}
//! Dumps the content of me into the stream
Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
+ //! Write texture to buffer, if file path, offset and length are known
+ //! This function is use only when user has turn on parameter by XSetUseTextureBuffer function
+ Standard_EXPORT void WriteToBuffer();
+
protected:
//! Read image from normal image file.
//=======================================================================
XCAFDoc_VisMaterialTool::XCAFDoc_VisMaterialTool()
{
- //
+ myUseTextureBuffer = false;
}
//=======================================================================
{
TDF_TagSource aTag;
TDF_Label aLab = aTag.NewChild (Label());
+ if (myUseTextureBuffer)
+ changeVisMaterial(theMat);
aLab.AddAttribute (theMat);
if (!theName.IsEmpty())
{
? GetMaterial (aMatLabel)
: Handle(XCAFDoc_VisMaterial)();
}
+
+//=======================================================================
+//function : changeVisMaterial
+//purpose :
+//=======================================================================
+void XCAFDoc_VisMaterialTool::changeVisMaterial(const Handle(XCAFDoc_VisMaterial)& theMat) const
+{
+ if (theMat->HasCommonMaterial())
+ {
+ theMat->CommonMaterial().DiffuseTexture->WriteToBuffer();
+ }
+ if (theMat->HasPbrMaterial())
+ {
+ theMat->PbrMaterial().BaseColorTexture->WriteToBuffer();
+ theMat->PbrMaterial().MetallicRoughnessTexture->WriteToBuffer();
+ theMat->PbrMaterial().EmissiveTexture->WriteToBuffer();
+ theMat->PbrMaterial().OcclusionTexture->WriteToBuffer();
+ theMat->PbrMaterial().NormalTexture->WriteToBuffer();
+ }
+}
//! Returns material assigned to shape or NULL if not assigned.
Standard_EXPORT Handle(XCAFDoc_VisMaterial) GetShapeMaterial (const TopoDS_Shape& theShape);
+ //! Return parameter for use texture buffer
+ const Standard_Boolean GetUseTextureBuffer() { return myUseTextureBuffer; }
+
+ //! Set parameter for use texture buffer
+ void SetUseTextureBuffer(const Standard_Boolean theUseBuffer) { myUseTextureBuffer = theUseBuffer; }
+
public:
//! Returns GUID of this attribute type.
virtual void Paste (const Handle(TDF_Attribute)& ,
const Handle(TDF_RelocationTable)& ) const Standard_OVERRIDE {}
+protected:
+
+ //! Reading a texture from file and save it to buffer
+ void changeVisMaterial(const Handle(XCAFDoc_VisMaterial)& theMat) const;
+
private:
+ Standard_Boolean myUseTextureBuffer;
Handle(XCAFDoc_ShapeTool) myShapeTool;
};
#include <XCAFDoc_LayerTool.hxx>
#include <XCAFDoc_Material.hxx>
#include <XCAFDoc_ShapeTool.hxx>
+#include <XCAFDoc_VisMaterialTool.hxx>
#include <XCAFDoc_Volume.hxx>
#include <XCAFPrs.hxx>
#include <XCAFPrs_AISObject.hxx>
return 0;
}
+//=======================================================================
+// function: XGetUseTextureBuffer
+// purpose: return current value of parameter
+//=======================================================================
+static Standard_Integer XGetUseTextureBuffer(Draw_Interpretor& di,
+ Standard_Integer argc,
+ const char** argv)
+{
+ if (argc < 2)
+ {
+ return 1;
+ }
+ Handle(TDocStd_Document) aDoc;
+ if (!DDocStd::GetDocument(argv[1], aDoc))
+ {
+ return 1;
+ }
+
+ Handle(XCAFDoc_VisMaterialTool) aVisMatTool = XCAFDoc_DocumentTool::VisMaterialTool(aDoc->Main());
+ if (aVisMatTool.IsNull())
+ {
+ return 1;
+ }
+ const char* aStr = aVisMatTool->GetUseTextureBuffer() ? "on" : "off";
+ di << "Current value is \"" << aStr << "\"" << "\n";
+
+ return 0;
+}
+
+//=======================================================================
+// function: XSetUseTextureBuffer
+// purpose: change parameter for store texture (on/off),
+// file path is use by default in case "off"
+//=======================================================================
+static Standard_Integer XSetUseTextureBuffer(Draw_Interpretor& di,
+ Standard_Integer argc,
+ const char** argv)
+{
+ if (argc < 3)
+ {
+ return 1;
+ }
+ Handle(TDocStd_Document) aDoc;
+ if (!DDocStd::GetDocument(argv[1], aDoc))
+ {
+ return 1;
+ }
+ bool aBuffOn = false;
+ if (!Draw::ParseOnOff(argv[2], aBuffOn))
+ {
+ return 1;
+ }
+
+ Handle(XCAFDoc_VisMaterialTool) aVisMatTool = XCAFDoc_DocumentTool::VisMaterialTool(aDoc->Main());
+ if (aVisMatTool.IsNull())
+ {
+ return 1;
+ }
+ aVisMatTool->SetUseTextureBuffer(aBuffOn);
+
+ (void)di;
+ return 0;
+}
//=======================================================================
//function : Init
di.Add("XRescaleGeometry",
"Doc factor [-root label] [-force]: Applies geometrical scale to assembly",
__FILE__, XRescaleGeometry, g);
+ di.Add("XGetUseTextureBuffer",
+ "Doc : return value of parameter for texture buffer usage",
+ __FILE__, XGetUseTextureBuffer, g);
+ di.Add("XSetUseTextureBuffer",
+ "Doc {on|off} : turns on/off texture buffer usage; \"off\" is use by default,\n"
+ "it means texture will store length, offset and will be read from file;\n"
+ "in case \"on\" texture data will be store in buffer",
+ __FILE__, XSetUseTextureBuffer, g);
// Specialized commands
XDEDRAW_Shapes::InitCommands ( di );
--- /dev/null
+puts "========"
+puts "0033451: Saving texture to buffer"
+puts "Checks store texture in .xbf file"
+puts "========"
+
+Close D -silent
+XNewDoc D
+XSetUseTextureBuffer D on
+ReadGltf D [locate_data_file bug31706_launchvehicle.glb] -noCreateDoc
+
+set aTmpFile ${imagedir}/result.xbf
+XSave D $aTmpFile
+Close D
+Open $aTmpFile D
+set data1 [XGetVisMaterial D 0:1:10:1]
+set data2 [XGetVisMaterial D 0:1:10:5]
+
+if {[string first "PBR.BaseColorTexture" $data1] == -1
+ || [string first "PBR.EmissiveTexture" $data1] == -1} {
+ puts "Error: Texture is not found"
+}
+if {[string first "PBR.BaseColorTexture" $data2] == -1
+ || [string first "PBR.MetallicRoughnessTexture" $data2] == -1
+ || [string first "PBR.OcclusionTexture" $data2] == -1
+ || [string first "PBR.NormalTexture" $data2] == -1} {
+ puts "Error: Texture is not found"
+}
+
+vinit View1
+XDisplay -dispMode 1 D
+vfit
+if { [vreadpixel 50 300 rgb name] != "WHITE" || [vreadpixel 120 250 rgb name] != "LEMONCHIFFON1" } {
+ puts "Error: color not match"
+}
+
+Close D
+file delete -force $aTmpFile
--- /dev/null
+puts "========"
+puts "0033451: Saving texture to buffer"
+puts "Checks store texture in .xml file"
+puts "========"
+
+Close D -silent
+XNewDoc D
+#XSetUseTextureBuffer D on
+ReadGltf D [locate_data_file bug31706_launchvehicle.glb] -noCreateDoc
+
+set aTmpFile ${imagedir}/res.xml
+Format D XmlXCAF
+XSave D $aTmpFile
+Close D
+XOpen $aTmpFile D
+set data1 [XGetVisMaterial D 0:1:10:1]
+set data2 [XGetVisMaterial D 0:1:10:5]
+
+if {[string first "PBR.BaseColorTexture" $data1] == -1
+ || [string first "PBR.EmissiveTexture" $data1] == -1} {
+ puts "Error: Texture is not found"
+}
+if {[string first "PBR.BaseColorTexture" $data2] == -1
+ || [string first "PBR.MetallicRoughnessTexture" $data2] == -1
+ || [string first "PBR.OcclusionTexture" $data2] == -1
+ || [string first "PBR.NormalTexture" $data2] == -1} {
+ puts "Error: Texture is not found"
+}
+
+vinit View1
+XDisplay -dispMode 1 D
+vfit
+if { [vreadpixel 50 300 rgb name] != "WHITE" || [vreadpixel 120 250 rgb name] != "LEMONCHIFFON1" } {
+ puts "Error: color not match"
+}
+
+Close D
+file delete -force $aTmpFile
--- /dev/null
+puts "========"
+puts "0033451: Saving texture to buffer"
+puts "Checks store texture in .xbf file"
+puts "========"
+
+Close D -silent
+XNewDoc D
+XSetUseTextureBuffer D on
+ReadObj D [locate_data_file ship_boat.obj] -noCreateDoc
+
+set aTmpFile ${imagedir}/result.xbf
+XSave D $aTmpFile
+Close D
+Open $aTmpFile D
+set data [XGetVisMaterial D 0:1:10:3]
+
+if {[string first "Common.DiffuseTexture" $data] == -1} {
+ puts "Error: Texture is not found"
+}
+
+vinit View1
+XDisplay -dispMode 1 D
+vfit
+if { [vreadpixel 130 300 rgb name] != "ROSYBROWN" } { puts "Error: color not match" }
+if { [vreadpixel 150 250 rgb name] != "ORANGE2" } { puts "Error: color not match" }
+if { [vreadpixel 250 250 rgb name] != "GRAY43" } { puts "Error: color not match" }
+
+Close D
+file delete -force $aTmpFile
--- /dev/null
+puts "========"
+puts "0033451: Saving texture to buffer"
+puts "Checks store texture in .xbf file"
+puts "========"
+
+Close D -silent
+XNewDoc D
+#XSetUseTextureBuffer D on
+ReadObj D [locate_data_file ship_boat.obj] -noCreateDoc
+
+set aTmpFile ${imagedir}/result.xml
+Format D XmlXCAF
+XSave D $aTmpFile
+Close D
+XOpen $aTmpFile D
+set data [XGetVisMaterial D 0:1:10:3]
+
+if {[string first "Common.DiffuseTexture" $data] == -1} {
+ puts "Error: Texture is not found"
+}
+
+vinit View1
+XDisplay -dispMode 1 D
+vfit
+if { [vreadpixel 130 300 rgb name] != "ROSYBROWN" } { puts "Error: color not match" }
+if { [vreadpixel 150 250 rgb name] != "ORANGE2" } { puts "Error: color not match" }
+if { [vreadpixel 250 250 rgb name] != "GRAY43" } { puts "Error: color not match" }
+
+Close D
+file delete -force $aTmpFile