User Tools

Site Tools


dragengine:modules:dragonscript:behavior_randomizegeometry

ECBehaviorRandomizeGeometry

Behavior adding support to randomize position, rotation and scaling.

This behavior is typically used to add variation to multiple instances of the same element added to a game world by randomizing the position, rotation and scaling before creating the element.

This behavior uses BehaviorPrepareStub to apply the changes before the element is actually created. No randomizing is done if the element is created while loading a game world.

Instance Counts

This behavior can be used only once on an element.

Element Class Properties

Element class properties have the prefix randomizeGeometry..

randomize

Set enable randmoize.

  • Full name: randomizeGeometry.randomize or randomizeGeometry({id}).randomize
  • Type: boolean
  • Default Value: true
  • Example (*.deeclass)
    <boolean name='randomizeGeometry.randomize'>false</boolean>

minTranslate

Set minimum translation that can be randomly selected.

  • Full name: randomizeGeometry.minTranslate or randomizeGeometry({id}).minTranslate
  • Type: 3-component float vector
  • Default Value: (0,0,0)
  • Example (*.deeclass)
    <vector name='randomizeGeometry.minTranslate' x='0' y='0' z='-0.2'/>

maxTranslate

Set maximum translation that can be randomly selected.

  • Full name: randomizeGeometry.maxTranslate or randomizeGeometry({id}).maxTranslate
  • Type: 3-component float vector
  • Default Value: (0,0,0)
  • Example (*.deeclass)
    <vector name='randomizeGeometry.maxTranslate' x='0' y='0' z='0.2'/>

minRotate

Set minimum rotation in degrees that can be randomly selected.

  • Full name: randomizeGeometry.minRotate or randomizeGeometry({id}).minRotate
  • Type: 3-component float vector
  • Default Value: (0,0,0)
  • Example (*.deeclass)
    <vector name='randomizeGeometry.minRotate' x='0' y='-45' z=''/>

maxRotate

Set maximum rotation in degrees that can be randomly selected.

  • Full name: randomizeGeometry.maxRotate or randomizeGeometry({id}).maxRotate
  • Type: 3-component float vector
  • Default Value: (0,0,0)
  • Example (*.deeclass)
    <vector name='randomizeGeometry.maxRotate' x='0' y='45' z=''/>

minScale

Set minimum scaling that can be randomly selected.

  • Full name: randomizeGeometry.minScale or randomizeGeometry({id}).minScale
  • Type: 3-component float vector
  • Default Value: (1,1,1)
  • Example (*.deeclass)
    <vector name='randomizeGeometry.minTranslate' x='0.9' y='0.9' z='0.9'/>

maxScale

Set maximum scaling that can be randomly selected.

  • Full name: randomizeGeometry.maxScale or randomizeGeometry({id}).maxScale
  • Type: 3-component float vector
  • Default Value: (1,1,1)
  • Example (*.deeclass)
    <vector name='randomizeGeometry.maxTranslate' x='1.1' y='1.1' z='1.1'/>

Events

This behavior has no events.

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

This behavior does not required element class to be persistable (setPersistable).

API Documentation

ECBehaviorRandomizeGeometry.

Since DragonScript Module Version 1.23

Use Cases

  • Randomize positon, rotation and scaling of an element each time the element is added to a game world.

Element Class Example

This example defines an element which is element with randomized geometry parameters.

class MyElement extends BehaviorElementClass
  public var ECBehaviorRandomizeGeometry randomizeGeometry
  func new()
    randomizeGeometry = ECBehaviorRandomizeGeometry.new(this)
    randomizeGeometry.getMinRotate().setVector(Vector.new(0, -45, 0))
    randomizeGeometry.getMaxRotate().setVector(Vector.new(0, 45, 0))
  end
end

Behavior Factory

Using element class supporting adding behaviors the behavior can be added like this:

<?xml version='1.0' encoding='UTF-8'?>
<elementClass name='MyClass' class='GenericBehaviorElement'>
  <behavior type='ECBehaviorRandomizeGeometry'>
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <vector name='.minRotate' x='0' y='-45' z='0'/>
    <vector name='.maxRotate' x='0' y='45' z='0'/>
  </behavior>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_randomizegeometry.txt · Last modified: 2025/03/11 19:56 by dragonlord