Methods, systems, and devices for implementing undoable operations in 3D object editing

By using a fixed number of command classes and base classes in 3D object editing, the problem of increased development and maintenance costs caused by class bloat in the command pattern is solved, and efficient undoable operations are achieved.

CN116149633BActive Publication Date: 2026-06-30BEI JING YOU NUO KE JI GU FEN YOU XIAN GONG SI

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEI JING YOU NUO KE JI GU FEN YOU XIAN GONG SI
Filing Date
2022-09-09
Publication Date
2026-06-30

AI Technical Summary

Technical Problem

In the process of editing 3D objects, the use of the command pattern to implement undoable operations leads to increased code development and maintenance costs.

Method used

By adopting a fixed number of command classes and the command pattern, a command manager is used to perform push and pop operations to realize the undo operation of 3D object editing. This reduces the number of command classes, centralizes 3D object attributes into four member variables, and avoids class bloat.

Benefits of technology

It effectively solves the problem of increased code development and maintenance costs, ensures that 3D object properties are regenerated every time, avoids external modifications, and achieves efficient undoable operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116149633B_ABST
    Figure CN116149633B_ABST
Patent Text Reader

Abstract

This invention discloses a method, system, and device for implementing undoable operations in 3D object editing, belonging to the field of computer technology applications. The method includes: defining a base class; defining subclasses; defining a command interface, command classes implementing the command interface, and a command manager; and using the command interface, the command manager performs push and pop operations on command objects, where each command object is an instance of the command class. This invention solves the problem of increased code development and maintenance costs due to adding new classes during 3D scene editing, and implements undoable operations in 3D object editing using a command pattern with a fixed number of command classes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology applications, specifically to a method, system, and device for implementing undoable operations in editing 3D objects. Background Technology

[0002] Currently, the Command pattern is used to implement undoable operations in 3D object editing. The Command pattern is a design pattern defined by the Gang of Four (GOF). Specifically, it abstracts command classes that implement the behaviors of other objects into unified command objects that implement an interface, storing the behavior and implementing undoable operations through a stack push and pop operation. As product features increase, new classes are created and continuously added, leading to an increase in related command classes. This increases code development and maintenance costs. Currently, there is no technical solution to this class bloat problem. Summary of the Invention

[0003] To address the shortcomings of existing technologies, this invention proposes a method, system, and device for implementing undoable operations in 3D object editing.

[0004] In a first aspect, the present invention proposes a method for implementing undoable operations in editing 3D objects, comprising the following steps:

[0005] Step S1: Define a base class and define two or more member variables. The base class includes a state base class and an object base class. The type of the member variables is inherited from the state base class.

[0006] Step S2: Define a subclass that inherits from the object base class. Define a member variable state subclass that is unique to the subclass. The member variable state subclass is used to describe the special attributes of the subclass and inherits from the state base class of one of the member variables. The member variable contains subclass information, which is unique to the subclass.

[0007] Step S3: Define the command interface, the command class that implements the command interface, and the command manager;

[0008] Step S4: Through the command interface, the command manager performs push and pop operations on the command object, where the command object is an instantiation of the command class.

[0009] The defined base class also includes a defined method, which is used to take a state object that inherits from the state base class type as input, and update member variables of the same state type according to the state type of the state object.

[0010] The command classes that implement the command interface include: defining a command class to create an object, a command class to delete an object, and a command class to change attributes.

[0011] The command interface includes methods for implementing execution operations and methods for implementing undo operations.

[0012] The defined object creation command class includes:

[0013] When initializing the constructor, 3D object information is recorded, and the 3D object information is the attribute value of the member variable;

[0014] The operation method is implemented by creating a 3D object, wherein the 3D object is created based on the 3D object information.

[0015] The undo operation method is implemented by deleting 3D objects.

[0016] The defined class for deleting objects includes:

[0017] Record 3D object information when initializing the constructor;

[0018] The operation method is executed by deleting a 3D object;

[0019] The undo operation method is implemented by recreating a 3D object, wherein the recreated 3D object is created based on the 3D object information.

[0020] The defined attribute change command class includes:

[0021] The pre-modified member variable value passed to the initialization constructor is used. The member variable type corresponding to the pre-modified member variable value is inherited from the state base class. The pre-modified member variable value is saved, and the original member variable value is also recorded.

[0022] The operation method is executed by passing the pre-modified member variable value through the method defined in the base class.

[0023] The undo operation is achieved by passing in the original member variable value of the corresponding modified member variable.

