public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        if (blendTree == null)
        {
            return;
        }

        conversionSystem.DeclareAssetDependency(gameObject, blendTree);

        var rig = dstManager.GetComponentData <Rig>(entity);

        var clipConfiguration = new ClipConfiguration
        {
            Mask = ClipConfigurationMask.LoopValues
        };

        var bakeOptions = new BakeOptions
        {
            ClipConfiguration = clipConfiguration,
            RigDefinition     = rig.Value,
            SampleRate        = 60.0f
        };

        var blendTreeIndex       = BlendTreeConversion.Convert(blendTree, entity, dstManager, bakeOptions);
        var blendTree2DResources = dstManager.GetBuffer <BlendTree2DResource>(entity);

        var blendTreeAsset =
            BlendTreeBuilder.CreateBlendTree2DFromComponents(blendTree2DResources[blendTreeIndex], dstManager, entity);

        conversionSystem.BlobAssetStore.AddUniqueBlobAsset(ref blendTreeAsset);

        var blendTree2DData = new BlendTree2DRuntime
        {
            BlendTreeAsset = blendTreeAsset
        };

        dstManager.AddComponentData(entity, blendTree2DData);

        var blendTree2DParam = new BlendTree2DParamRuntime
        {
            InputMapping = float2.zero,
            StepMapping  = paramStep
        };

        dstManager.AddComponentData(entity, blendTree2DParam);

        dstManager.AddComponent <DeltaTimeRuntime>(entity);
        dstManager.AddComponent <ProcessDefaultAnimationGraph.AnimatedRootMotion>(entity);
    }
