Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 15 Next »

To build an agent type event, open the Atoms UI and make sure to have the "AgentTypeEvents" tab selected.

Click on "Add" and you will be prompted with a dialog asking if you want to edit your clip in GUI or script mode.


GUI mode

Give a name for your agent type (i.e. testRobot).

Select the skeleton and geo files you exported previously. The "Skeleton File" will point to your skeleton definition file, the "Geo Path" to your proxy geo file, the "Skin Path" to your skinned geo file and the "Ragdoll Path" to your ragdoll file.

Set the state machine to "robotStateMachine" (you created this in the previous section) or select it from the drop down menu on the right side of the field.

You can edit the Agent Type scale multiplier if you want, but it's not necessary for this tutorial. 

Your GUI should look like the one in the picture.
Click on the "Register" button or press CTRL+S.

Your agent type is now ready to be used.

The Agent Type scale multiplier will affect all agents of this type. If you want to change the scale of a specific agent you should use the agent scale Behaviour Module.


Script mode

In case you selected the script mode, you should edit your script so it looks like the following.

Then hit CTRL+S or click on the "Register" button. 

AgentType
import os
import AtomsMath
import AtomsCore
import Atoms
import AtomsUtils
from Atoms import GLOBAL_NAMES


class AgentTypeEvent1(Atoms.SimulationEvent):
    eventName = 'agentType1'
    skelFile = 'path/file.atomsskel'
    geoPath = 'path/file.geos'
    skinPath = 'path/file.geos'
    ragdollSetupPath = 'path/file.atomsragdoll'
    characterSetupPath = 'path/file.atomscharacter'
    stateMachine = ''
    scaleMultiplier = 1.0
    drawOptimization = {}
    pelvises = []
    skipIks = []
    legs = []
    sanitizeJointNames = False

    def __init__(self):
        Atoms.SimulationEvent.__init__(self)
        self.setName(self.eventName)

    def load(self):
        AGENT_TYPE = GLOBAL_NAMES.AGENT_TYPE
        
        skel = Atoms.loadSkeleton(self.skelFile)
        if self.sanitizeJointNames:
            skel.sanitizeJointNames()
        for p in self.pelvises:
            id = skel.jointId(p)
            if id != -1:
                skel.addPelvis(id)

        for si in self.skipIks:
            id = skel.jointId(si)
            if id != -1:
                skipIkMeta = AtomsCore.BoolMetadata(True)
                skel.addJointMetadata(id, "skipIk", skipIkMeta)

        for f in self.legs:
            if not isinstance(f, (tuple, list)) or not len(f) == 4:
                continue
            root = skel.jointId(f[0])
            ik = skel.jointId(f[1])
            tip = skel.jointId(f[2])
            if root == -1 or tip == -1 or ik == -1:
                continue
            skel.addFoot(ik, root, tip)
            poleVector = AtomsMath.V3d(f[3][0], f[3][1], f[3][2])
            poleVectorMeta = AtomsCore.Vector3Metadata(poleVector)
            skel.addJointMetadata(root, "poleVector", poleVectorMeta)
        if self.legs or self.pelvises:
            skel.buildIkData()

        aType = Atoms.AgentType()
        aType.setSkeleton(skel)

        meshMap = Atoms.loadMesh(self.geoPath)
        if meshMap:
            aType.metadata()[AGENT_TYPE.LOW_GEO] = meshMap
        elif self.geoPath != "":
            AtomsUtils.Logger.warning("Could not read geo file: " + str(self.geoPath))

        skinMap = Atoms.loadMesh(self.skinPath)
        if skinMap:
            aType.metadata()[AGENT_TYPE.SKIN_GEO] = skinMap
        elif self.skinPath != "":
            AtomsUtils.Logger.warning("Could not read skin geo file: " + str(self.skinPath))

        ragdoll_setup = AtomsCore.MapMetadata()
        if self.ragdollSetupPath:
            ark = AtomsCore.Archive()
            if ark.readFromFile(AtomsUtils.solvePath(self.ragdollSetupPath)):
                ragdoll_setup.deserialise(ark)
        aType.metadata()[AGENT_TYPE.RAGDOLL] = ragdoll_setup

        character_setup = AtomsCore.MapMetadata()
        if self.characterSetupPath:
            ark = AtomsCore.Archive()
            if ark.readFromFile(AtomsUtils.solvePath(self.characterSetupPath)):
                character_setup.deserialise(ark)
                aType.metadata()[AGENT_TYPE.CHARACTER] = character_setup
        else:
            character_setup = Atoms.createCharacterizationFromSkeleton(self.skelFile)
            if character_setup:
                aType.metadata()[AGENT_TYPE.CHARACTER] = character_setup

        aType.metadata()[AGENT_TYPE.STATE_MACHINE] = AtomsCore.StringMetadata(self.stateMachine)
        aType.metadata()[AGENT_TYPE.SCALE_MULTIPLIER] = AtomsCore.DoubleMetadata(self.scaleMultiplier)

        lod_levels = [0]
        lod_values = []

        for lod_key in ['B', 'C', 'D']:
            if lod_key in self.drawOptimization:
                lod_levels.append(self.drawOptimization[lod_key][0])
                lod_values.append(self.drawOptimization[lod_key][1])

        lod_levels_meta = AtomsCore.IntArrayMetadata()
        lod_levels_meta.set(lod_levels)
        aType.metadata()[AGENT_TYPE.LOD_LEVELS] = lod_levels_meta

        lod_values_meta = AtomsCore.DoubleArrayMetadata()
        lod_values_meta.set(lod_values)
        aType.metadata()[AGENT_TYPE.LOD_DISTANCES] = lod_values_meta

        lod_mode_meta = AtomsCore.IntMetadata(0)
        if 'mode' in self.drawOptimization:
            lod_mode_meta.set(self.drawOptimization['mode'])
        aType.metadata()[AGENT_TYPE.LOD_MODE] = lod_mode_meta

        Atoms.AgentTypes.instance().addAgentType(self.eventName, aType)

    def unload(self):
        Atoms.AgentTypes.instance().removeAgentType(self.eventName)

  • No labels