[0024] Secondly, this invention proposes a system for implementing undoable operations on 3D object editing, comprising:

[0025] The base class definition module is used to define a base class and define two or more member variables. The base class includes a state base class and an object base class, and the type of the member variables is inherited from the state base class.

[0026] The subclass definition module is used to define subclasses that inherit from the object base class. It defines member variable state subclasses that are unique to the subclass. The member variable state subclasses are used to describe the special attributes of the subclass and inherit from the state base class of one of the member variables. The member variables contain subclass information that is unique to the subclass.

[0027] The command interface definition module is used to define the command interface, the command classes that implement the command interface, and the command manager;

[0028] The command implementation module is used to perform push and pop operations on command objects by the command manager through the command interface, wherein the command object is an instantiation of the command class.

[0029] Thirdly, the present invention proposes a device for implementing reversible operations for editing 3D objects, including a memory for storing computer program instructions and a processor for executing the computer program instructions, wherein when the computer program instructions are executed by the processor, the device is triggered to execute the method for implementing reversible operations for editing 3D objects.

[0030] Fourthly, the present invention provides a computer-readable storage medium storing computer program instructions that, when executed on a computer, cause the computer to perform the method for implementing undoable operations on 3D object editing.

[0031] This invention employs a command pattern using a fixed number of command classes to implement the undo function for editing 3D objects. This solves the problem that currently, when implementing the undo function by adding new classes during object editing in 3D scenes, the code development and maintenance costs increase.

[0032] The advantages of additional aspects of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description

[0033] Figure 1 This is a flowchart illustrating a method for implementing undoable operations in 3D object editing according to an embodiment of the present invention.

[0034] Figure 2 This is a system principle block diagram of an embodiment of the present invention for implementing undoable operations in 3D object editing;

[0035] Figure 3 This is a schematic diagram illustrating the type inheritance relationship between the member variable state subclass, the member variable, and the state base class in an embodiment of the present invention. Detailed Implementation

[0036] The principles and features of the present invention are described below with reference to the accompanying drawings. The embodiments described are only for explaining the present invention and are not intended to limit the scope of the present invention.

[0037] To address the issue that existing technologies for implementing undoable operations in 3D object editing face the problem of increased code development and maintenance costs due to class expansion, this invention proposes to implement undoable operation functionality using a command pattern with a fixed number of command classes, specifically by improving upon existing command patterns.

[0038] Currently, based on the command pattern, undo and redo operations in 3D object editing can be implemented. All command objects used in this pattern are instantiations of the command class and are implemented in the command interface. Each command object performs actions that edit the 3D object. The command interface only contains methods. Traditionally, different command classes are needed for different operations on each type of 3D object within the command object. This results in an increase in the number of command objects as the number of command classes increases, leading to increased code development and maintenance costs. The improvement of this invention is to adopt a command pattern where 3D objects inherit from a base class. The base class contains data and methods. The methods in the base class can save and record the attribute values ​​of editor member variables before and after updates based on the input 3D object. This feature ensures that 3D object attributes are regenerated each time, rather than modified, thus guaranteeing data immutability. Therefore, when creating, modifying, or deleting 3D objects during editing, the attributes of the 3D object can be used directly without worrying about external modification.

[0039] This invention centralizes 3D object attributes into four member variables. Since all four member variables inherit from the BaseState (basic state) base class (hereinafter referred to as the state base class), the modification command only needs to store data of the state base class type. Therefore, the command to modify 3D object attributes only requires one implementation command; the rest are add and delete commands, totaling only three commands. This eliminates the class bloat problem that arises when new 3D (three-dimensional) classes are created and added as product functionality expands, causing the command class to grow exponentially.

[0040] The initialization constructor is a method called when creating a command object. In a specific embodiment of this invention, it represents recording the values ​​of member variables to be modified and the original values ​​of member variables when defining a subclass.

[0041] Firstly, this invention proposes a method for implementing undoable operations in 3D object editing, such as... Figure 1 As shown, it includes the following steps:

[0042] Step S1: Define a base class and define two or more member variables. The base class includes a state base class and an object base class. The type of the member variables is inherited from the state base class.

[0043] Step S2: Define a subclass that inherits from the object base class. Define a member variable state subclass that is unique to the subclass. The member variable state subclass is used to describe the special attributes of the subclass and inherits from the state base class of one of the member variables. The member variable contains subclass information, which is unique to the subclass.

