how to redo or undo in ocaf with light or camera or color or material or shader or map

Hello everyone, I don't know how you can use the ocaf framework to realize the undo and redo functions (modify parameters, add, delete) of light, camera, color, material, shader, and map? In other words, according to the occt example, I created a driver with ocaf, but this driver can only generate shapes, not light, etc. Is there any way? Thank you all.

Kirill Gavrilov's picture

There is no OCAF drivers storing things like a light source or a shader program.
Within a custom OCAF document, you will have to implement necessary drivers on your own.

If you refer to TPrsStd document, I would discourage writing an application following its approach.
Package TPrsStd has been developed to demonstrate usage of OCAF mechanisms for working with AIS presentations.
Tight bindings of Document structure to 3D Viewer allow rapid development of simple applications with semi-automatic synchronization of Viewer content with Data Model modifications.
But as application complexity grows up, viewer synchronization might become a burden and cause various performance issues difficult to overcome.

A strict separation of Data Model and its displaying in 3D Viewer is usually more flexible.
Such approach can be seen in XCAF: XCAFDoc defines storage and XCAFPrs provides tools for displaying document in OCCT 3D Viewer.
Synchronization of 3D Viewer content after document modifications should be done at application level in this case.

XCAF document supports definition of visualization material (XCAFDoc_VisMaterialTool/XCAFDoc_VisMaterial), color (XCAFDoc_ColorTool/XCAFDoc_Color), camera (XCAFDoc_ViewTool/XCAFView_Object).
However, XCAF itself is designed for an exchange of quite specific data - assembly structures with properties - and used by STEP, IGES, glTF, OBJ translators.
In case of an application-specific Data Model, an independent OCAF document is expected to be written.
TObj document might be a simpler API (on top of OCAF) for writing your own model structure, although it might be troublesome finding existing code samples for it.

w d's picture

Thank you very much.
1. I saw your answer. I checked, tested and compared XCAFPrs and TPrsStd, and found that they use

Handle(TPrsStd_AISPresentation) prs = TPrsStd_AISPresentation::Set(objectlabel, XCAFPrs_Driver::GetID());

and

Handle(TPrsStd_AISPresentation) prs = TPrsStd_AISPresentation::Set(label, TNaming_NamedShape::GetID());

to Convert a TDF_Label to XCAFPrs_AISObject (inherited from AIS_ColoredShape) and AIS_Shape.
To a certain extent, they are the same. I can't see the difference between XCAFPrs and TPrsStd. If there is a problem with the TPrsStd package, then XCAFPrs will also have a problem.

2. I also checked the Tobj package and found that it does not have any information about the process of creating AIS_Shape. How does he connect the data model with the 3D viewer?

3. I found a way to solve my problem. I can implement a driver by myself and customize a Shape that contains TDF_Label and inherits from AIS_Shape. When creating a new Shape in the driver, I get the relevant attributes from TDF_Label and assign it to AIS_Shape , Is this idea correct?

4.  "The XCAF document supports definition of visualization material (XCAFDoc_VisMaterialTool/XCAFDoc_VisMaterial), color (XCAFDoc_ColorTool/XCAFDoc_Color), camera (XCAFDoc_ViewTool/XCAFView_Object)
However, XCAF itself is designed for an exchange of quite specific data-assembly structures with properties-and used by STEP, IGES, glTF, OBJ translators."     you mentioned it.However, it only includes data storage, if I need to display, I need to write it myself Code, convert TDF_Label to AIS_Shape like the XDEDRAW_XDisplayTool::displayLabel function in XEDDRAW.cxx, if this is the case, it will become very troublesome. Is my understanding correct?

5. I created an ais_shape through ocaf, and set the color and material to it, and then I modified the Topods_Shape corresponding to this AIS_Shape. How to ensure that the color and material remain unchanged? Is this related to ocaf storage? Is it related to TNaming_Builder.Modify? I am a little confused.
Thank you again.