AnyLogic
Expand
Font size

3D Object

The 3D Object element enables AnyLogic users to import ready-to-use 3D models created with the help of any third-party 3D graphics packets into their models.

3D object supports 3D models created in Collada (DAE) file format.

To add a 3D object onto your presentation

  1. Drag the  3D Object element from the 3D section of the  Presentation palette onto the graphical editor. In Windows OS, you can also drag the 3D object files from other applications directly onto the AnyLogic graphical diagram. In this case AnyLogic automatically adds a new  3D Object element on the graphical diagram containing the added 3D object file.
  2. AnyLogic will prompt to resize the object automatically to make its size correspond to the agent scale. In most cases it is recommended to confirm this action. You can set auto-scaling to be performed automatically (as well as disable it) in the AnyLogic preferences.
  3. Now you should tell this shape where the required object is stored. Navigate to the Properties view and choose the file containing the 3D object you want to be displayed by this shape. Click the Browse button to open the Open dialog box. Browse for the required file, select it and click Open when finished. The source file will automatically appear in the model’s Resource folder in the Projects view. This way you will be able to track the current state of the source file, switch between the absolute and relative file paths, etc.
  4. You will see 3D object’s shape in the graphical editor. You can resize the object by selecting it in the graphical editor and dragging the handle located in the bottom right corner of the object. It can be also done in the object’s properties, in the Additional scale control.
  5. 3D object may have internal light sources. You can manage them in the object’s Advanced properties section (Internal lights and Ignore scene lights properties).
When you add a 3D object onto the agent’s graphical diagram, it is displayed as if you are looking at it from above. At model runtime this 2D image will be shown in the regular canvas of the model window, while the full 3D object will be shown in the 3D window.

Properties

General

Name — The name of the object. It is used to identify and access the object from code.

Ignore — If selected, the object will be excluded from the model.

Visible on upper agent — If selected, the object will be also visible on the upper agent where this agent lives.

Lock — If selected, the shape is locked. Locked shapes do not react to mouse clicks — it is impossible to select them in the graphical editor until you unlock them. It is frequently needed when you use your shape as a background image for your animation and you want to prevent editing this shape while drawing other shapes over it.

Visible — The object visibility. The object is visible when the specified expression evaluates to true, otherwise it is not visible.

File — The name of the file containing 3D object that is displayed by this shape. To choose a file, use the Browse... button. The button to the right allows to switch between the absolute and relative file path.

Resize automatically to match agent scale — If selected, the object will be resized automatically to make it correspond to the agent scale. If you change the agent scale afterwards, the object will be resized accordingly. In the AnyLogic preferences, you can set resizing to be performed automatically on adding a new 3D object.

Additional scale — Here you can adjust the size of the 3D object by the specified percentage. If Resize automatically to match agent scale option is selected, additional scale will be still applied. Another way to resize the object is to select it in the graphical editor and drag the handle located in the bottom right corner of the object.
If you need to specify a fractional value, you should switch the Additional scale field to dynamic value editor. Note that the dynamic value that you provide will be applied during the model run, i.e. your changes will not be immediately reflected in the graphical editor.

Orientation — Here you can set the orientation of the 3D object in the 3D scene: the object’s upper side, etc.

Colors

Here you can define colors of the object if they are available for editing.

Position

Level — Level to which this object belongs.

X — X-coordinate of the 3D object.

Y — Y-coordinate of the 3D object.

Z — Z-coordinate of the 3D object.

Rotation Z — The rotation angle in XY plane (in angles or radians).

Advanced

Show in — Here you can choose whether you want the object to be shown both In 2D and 3D animation or in 2D only, or in 3D only.

Replication — The replication factor of the object. Here you specify the number of copies of the object to create. If you leave this field empty, only one object will be created.

Show name — If selected, the object name will be displayed on the presentation diagram.

Internal lights — Here you can choose how the 3D object’s own lights are handled during the model run:

  • Off — the lights are disabled.
  • Illuminate the object — the lights only affect the 3D object itself.
  • Illuminate globally — the lights affect the whole 3D scene (e.g. the car’s headlights illuminate the wall).

Ignore scene lights — If selected, this object won’t be illuminated by any external light sources.

All 3D object files added to your model will be copied into the model folder. In case you copy your model elsewhere, all image files will be copied as well with the model.

Functions