[0044] Step S3: Define the command interface, the command class that implements the command interface, and the command manager;

[0045] Step S4: Through the command interface, the command manager performs push and pop operations on the command object, where the command object is an instantiation of the command class.

[0046] Since the instantiation of the command class is a conventional technique for those skilled in the art, it will not be described in detail here.

[0047] Each step is now described in detail below through specific embodiments:

[0048] Step S1 is to define a base class and define two or more member variables. The base class includes an object base class and a state base class, and the type of the member variables is inherited from the state base class.

[0049] In this specific embodiment, all member variables of the base class are defined, one of which is used to represent data specific to the 3D object, and the other member variables represent public data;

[0050] Define a base class A, and define four member variables in base class A: Transformation, Relationship, Information, and TypeState. The specific definitions of the member variables are as follows:

[0051] (1) Transformation is a data set of position, scale and rotation, with three sub-member variables: Position, Scale and Quaternion.

[0052] (2) Relationship is a data set of parent-child relationships, with two child member variables: Parent (father) representing the father and Children (children) representing the children;

[0053] (3) Information is a collection of additional information, such as Name, UserID, attributes, etc.

[0054] (4) TypeState is a collection of information unique to each subclass. The information is different depending on the things represented by the subclass. For base class A, this embodiment uses an empty class that inherits from TypeState to assign the value. For subclass B, a member variable state subclass needs to be defined. The member variable state subclass inherits from the member variable type of TypeState, and the state object instantiated by the member variable state subclass is assigned to the member variable of type TypeState.

[0055] (5) The types of these four member variables are all inherited from the BaseState (basic state) base class, hereinafter referred to as the state base class;

[0056] (6) The definition of base class A also includes defining a method, which is used to input a state object that inherits from the state base class type. The state object is an instantiation of the member variable state subclass. According to the state type of the state object, the member variable of the same state type is updated.

[0057] Specifically, in this embodiment: a method With is defined. This method takes a state object of type base state as input and updates the corresponding member variables of the same type according to the actual type of the input state object. For example, if the state object passed to With is of type Transformation, then the Transformation member variables are updated.

[0058] For editing 3D objects, the four member variables defined in this embodiment are sufficient for daily use. Except for the type / state member variable, the other three are common attribute categories that will not change with the addition of new 3D classes in daily operations. The number of member variables can be divided into at least two parts: member variables for common attributes and member variables that change according to the 3D class. If the standard allows, more than three member variables can be defined, depending on the standard used for division. Therefore, this invention does not specifically limit the upper limit on the number of member variables; the minimum number of member variables is two, and once the member variables are defined, the number of member variables remains fixed.

[0059] Step S2 is to define a subclass that inherits from the object base class and define a member variable state subclass that is unique to the subclass. The member variable state subclass is used to describe the special attributes of the subclass and inherits from the state base class of one of the member variables. The member variable contains subclass information, which is unique to the subclass.

[0060] Specifically, the definition of the subclass in this embodiment includes: the subclass inheriting from the object base class, defining a state class for the member variables exclusive to the subclass, the state class of the member variables being used to describe the special attributes of the subclass, and inheriting from the state base class of the member variables; in this embodiment, the state class of the member variables inherits from the TypeState class, and defines data belonging to the subclass in it. When instantiating the subclass, it is also necessary to instantiate the state class of the member variables of the subclass and assign it to the member variable of the state class of type member variable. In this embodiment, it is assigned to the member variable T of the subclass.

[0061] In this embodiment, the four member variables are inherited from the state base class. The type inheritance relationship between the member variable state subclass and the member variables and state base class is as follows: Figure 3 As shown below, the following example illustrates how member variable state subclasses are used in practice. Let's assume the member variable representing TypeState is T'. TypeState itself cannot be instantiated; member variable state subclasses need to inherit from TypeState based on their specific attributes or states. For example, PlacementTypeState (object placement type state) contains data about specific attributes of placement. Then, PlacementTypeState is instantiated and assigned to T'. Because PlacementTypeState inherits from TypeState, it also belongs to the TypeState type. This is how the Placement subclass is assigned values. Other member variable state subclasses follow the same logic.

[0062] Step S3 involves defining a command interface, a command class that implements the command interface, and a command manager. The command interface is used to implement 3D object editing functionality, and the command manager is used to record command objects. Obviously, the 3D objects are 3D objects with defined base classes and subclasses.

[0063] The command interface includes methods for implementing execution operations and methods for implementing undo operations.

