/// <summary>
        /// Convert the given <see cref="Renderer"/> into a single Hybrid Rendered entity that uses
        /// the first <see cref="Material"/> configured in the <see cref="Renderer"/>.
        /// </summary>
        public void ConvertToSingleEntity(
            EntityManager dstEntityManager,
            GameObjectConversionSystem conversionSystem,
            RenderMeshDescription renderMeshDescription,
            Renderer renderer)
        {
            var entity = conversionSystem.GetPrimaryEntity(renderer);

            var lightmappedMaterial = ConfigureHybridStaticLighting(
                entity,
                dstEntityManager,
                renderer,
                renderMeshDescription.RenderMesh.material);

            if (lightmappedMaterial != null)
            {
                renderMeshDescription.RenderMesh.material = lightmappedMaterial;
            }

            RenderMeshUtility.AddComponents(
                entity,
                dstEntityManager,
                renderMeshDescription);

            conversionSystem.ConfigureEditorRenderData(entity, renderer.gameObject, true);
        }
        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);
            }
        }
        /// <summary>
        /// Convert the given <see cref="Renderer"/> into a multiple Hybrid Rendered entities such that every
        /// <see cref="Material"/> in the <see cref="Renderer"/> is converted into one entity that uses that <see cref="Material"/>
        /// with the corresponding sub-mesh from <see cref="RenderMesh.mesh"/>. All created entities will be parented
        /// to the entity created from <see cref="root"/>.
        /// </summary>
        public void ConvertToMultipleEntities(
            EntityManager dstEntityManager,
            GameObjectConversionSystem conversionSystem,
            RenderMeshDescription renderMeshDescription,
            Renderer renderer,
            List <Material> sharedMaterials,
            Transform root)
        {
            int materialCount = sharedMaterials.Count;

            float4x4 localToWorld = root.localToWorldMatrix;
            var      rootEntity   = conversionSystem.GetPrimaryEntity(root);

            for (var m = 0; m != materialCount; m++)
            {
                var meshEntity = conversionSystem.CreateAdditionalEntity(renderer);

                // required for incremental conversion to work without a dependency on the transform itself.
                dstEntityManager.AddComponent <CopyTransformFromPrimaryEntityTag>(meshEntity);
                dstEntityManager.AddComponentData(meshEntity, new LocalToWorld {
                    Value = localToWorld
                });
                if (!dstEntityManager.HasComponent <Static>(meshEntity))
                {
                    dstEntityManager.AddComponentData(meshEntity, new Parent {
                        Value = rootEntity
                    });
                    dstEntityManager.AddComponentData(meshEntity,
                                                      new LocalToParent {
                        Value = float4x4.identity
                    });
                }

                var material = sharedMaterials[m];

                var lightmappedMaterial = ConfigureHybridLightMapping(
                    meshEntity,
                    dstEntityManager,
                    renderer,
                    material);

                if (lightmappedMaterial != null)
                {
                    material = lightmappedMaterial;
                }

                renderMeshDescription.RenderMesh.subMesh  = m;
                renderMeshDescription.RenderMesh.material = material;

                RenderMeshUtility.AddComponents(
                    meshEntity,
                    dstEntityManager,
                    renderMeshDescription);

                RemoveLightProbeComponentsFromLightMappedEntities(meshEntity, dstEntityManager);

                conversionSystem.ConfigureEditorRenderData(meshEntity, renderer.gameObject, true);
            }
        }