Location
Function Description
double getX() Returns the X coordinate of the shape.
double getY() Returns the Y coordinate of the shape.
double getZ() Returns the Z coordinate of the shape (relative to the shape's level).
void setX(double x) Sets the X coordinate of the shape.

x — the new value of X coordinate.
void setY(double y) Sets the Y coordinate of the shape.

y — the new value of Y coordinate.
void setZ(double z) Sets the Z coordinate of the shape.

z — the new value of Z coordinate.
void setPos(double x, double y) Sets new coordinates for the shape.

x — the new value of x coordinate.
y — the new value of y coordinate.
void setPos(double x, double y, double z) Sets new coordinates for the shape.

x — the new value of x coordinate.
y — the new value of y coordinate.
z — the new value of z coordinate.
void setPos(Point p) Sets new coordinates for the shape.

p — the Point object containing coordinates.
Scale
Function Description
double getAgentScalingFactor() Returns the additional scaling factor applied accordingly to the Scale element of the agent.
double getScaleX()
double getScaleY()
double getScaleZ()
Returns the scale of the shape along X (Y, Z) axis.
void setScaleX(double sx)
void setScaleY(double sy)
void setScaleZ(double sz)
Sets the scale of the shape along X (Y, Z) axis.

sx — the new value of scale along X axis. *
sy — the new value of scale along Y axis. *
sz — the new value of scale along Z axis. *
void setScale(double sx, double sy) Sets the scales of the shape along both axes.

sx — the new value of scale along X axis. *
sy — the new value of scale along Y axis. *
void setScale(double sx, double sy, double sz) Sets the scales of the shape along three axes.

sx — the new value of scale along X axis. *
sy — the new value of scale along Y axis. *
sz — the new value of scale along Z axis. *
void setScale(double s) Sets the same scale of the shape along both axes.
s — the new value of scale along both axis. *
* The new scale value is relative to the original object’s size. Set to 1 to keep the original size.
File name
Function Description
String getFilename() Returns the name of 3D object file.
Colors
Function Description
void setColor(String materialName, Color color) Changes custom color for the shape material with the given name.
Current implementation updates object on the 3D scene only, it doesn’t update the 2D picture.
materialName — the name of the material. Please refer to Properties View of this 3D object in AnyLogic to see the names list.
color — new color, or null to reset the color to default value.
Rotation
Function Description
double getRotation() Returns the rotation of the shape in radians, clockwise.
void setRotation(double r) Sets the rotation of the shape.

r — the new value of rotation in radians.
Visibility
Function Description
boolean isVisible() Checks the visibility of the shape. If the shape is visible, returns true, otherwise returns false.
void setVisible(boolean v) Sets the visibility of the shape.

v — visibility: if true — the shape is set to be visible, if false — not visible.
Level
Function Description
Level getLevel() Returns the level, where this shape is located.
Group
Function Description
ShapeGroup getGroup() Returns the group containing this shape.
Draw mode (2D / 3D)
Function Description
ShapeDrawMode getDrawMode() Returns the drawing mode of the shape (it defines where this shape is drawn: in 2D, 3D or 2D+3D animation).

Valid values:
SHAPE_DRAW_2D3D — show in 2D and 3D animation
SHAPE_DRAW_2D — show in 2D animation only
SHAPE_DRAW_3D — show in 3D animation only
void setDrawMode(ShapeDrawMode drawMode) Sets the drawing mode of the shape (where to draw this shape: 2D, 3D or 2D+3D animation).
This method may be called only once and only for the shapes created using the constructor without arguments. The call, which changes the set draw mode, will throw the error.
drawMode — the new draw mode of the shape.
Valid values:
SHAPE_DRAW_2D3D — show in 2D and 3D animation
SHAPE_DRAW_2D — show in 2D animation only
SHAPE_DRAW_3D — show in 3D animation only
Points inside the shape
Function Description
boolean contains(double px, double py) Test if the shape contains the point with the given coordinates (relative to this shape’s container, i.e. in the same system with the coordinates of this shape, x and y). Returns true if the shape contains the point with the given coordinates.

px — the x coordinate relative to this shape’s container.
py — the y coordinate relative to this shape’s container.
Point randomPointInside() Returns the randomly chosen point inside the shape area.
This function utilizes Random Number Generator of the Presentable object containing this shape. (Will throw an exception if the shape has been created from code and has not been added to any group, — in this case use randomPointInside(Random rng)).
Point randomPointInside(java.util.Random rng) Returns the randomly chosen point inside the shape area. This function utilizes the given Random Number Generator.

rng — the random number generator.
How can we improve this article?