Example #2
0
    protected override BlendTree2DData CreateGraph(Entity entity, NodeSet set, ref BlendTree2DSetup setup)
    {
        if (!EntityManager.HasComponent <SharedRigDefinition>(entity))
        {
            throw new System.NullReferenceException("Entity doesn't have required SharedRigDefinition");
        }

        var rigDefinition = EntityManager.GetSharedComponentData <SharedRigDefinition>(entity);

        var blendTreeComponent = EntityManager.GetBuffer <BlendTree2DResource>(entity);
        var blendTreeAsset     = BlendTreeBuilder.CreateBlendTree2DFromComponents(blendTreeComponent[setup.BlendTreeIndex], EntityManager, entity);
        var data = new BlendTree2DData();

        var strongHandle = set.Create <BlendTree2DNode>();

        data.paramX         = rand.NextFloat(-1.0f, 1.0f);
        data.paramY         = rand.NextFloat(-1.0f, 1.0f);
        data.BlendTree      = strongHandle;
        data.BlendTreeAsset = blendTreeAsset;

        data.DeltaTimeNode   = set.Create <DeltaTimeNode>();
        data.TimeCounterNode = set.Create <TimeCounterNode>();
        data.TimeLoopNode    = set.Create <TimeLoopNode>();
        data.FloatRcpSimNode = set.Create <FloatRcpSimNode>();

        set.Connect(data.DeltaTimeNode, (OutputPortID)DeltaTimeNode.KernelPorts.DeltaTime, data.TimeCounterNode, (InputPortID)TimeCounterNode.KernelPorts.DeltaTime);
        set.Connect(data.TimeCounterNode, (OutputPortID)TimeCounterNode.KernelPorts.Time, data.TimeLoopNode, (InputPortID)TimeLoopNode.KernelPorts.InputTime);
        set.Connect(data.TimeLoopNode, (OutputPortID)TimeLoopNode.KernelPorts.OutputTime, data.BlendTree, (InputPortID)BlendTree2DNode.KernelPorts.NormalizedTime);

        set.Connect(data.BlendTree, (OutputPortID)BlendTree2DNode.SimulationPorts.Duration, data.FloatRcpSimNode, (InputPortID)FloatRcpSimNode.SimulationPorts.Input);
        set.Connect(data.FloatRcpSimNode, (OutputPortID)FloatRcpSimNode.SimulationPorts.Output, data.TimeCounterNode, (InputPortID)TimeCounterNode.SimulationPorts.Speed);

        set.SendMessage(data.TimeLoopNode, (InputPortID)TimeLoopNode.SimulationPorts.Duration, 1.0F);

        set.SendMessage(data.BlendTree, (InputPortID)BlendTree2DNode.SimulationPorts.RigDefinition, rigDefinition.Value);
        set.SendMessage(data.BlendTree, (InputPortID)BlendTree2DNode.SimulationPorts.BlendTree, data.BlendTreeAsset);

        data.Output.Buffer = set.CreateGraphValue(strongHandle, BlendTree2DNode.KernelPorts.Output);
        PostUpdateCommands.AddComponent(entity, data.Output);

        return(data);
    }
    protected override BlendTree2DData CreateGraph(Entity entity, ref Rig rig, PreAnimationGraphSystem graphSystem, ref BlendTree2DSetup setup)
    {
        var set = graphSystem.Set;
        var blendTreeComponent = EntityManager.GetBuffer <BlendTree2DResource>(entity);
        var blendTreeAsset     = BlendTreeBuilder.CreateBlendTree2DFromComponents(blendTreeComponent[setup.BlendTreeIndex], EntityManager, entity);
        var data = new BlendTree2DData();

        data.BlendTreeNode  = set.Create <BlendTree2DNode>();
        data.BlendTreeAsset = blendTreeAsset;

        data.DeltaTimeNode      = set.Create <DeltaTimeNode>();
        data.TimeCounterNode    = set.Create <TimeCounterNode>();
        data.TimeLoopNode       = set.Create <TimeLoopNode>();
        data.FloatRcpNode       = set.Create <FloatRcpNode>();
        data.EntityNode         = set.CreateComponentNode(entity);
        data.BlendTreeInputNode = set.Create <ExtractBlendTree2DParametersNode>();

        set.Connect(data.DeltaTimeNode, DeltaTimeNode.KernelPorts.DeltaTime, data.TimeCounterNode, TimeCounterNode.KernelPorts.DeltaTime);
        set.Connect(data.TimeCounterNode, TimeCounterNode.KernelPorts.Time, data.TimeLoopNode, TimeLoopNode.KernelPorts.InputTime);
        set.Connect(data.TimeLoopNode, TimeLoopNode.KernelPorts.OutputTime, data.BlendTreeNode, BlendTree2DNode.KernelPorts.NormalizedTime);

        set.Connect(data.BlendTreeNode, BlendTree2DNode.KernelPorts.Duration, data.FloatRcpNode, FloatRcpNode.KernelPorts.Input);
        set.Connect(data.FloatRcpNode, FloatRcpNode.KernelPorts.Output, data.TimeCounterNode, TimeCounterNode.KernelPorts.Speed);

        set.Connect(data.BlendTreeNode, BlendTree2DNode.KernelPorts.Output, data.EntityNode);

        set.Connect(data.EntityNode, data.BlendTreeInputNode, ExtractBlendTree2DParametersNode.KernelPorts.Input, NodeSet.ConnectionType.Feedback);
        set.Connect(data.BlendTreeInputNode, ExtractBlendTree2DParametersNode.KernelPorts.OutParamX, data.BlendTreeNode, BlendTree2DNode.KernelPorts.BlendParameterX);
        set.Connect(data.BlendTreeInputNode, ExtractBlendTree2DParametersNode.KernelPorts.OutParamY, data.BlendTreeNode, BlendTree2DNode.KernelPorts.BlendParameterY);

        set.SendMessage(data.TimeLoopNode, TimeLoopNode.SimulationPorts.Duration, 1.0F);
        set.SendMessage(data.BlendTreeNode, BlendTree2DNode.SimulationPorts.Rig, rig);
        set.SendMessage(data.BlendTreeNode, BlendTree2DNode.SimulationPorts.BlendTree, data.BlendTreeAsset);

        PostUpdateCommands.AddComponent(entity, graphSystem.Tag);

        return(data);
    }