[0064] In this embodiment, the ICommand interface is defined according to the command pattern. It contains two methods: Execute (execute command) and UnExecute (undo command), which represent the execution and undo operations, respectively.

[0065] The command classes that implement the command interface are defined as follows: a command class for creating an object, a command class for deleting an object, and a command class for changing attributes, which are described below;

[0066] The defined object creation command class includes:

[0067] When initializing the constructor, 3D object information is recorded, and the 3D object information is the attribute value of the member variable;

[0068] The operation method is implemented by creating a 3D object, wherein the 3D object is created based on the 3D object information.

[0069] The undo operation method is implemented by deleting 3D objects.

[0070] In this embodiment of the invention, a CreateObjectCommand class is defined, which implements the ICommand interface. Here, Object refers to a 3D object that inherits from the base class A, and the definition method is as follows:

[0071] (1) When initializing the constructor, record the information of creating a 3D object. At this time, the 3D object is not created. The information here refers to the values ​​of the four member variables (i.e., Transformation, Relationship, Information, TypeState) defined in the base class A.

[0072] (2) Implement the Execute method, in which a 3D object is created based on the 3D object information recorded in (1);

[0073] (3) Implement the UnExecute method, which deletes the 3D object.

[0074] The defined class for deleting objects includes:

[0075] Record 3D object information when initializing the constructor;

[0076] The operation method is executed by deleting a 3D object;

[0077] The undo operation method is implemented by recreating a 3D object, wherein the recreated 3D object is created based on the 3D object information.

[0078] In this embodiment of the invention, a DeleteObjectCommand class is defined, which implements the ICommand interface. Here, Object refers to a 3D object that inherits from the base class A. The specific definition method is as follows:

[0079] (1) When initializing the constructor, save the information of the 3D object to be deleted, namely the values ​​of the four member variables (Transformation, Relationship, Information, TypeState);

[0080] (2) Implement the Execute method, which deletes the 3D object;

[0081] (3) Implement the UnExecute method, specifically in this method, recreate the 3D object based on the 3D object information recorded in (1).

[0082] The defined attribute change command class includes:

[0083] The pre-modified member variable value passed to the initialization constructor is used. The member variable type corresponding to the pre-modified member variable value is inherited from the state base class. The pre-modified member variable value is saved, and the original member variable value is also recorded.

[0084] The operation method is executed by passing the pre-modified member variable value through the method defined in the base class.

[0085] The undo operation is achieved by passing in the original member variable value of the corresponding modified member variable.

[0086] In this embodiment of the invention, a ChangePropertyCommand class is defined, which implements the ICommand interface. The specific definition steps are as follows:

[0087] (1) Initialize the value of the pre-modified member variable passed to the constructor. This member variable is an object that inherits from the state base class. Save the value of the member variable and record the original value of the corresponding property to be modified. For example, if the value of the member variable passed is of type Transformation, then the original value of type Transformation on the 3D object should be saved. The same applies to other cases.

[0088] (2) Implement the Execute method. In this method, call the With interface of the 3D object (i.e., the method defined in the base class) and pass in the new modified value. This With interface refers to the method implemented in step 1.

[0089] (3) Implement the Unexcute method. In this method, call the With interface of the 3D object and pass in the original member variable value saved in (1).

[0090] Step S4 involves the command manager performing push and pop operations on the command object via the command interface. The command object is an instantiation of the command class.

[0091] In this specific embodiment, a manager for the command class is implemented in the command pattern, using push and pop commands. This is a conventional technique for those skilled in the art and will not be elaborated here.

[0092] Secondly, this invention proposes a system for implementing undoable operations on 3D object editing, such as... Figure 2As shown, it includes: a base class definition module, a subclass definition module, a command interface definition module, and a command implementation module. These modules are connected sequentially, and the functions of each module are as follows:

[0093] The base class definition module is used to define a base class and define two or more member variables. The base class includes a state base class and an object base class, and the type of the member variables is inherited from the state base class.

[0094] The subclass definition module is used to define subclasses that inherit from the object base class. It defines member variable state subclasses that are unique to the subclass. The member variable state subclasses are used to describe the special attributes of the subclass and inherit from the state base class of one of the member variables. The member variables contain subclass information that is unique to the subclass.

[0095] The command interface definition module is used to define the command interface, the command class that implements the command interface, and the command manager. The command manager is used to record command objects.

