예제 #1
0
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        if (SourceClip == null)
        {
            throw new NullReferenceException($"Error in ({this}) conversion: source clip is null.");
        }
        if (DestClip == null)
        {
            throw new NullReferenceException($"Error in ({this}) conversion: dest clip is null.");
        }

        conversionSystem.DeclareAssetDependency(gameObject, SourceClip);
        conversionSystem.DeclareAssetDependency(gameObject, DestClip);

        var blendCurve = BlobAssetReference <AnimationCurveBlob> .Null;

        if (BlendCurve != null && TransitionType == TransitionByBoolNode.TransitionType.Crossfade)
        {
            blendCurve = CurveConversion.ToAnimationCurveBlobAssetRef(BlendCurve);
        }

        dstManager.AddComponentData(entity, new InertialBlendingGraphSetup
        {
            SourceClip     = conversionSystem.BlobAssetStore.GetClip(SourceClip),
            DestClip       = conversionSystem.BlobAssetStore.GetClip(DestClip),
            TransitionType = TransitionType,
            BlendCurve     = blendCurve,
        });

        dstManager.AddComponent <DeltaTime>(entity);
    }
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        if (clip01 == null || clip02 == null)
        {
            return;
        }

        _clipsRef.Clear();

        conversionSystem.DeclareAssetDependency(gameObject, clip01);
        conversionSystem.DeclareAssetDependency(gameObject, clip02);

        var clipRef01 = clip01.ToDenseClip();
        var clipRef02 = clip02.ToDenseClip();

        conversionSystem.BlobAssetStore.AddUniqueBlobAsset(ref clipRef01);
        conversionSystem.BlobAssetStore.AddUniqueBlobAsset(ref clipRef02);

        _clipsRef.Add(clipRef01);
        _clipsRef.Add(clipRef02);

        var dynamicBufferClips = dstManager.AddBuffer <PlayerBlendClipBuffer>(entity);

        for (byte i = 0; i < _clipsRef.Count; i++)
        {
            dynamicBufferClips.Add(new PlayerBlendClipBuffer {
                Clip = _clipsRef[i]
            });
        }

        dstManager.AddComponent <PlayerBlendKernelRuntime>(entity); //Used for the animation node kernel.
        dstManager.AddComponent <DeltaTimeRuntime>(entity);         //Used for the animation node kernel.
    }
        public void Convert(
            Renderer renderer,
            Mesh mesh,
            List <Material> sharedMaterials = null,
            Transform root = null)
        {
            if (sharedMaterials == null)
            {
                renderer.GetSharedMaterials(m_SharedMaterials);
                sharedMaterials = m_SharedMaterials;
            }

            // Declare asset dependencies before any input validation, so dependency info will
            // be correct even if there is an error later.
            m_ConversionSystem.DeclareAssetDependency(renderer.gameObject, mesh);
            for (int i = 0; i < sharedMaterials.Count; ++i)
            {
                m_ConversionSystem.DeclareAssetDependency(renderer.gameObject, sharedMaterials[i]);
            }

            if (mesh == null || sharedMaterials.Count == 0)
            {
                Debug.LogWarning(
                    "Renderer is not converted because either the assigned mesh is null or no materials are assigned.",
                    renderer);
                return;
            }

            if (root is null)
            {
                root = renderer.transform;
            }
            //@TODO: Transform system should handle RenderMeshFlippedWindingTag automatically. This should not be the responsibility of the conversion system.
            bool flipWinding = math.determinant(root.localToWorldMatrix) < 0.0;

            var desc = new RenderMeshDescription(renderer, mesh, sharedMaterials, 0)
            {
                FlipWinding = flipWinding,
            };

            if (AttachToPrimaryEntityForSingleMaterial && sharedMaterials.Count == 1)
            {
                ConvertToSingleEntity(
                    m_DstEntityManager,
                    m_ConversionSystem,
                    desc,
                    renderer);
            }
            else
            {
                ConvertToMultipleEntities(
                    m_DstEntityManager,
                    m_ConversionSystem,
                    desc,
                    renderer,
                    sharedMaterials,
                    root);
            }
        }
 public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
 {
     conversionSystem.DeclareAssetDependency(gameObject, Asset);
     conversionSystem.DeclareAssetDependency(gameObject, Texture);
     conversionSystem.DeclareAssetDependency(gameObject, Material);
     conversionSystem.DeclareDependency(gameObject, GameObject);
     dstManager.AddComponentData(entity, new ConversionDependencyData
     {
         MaterialColor     = Material != null ? Material.color : default,
예제 #5
0
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        if (clip == null)
        {
            return;
        }

        var animationCurve = conversionSystem.BlobAssetStore.GetAnimationCurve(curve);

        //conversion result on this gameObject depends on source asset. Any changes on clip will
        //trigger a reconversion on this gameObject to an entity.
        conversionSystem.DeclareAssetDependency(gameObject, clip);

        //Convert unityengine animation clip to a DOTS dense clip (class to a blob ref struct container)
        var denseClip = clip.ToDenseClip();

        //Try to see if a the blob is already in the BlobAssetStore if so it will fetch rather then create. if not it will create and then cache
        conversionSystem.BlobAssetStore.AddUniqueBlobAsset(ref denseClip);

        //Add RotateCube_PlayClip Component to the entity with the dense clip as BlobAssetReference<Clip> param
        dstManager.AddComponentData(entity, new RotateCube_PlayClipRuntime
        {
            clip  = denseClip,
            curve = animationCurve
        });

        //Add DeltaTime Component to the entity with default value (float 0.0f)
        dstManager.AddComponent <DeltaTimeRuntime>(entity);
    }
예제 #6
0
 public void Convert(Entity entity, EntityManager dstManager,
                     GameObjectConversionSystem conversionSystem)
 {
     dstManager.AddComponentData(entity, new BoundsComponent {
         Bounds = Mesh.bounds
     });
     // Declare the dependency on the asset. Note the lack of a check for null.
     conversionSystem.DeclareAssetDependency(gameObject, Mesh);
 }
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        if (Clip == null)
            return;

        conversionSystem.DeclareAssetDependency(gameObject, Clip);

        dstManager.AddComponentData(entity, new Scorpion_PlayClipComponent
        {
            Clip = conversionSystem.BlobAssetStore.GetClip(Clip)
        });

        dstManager.AddComponent<DeltaTime>(entity);
    }
    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);
    }
