Class Thing

java.lang.Object
com.j3d.engine.scene.nodes.Thing
All Implemented Interfaces:
SceneObjectList, SceneObject, HasProperties

public class Thing extends Object implements SceneObjectList
A Thing, or more commonly in engine lingo, a mesh, is an SceneObjectList which makes up an entire 3d object made of GTris, GPoints and GLines.

A Thing, can be transformed in any means necessary and is the only "object" which the user can actually interact with. They can interact with GObjects but a Thing is the first tangible thing. (pun intended)

A Thing is the first user tangible object. So it naturally has to interact with the app in many different ways whther it be showing itself in the JTree or being written to a ProjectFile

Author:
Lehlogonolo Poole
See Also:
  • Field Details

    • centroid

      private Vector3 centroid
      The centroid of the Thing, calculated from the GPoints it contains.
    • id

      private UUID id
      The unique identifier for this Thing.
    • name

      private String name
      The name of this Thing.
    • properties

      private final ArrayList<Property<?,?>> properties
    • onSelectCallback

      private final BiConsumer<Thing,DefaultMutableTreeNode> onSelectCallback
      What the thing should do when it gets selected within the tree GUI
    • objects

      private final ArrayList<GObject> objects
      The master list of GObjects that compose this 3D Thing.
    • points

      private final List<GPoint> points
      The list of points that compose this 3D Thing.
    • solid

      private boolean solid
      Whether all triangles that get added to this Thing should be single sided or not.
    • parent

      private Layer parent
      The parent layer of this Thing.
    • isBg

      private boolean isBg
      A Flag set by the Thing itself to check whether its part of the background. if so it only draws the axes and the background.
    • hidden

      private boolean hidden
      Governed by SceneObjectList, whether this Thing is hidden or not.
    • forDeletion

      private boolean forDeletion
      Governed by SceneObjectList, whether this Thing is for deletion or not.
    • treeNodeIdentity

      private TreeNodeIdentity<Thing> treeNodeIdentity
      Required by SceneObjectList, The Tree Node Identity object defining this Thing within the Tree GUI.
    • treeNode

      private DefaultMutableTreeNode treeNode
      Required by SceneObjectList, The actual tree node reference for this Thing within the Tree GUI.
  • Constructor Details

    • Thing

      public Thing(Layer l, String name, boolean invokeSwingHooks)
      Constructs a Thing.
      Parameters:
      l - The parent layer of the Thing.
      name - The name of the Thing.
      invokeSwingHooks - Whether to run GUI related hooks
    • Thing

      public Thing(Layer l, String name)
      Constructs a Thing and runs GUI related hooks.
      Parameters:
      l - The parent layer of the Thing.
      name - The name of the Thing.
  • Method Details

    • getName

      public String getName()
      Gets the name of this Thing.
      Specified by:
      getName in interface SceneObject
      Returns:
      The name of this Thing.
    • fromRaw

      public static Thing fromRaw(String name, String id, boolean hidden, Layer l)
      Constructs a Thing.
      Parameters:
      name - The name of the Thing defined in the file.
      id - The ID of the Thing defined in the file.
      hidden - Whether the Thing is hidden or not.
      l - The parent layer of the Thing.
      Returns:
      A Thing
    • setId

      private void setId(UUID uuid)
      Sets this thing's unique identifier
      Parameters:
      uuid - The new UUID
      See Also:
    • invokeSwingHooks

      public void invokeSwingHooks()
      Description copied from interface: SceneObjectList
      A method to initialise anything swing related within the constructor. This is typically called within the SceneObjectList's constructor who needs to create an object outside the EDT thread.

      A use case (the current use case) would be when an SceneObjectList is loaded from disk to memory and the Spinner dialog is blocking the EDT thread. After the throbber has finished, you may call invokeSwingHooks safely rather than fighting with a blocked EDT thread.

      Specified by:
      invokeSwingHooks in interface SceneObjectList
    • addObjs

      public Thing addObjs(GObject... gObjects)
      Adds one or more GObjects to this Thing.
      Parameters:
      gObjects - The GObjects to add.
    • calculateCentroid

      private void calculateCentroid(GObject[] gObjects)
    • draw

      public void draw(Graphics2D graphics2D)
      Draws this Thing to the screen.
      Parameters:
      graphics2D - The Graphics2D instance
    • getId

      public UUID getId()
      Returns the unique identifier of this Thing.
      Specified by:
      getId in interface SceneObject
      Returns:
      The UUID of this Thing.
    • getObjects

      public ArrayList<GObject> getObjects()
      Returns the GObjects that compose this Thing.
      Returns:
      The GObjects that compose this Thing.
    • getCentroid

      public Vector3 getCentroid()
      Returns the centroid of this Thing.
      Returns:
      The centroid of this Thing.
    • getProperties

      public ArrayList<Property<?,?>> getProperties()
      Description copied from interface: HasProperties
      Returns an ArrayList of Property objects associated with this instance. Each property can hold a value of a specific type and have a specific key type.
      Specified by:
      getProperties in interface HasProperties
      Returns:
      an ArrayList of properties.
    • solidify

      public Thing solidify()
      Solidifies the Thing by setting all its GTris to be single-sided.
      Returns:
      This Thing, for method chaining.
    • addProps

      private void addProps()
    • setName

      private void setName(String s)
    • moveObjects

      public static void moveObjects(ArrayList<GObject> stuff, Thing to)
    • removeObjects

      private void removeObjects(ArrayList<GObject> stuff)
    • copy

      public Action<Thing> copy(SceneManager sceneManager, Layer l)
      Creates a copy of this Thing, adding its GObjects to the specified sceneManager and layer.
      Parameters:
      sceneManager - The sceneManager to associate the new Thing with.
      l - The layer to add the new Thing to.
      Returns:
      An Action that performs the copy operation and itself returns the new Thing.
    • scale

      public VoidAction scale(double scale)
      Scales the Thing by a uniform factor around its centroid.
      Parameters:
      scale - The uniform scaling factor.
      Returns:
      An Action which performs the scae operation.
    • scale

      public VoidAction scale(Vector3 scale)
      Scales the Thing by a vector factor around its centroid.
      Parameters:
      scale - The scaling vector, where each component scales along its respective axis.
      Returns:
      An Action which performs the scale operation.
    • translate

      public VoidAction translate(Vector3 v)
      Translates the Thing by a given vector.
      Parameters:
      v - The translation vector.
      Returns:
      An Action which performs the translation operation.
    • rotate

      public VoidAction rotate(Vector3 axis, double angleDegrees)
      Rotates the Thing around a given axis by a given angle.
      Parameters:
      axis - The rotation axis.
      angleDegrees - The rotation angle in degrees.
      Returns:
      An Action which performs the rotation operation.
    • rotate

      public VoidAction rotate(Vector3 centre, Vector3 axis, double angleDegrees)
      Rotates the Thing around a given axis by a given angle.
      Parameters:
      centre - The rotation centre.
      axis - The rotation axis.
      angleDegrees - The rotation angle in degrees.
      Returns:
      An Action which performs the rotation operation.
    • instantDelete

      public void instantDelete()
      Description copied from interface: SceneObjectList
      An internal delete method which all implementors should override for instantaneous deletion.

      This method should not be called by a user interface things. However, any object overriding the method must provide a way to delete everything relating to it.

      Specified by:
      instantDelete in interface SceneObjectList
    • getIdentity

      public TreeNodeIdentity<Thing> getIdentity()
      Description copied from interface: SceneObjectList
      Returns the TreeNodeIdentity for the given object to use within the LayerTree
      Specified by:
      getIdentity in interface SceneObjectList
      Returns:
      The identity
    • getTreeNode

      public DefaultMutableTreeNode getTreeNode()
      Description copied from interface: SceneObjectList
      The actual tree node for the representation of this object within LayerTree
      Specified by:
      getTreeNode in interface SceneObjectList
      Returns:
      The tree node
    • getOnSelect

      public BiConsumer<? extends SceneObjectList,DefaultMutableTreeNode> getOnSelect()
      Description copied from interface: SceneObjectList
      The callback for when the object is selected in the tree.
      Specified by:
      getOnSelect in interface SceneObjectList
      Returns:
      The callback
    • isHidden

      public boolean isHidden()
      Description copied from interface: SceneObjectList
      Whether the given object is hidden or not
      Specified by:
      isHidden in interface SceneObjectList
      Returns:
      true if hidden, false otherwise
    • setHidden

      public void setHidden(boolean hidden)
      Description copied from interface: SceneObjectList
      Hides the object. This is for internal use. GUI and other user things should make use of SceneObjectList.toggleVisibility() instead.
      Specified by:
      setHidden in interface SceneObjectList
    • isForDeletion

      public boolean isForDeletion()
      Description copied from interface: SceneObjectList
      Labels the object as for deletion. Has similar implications as being hidden however it will be cleaned up later and won't be available on lists.
      Specified by:
      isForDeletion in interface SceneObjectList
      Returns:
      true if the object was marked for deletion
    • setForDeletion

      public void setForDeletion(boolean forDeletion)
      Description copied from interface: SceneObjectList
      Marks the object for deletion.
      Specified by:
      setForDeletion in interface SceneObjectList
    • toggleVisibility

      public Action<Boolean> toggleVisibility()
      Description copied from interface: SceneObjectList
      Toggles the visibility of the object.
      Specified by:
      toggleVisibility in interface SceneObjectList
      Returns:
      An action that toggles the visibility of the object and returns the new visibility state.
    • deleteLater

      public DirtyVoidAction deleteLater()
      Description copied from interface: SceneObjectList
      Deletes the object.

      The use of the word "later" is because the action of deletion is only ever done once the Action object is out of the history's bounds. At that point CleanableAction.cleanup() is called, which actually deletes.

      Specified by:
      deleteLater in interface SceneObjectList
      Returns:
      An action that deletes the object.
    • objectsStream

      public Stream<GObject> objectsStream()
    • isSolid

      public boolean isSolid()
    • remove

      public void remove(GObject tri)