[0096] The command implementation module is used to perform push and pop operations on command objects by the command manager through the command interface, wherein the command object is an instantiation of the command class.

[0097] Thirdly, the present invention proposes a device for implementing reversible operations for editing 3D objects, including a memory for storing computer program instructions and a processor for executing the computer program instructions, wherein when the computer program instructions are executed by the processor, the device is triggered to execute the method for implementing reversible operations for editing 3D objects.

[0098] Fourthly, the present invention provides a computer-readable storage medium storing computer program instructions that, when executed on a computer, cause the computer to perform the method for implementing undoable operations on 3D object editing.

[0099] It should be understood that, without departing from the concept of the present invention, those skilled in the art can combine the above embodiments in any way, and all such combinations are within the protection scope of the present invention.

[0100] If the above methods are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0101] The above are merely specific embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A method for implementing undoable operations in editing 3D objects, characterized in that, Includes the following steps: Step S1: Define a base class and define member variables. The base class includes a state base class and an object base class. The type of the member variables is inherited from the state base class. Step S2: Define a subclass that inherits from the object base class. Define a member variable state subclass that is unique to the subclass. The member variable state subclass is used to describe the special attributes of the subclass and inherits from the state base class of one of the member variables. The member variable contains subclass information, which is unique to the subclass. Step S3: Define the command interface, the command class that implements the command interface, and the command manager; Step S4: Through the command interface, the command manager performs push and pop operations on the command object, where the command object is an instantiation of the command class; The command classes that implement the command interface include: defining a command class for creating an object, defining a command class for deleting an object, and defining a command class for changing attributes; The command interface includes methods for implementing execution operations and methods for implementing undo operations; The defined base class also includes a defined method, which is used to take a state object that inherits from the state base class type as input, and update member variables of the same state type according to the state type of the state object; The member variables include Transformation, Relationship, Information, and TypeState.

2. The method for implementing undoable operations on 3D object editing according to claim 1, characterized in that, The defined object creation command class includes: When initializing the constructor, 3D object information is recorded, and the 3D object information is the attribute value of the member variable; The operation method is implemented by creating a 3D object, wherein the 3D object is created based on the 3D object information. The undo operation method is implemented by deleting 3D objects.

3. The method for implementing undoable operations on 3D object editing according to claim 1, characterized in that, The defined class for deleting objects includes: Record 3D object information when initializing the constructor; The operation method is executed by deleting a 3D object; The undo operation method is implemented by recreating a 3D object, wherein the recreated 3D object is created based on the 3D object information.

4. The method for implementing undoable operations on 3D object editing according to claim 1, characterized in that, The defined attribute change command class includes: The pre-modified member variable value passed to the initialization constructor is used. The member variable type corresponding to the pre-modified member variable value is inherited from the state base class. The pre-modified member variable value is saved, and the original member variable value is also recorded. The operation method is executed by passing the pre-modified member variable value through the method defined in the base class. The undo operation is achieved by passing in the original member variable value of the corresponding modified member variable.

5. A system for implementing undoable operations in editing 3D objects, characterized in that, include: The base class definition module is used to define base classes and member variables. The base classes include state base classes and object base classes, and the types of the member variables are inherited from the state base class. The subclass definition module is used to define subclasses that inherit from the object base class. It defines member variable state subclasses that are unique to the subclass. The member variable state subclasses are used to describe the special attributes of the subclass and inherit from the state base class of one of the member variables. The member variables contain subclass information that is unique to the subclass. The command interface definition module is used to define the command interface, the command classes that implement the command interface, and the command manager; The command implementation module is used to perform push and pop operations on command objects by the command manager through the command interface, wherein the command object is an instantiation of the command class; The command classes that implement the command interface include: defining a command class for creating an object, defining a command class for deleting an object, and defining a command class for changing attributes; The command interface includes methods for implementing execution operations and methods for implementing undo operations; The defined base class also includes a defined method, which is used to take a state object that inherits from the state base class type as input, and update member variables of the same state type according to the state type of the state object; The member variables include Transformation, Relationship, Information, and TypeState.

6. A device for implementing undoable operations on 3D object editing, characterized in that, It includes a memory for storing computer program instructions and a processor for executing the computer program instructions, wherein when the computer program instructions are executed by the processor, the device is triggered to execute a method for implementing an undoable operation for editing a 3D object as described in any one of claims 1-4.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer program instructions that, when executed on a computer, cause the computer to perform a method for implementing an undoable operation on editing a 3D object as described in any one of claims 1-4.