예제 #9
0
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        if (clip == null)
        {
            return;
        }

        conversionSystem.DeclareAssetDependency(gameObject,
                                                clip); //if clip changes then the dependent (this.gameObject) will get re-converted

        var clipRef = clip.ToDenseClip();

        conversionSystem.BlobAssetStore.AddUniqueBlobAsset(ref clipRef);
        dstManager.AddComponentData(entity, new PlayerDeath_PlayClipRuntime
        {
            clip = clipRef
        });

        dstManager.AddComponent <DeltaTimeRuntime>(entity);
    }
    public void Convert(Entity entity, EntityManager dstManager, [NotNull] GameObjectConversionSystem conversionSystem)
    {
        conversionSystem.DeclareAssetDependency(gameObject, blendTree);

        var rigComponent      = dstManager.GetComponentData <Rig>(entity);
        var clipConfiguration = new ClipConfiguration {
            Mask = ClipConfigurationMask.LoopValues
        };
        var bakeOptions = new BakeOptions
        {
            RigDefinition = rigComponent.Value, ClipConfiguration = clipConfiguration, SampleRate = 60.0f
        };

        var blendTreeIndex = BlendTreeConversion.Convert(blendTree, entity, dstManager, bakeOptions);

        var blendTreeComponents = dstManager.GetBuffer <BlendTree1DResource>(entity);
        var blobBlendTreeRef    =
            BlendTreeBuilder.CreateBlendTree1DFromComponents(blendTreeComponents[blendTreeIndex], dstManager, entity);

        conversionSystem.BlobAssetStore.AddUniqueBlobAsset(ref blobBlendTreeRef);

        var blendTreeRuntime = new BlendTree1DRuntime
        {
            BlendTree = blobBlendTreeRef
        };

        dstManager.AddComponentData(entity, blendTreeRuntime);

        var blendTreeParamRuntime = new BlendTree1DParamRuntime
        {
            VelocityStep = velocityStep,
            VelocityX    = 0.0f
        };

        dstManager.AddComponentData(entity, blendTreeParamRuntime);

        dstManager.AddComponent <DeltaTimeRuntime>(entity);
    }
예제 #11
0
        private static void AddComponentsToEntity(
            Entity entity,
            EntityManager dstEntityManager,
            GameObjectConversionSystem conversionSystem,
            Renderer meshRenderer,
            Mesh mesh,
            List <Material> materials,
            Dictionary <MaterialLookupKey, Material> createdMaterials,
            bool flipWinding,
            int id,
            LightMaps lightMaps,
            int lightmapIndex,
            AABB localBounds)
        {
            var needMotionVectorPass = (meshRenderer.motionVectorGenerationMode == MotionVectorGenerationMode.Object) ||
                                       (meshRenderer.motionVectorGenerationMode == MotionVectorGenerationMode.ForceNoMotion);

            var renderMesh = new RenderMesh
            {
                mesh                 = mesh,
                castShadows          = meshRenderer.shadowCastingMode,
                receiveShadows       = meshRenderer.receiveShadows,
                layer                = meshRenderer.gameObject.layer,
                subMesh              = id,
                needMotionVectorPass = needMotionVectorPass
            };

            var staticLightingMode = StaticLightingMode.None;

            if (meshRenderer.lightmapIndex >= 65534 || meshRenderer.lightmapIndex < 0)
            {
                staticLightingMode = StaticLightingMode.LightProbes;
            }
            else if (meshRenderer.lightmapIndex >= 0)
            {
                staticLightingMode = StaticLightingMode.Lightmapped;
            }

            dstEntityManager.AddComponentData(entity, new PerInstanceCullingTag());
            dstEntityManager.AddComponentData(entity, new RenderBounds {
                Value = localBounds
            });

            var material = materials[id];

            if (staticLightingMode == StaticLightingMode.Lightmapped && lightMaps.isValid)
            {
                conversionSystem.DeclareAssetDependency(meshRenderer.gameObject, material);

                var localFlags = LightMappingFlags.Lightmapped;
                if (lightMaps.hasDirections)
                {
                    localFlags |= LightMappingFlags.Directional;
                }
                if (lightMaps.hasShadowMask)
                {
                    localFlags |= LightMappingFlags.ShadowMask;
                }

                var key = new MaterialLookupKey
                {
                    BaseMaterial = materials[id],
                    lightmaps    = lightMaps,
                    Flags        = localFlags
                };

                var lookUp = createdMaterials ?? new Dictionary <MaterialLookupKey, Material>();
                if (lookUp.TryGetValue(key, out Material result))
                {
                    material = result;
                }
                else
                {
                    material      = new Material(materials[id]);
                    material.name = $"{material.name}_Lightmapped_";
                    material.EnableKeyword("LIGHTMAP_ON");

                    material.SetTexture("unity_Lightmaps", lightMaps.colors);
                    material.SetTexture("unity_LightmapsInd", lightMaps.directions);
                    material.SetTexture("unity_ShadowMasks", lightMaps.shadowMasks);

                    if (lightMaps.hasDirections)
                    {
                        material.name = material.name + "_DIRLIGHTMAP";
                        material.EnableKeyword("DIRLIGHTMAP_COMBINED");
                    }

                    if (lightMaps.hasShadowMask)
                    {
                        material.name = material.name + "_SHADOW_MASK";
                    }

                    lookUp[key] = material;
                }
                dstEntityManager.AddComponentData(entity, new BuiltinMaterialPropertyUnity_LightmapST()
                {
                    Value = meshRenderer.lightmapScaleOffset
                });
                dstEntityManager.AddComponentData(entity, new BuiltinMaterialPropertyUnity_LightmapIndex()
                {
                    Value = lightmapIndex
                });
                dstEntityManager.AddSharedComponentData(entity, lightMaps);
            }
            else if (staticLightingMode == StaticLightingMode.LightProbes)
            {
                if (meshRenderer.lightProbeUsage == LightProbeUsage.CustomProvided)
                {
                    dstEntityManager.AddComponent <CustomProbeTag>(entity);
                }
                else if (meshRenderer.lightProbeUsage == LightProbeUsage.BlendProbes &&
                         LightmapSettings.lightProbes != null &&
                         LightmapSettings.lightProbes.count > 0)
                {
                    dstEntityManager.AddComponent <BlendProbeTag>(entity);
                }
                else
                {
                    dstEntityManager.AddComponent <AmbientProbeTag>(entity);
                }
            }
            renderMesh.material = material;

            dstEntityManager.AddSharedComponentData(entity, renderMesh);

            if (flipWinding)
            {
                dstEntityManager.AddComponent(entity, ComponentType.ReadWrite <RenderMeshFlippedWindingTag>());
            }

            conversionSystem.ConfigureEditorRenderData(entity, meshRenderer.gameObject, true);

#if ENABLE_HYBRID_RENDERER_V2
            dstEntityManager.AddComponent(entity, ComponentType.ReadOnly <WorldToLocal_Tag>());

#if HDRP_9_0_0_OR_NEWER
            // HDRP previous frame matrices (for motion vectors)
            if (needMotionVectorPass)
            {
                dstEntityManager.AddComponent(entity, ComponentType.ReadWrite <BuiltinMaterialPropertyUnity_MatrixPreviousM>());
                dstEntityManager.AddComponent(entity, ComponentType.ReadWrite <BuiltinMaterialPropertyUnity_MatrixPreviousMI_Tag>());
            }
            dstEntityManager.AddComponentData(entity, CreateMotionVectorsParams(ref renderMesh, ref meshRenderer));
#endif

            dstEntityManager.AddComponentData(entity, new BuiltinMaterialPropertyUnity_RenderingLayer
            {
                Value = new uint4(meshRenderer.renderingLayerMask, 0, 0, 0)
            });

            dstEntityManager.AddComponentData(entity, new BuiltinMaterialPropertyUnity_WorldTransformParams
            {
                Value = flipWinding ? new float4(0, 0, 0, -1) : new float4(0, 0, 0, 1)
            });

#if URP_9_0_0_OR_NEWER
            // Default initialized light data for URP
            dstEntityManager.AddComponentData(entity, new BuiltinMaterialPropertyUnity_LightData
            {
                Value = new float4(0, 0, 1, 0)
            });
#endif
#endif
        }
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        if (Clips == null || BlendThresholds == null)
        {
            return;
        }

        if (!dstManager.HasComponent <Rig>(entity))
        {
            throw new System.InvalidOperationException("RigComponent must be converted before this component.");
        }

        if (Clips.Length != BlendThresholds.Length)
        {
            throw new System.InvalidOperationException("You must have the same number of clips and blendthresholds.");
        }

        var        rigComponent = GetComponent <RigComponent>() as RigComponent;
        StringHash motionId     = "";

        for (var boneIter = 0; boneIter < rigComponent.Bones.Length; boneIter++)
        {
            if (MotionJointName == rigComponent.Bones[boneIter].name)
            {
                motionId = RigGenerator.ComputeRelativePath(rigComponent.Bones[boneIter], rigComponent.transform);
            }
        }

        var rigDefinition     = dstManager.GetComponentData <Rig>(entity);
        var clipConfiguration = new ClipConfiguration();

        clipConfiguration.Mask     = ClipConfigurationMask.LoopTime | ClipConfigurationMask.LoopValues | ClipConfigurationMask.CycleRootMotion | ClipConfigurationMask.DeltaRootMotion;
        clipConfiguration.MotionID = motionId;

        var denseClips = new NativeArray <SampleClip>(Clips.Length, Allocator.Temp);
        var durations  = new NativeArray <SampleClipDuration>(Clips.Length, Allocator.Temp);
        var thresholds = new NativeArray <SampleClipBlendThreshold>(Clips.Length, Allocator.Temp);

        for (int i = 0; i < Clips.Length; i++)
        {
            conversionSystem.DeclareAssetDependency(gameObject, Clips[i]);

            denseClips[i] = new SampleClip
            {
                Clip = UberClipNode.Bake(rigDefinition.Value, Clips[i].ToDenseClip(), clipConfiguration, 60.0f)
            };
            durations[i] = new SampleClipDuration {
                Value = denseClips[i].Clip.Value.Duration
            };
            thresholds[i] = new SampleClipBlendThreshold {
                Value = BlendThresholds[i]
            };
        }

        var synchronizeMotions = dstManager.AddBuffer <SampleClip>(entity);

        synchronizeMotions.CopyFrom(denseClips);

        var synchronizeMotionDurations = dstManager.AddBuffer <SampleClipDuration>(entity);

        synchronizeMotionDurations.CopyFrom(durations);

        var synchronizeMotionThresholds = dstManager.AddBuffer <SampleClipBlendThreshold>(entity);

        synchronizeMotionThresholds.CopyFrom(thresholds);

        dstManager.AddComponentData(entity, new WeightComponent
        {
            Value = 0.0f
        });

        denseClips.Dispose();
        durations.Dispose();
        thresholds.Dispose();
    }