Exemplo n.º 1
0
        void Initialize()
        {
            meshFilter.sharedMesh = sharedMesh;
            if (!debugHelperRenderer)
            {
                meshRenderer.receiveShadows = ((query & LayerUsageFlags.ReceiveShadows) == LayerUsageFlags.ReceiveShadows);
                switch (query & (LayerUsageFlags.Renderable | LayerUsageFlags.CastShadows))
                {
                case LayerUsageFlags.None:                          meshRenderer.enabled = false; break;

                case LayerUsageFlags.Renderable:            meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;                   break;

                case LayerUsageFlags.CastShadows:           meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.ShadowsOnly;   break;

                case LayerUsageFlags.RenderCastShadows:     meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;                    break;
                }

#if UNITY_EDITOR
                UnityEditor.EditorUtility.SetSelectedRenderState(meshRenderer, UnityEditor.EditorSelectedRenderState.Hidden);
                ChiselGeneratedComponentManager.SetHasLightmapUVs(sharedMesh, false);
#endif
            }
            else
            {
                meshRenderer.allowOcclusionWhenDynamic  = false;
                meshRenderer.lightProbeUsage            = LightProbeUsage.Off;
                meshRenderer.reflectionProbeUsage       = ReflectionProbeUsage.Off;
                meshRenderer.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion;
                meshRenderer.shadowCastingMode          = ShadowCastingMode.Off;
#if UNITY_EDITOR
                meshRenderer.scaleInLightmap = 0.0f;
#endif
            }
        }
Exemplo n.º 2
0
        void UpdateSettings(ChiselModel model, GameObjectState state, bool meshIsModified)
        {
#if UNITY_EDITOR
            Profiler.BeginSample("CheckIfFullMeshNeedsToBeHidden");
            // If we need to render partial meshes (where some brushes are hidden) then we should show the full mesh
            ChiselGeneratedComponentManager.CheckIfFullMeshNeedsToBeHidden(model, this);
            Profiler.EndSample();
            if (meshIsModified)
            {
                // Setting the sharedMesh to ensure the meshFilter knows it needs to be updated
                Profiler.BeginSample("OverrideMesh");
                meshFilter.sharedMesh = meshFilter.sharedMesh;
                Profiler.EndSample();
                Profiler.BeginSample("SetDirty");
                UnityEditor.EditorUtility.SetDirty(meshFilter);
                UnityEditor.EditorUtility.SetDirty(model);
                Profiler.EndSample();
                Profiler.BeginSample("SetHasLightmapUVs");
                ChiselGeneratedComponentManager.SetHasLightmapUVs(sharedMesh, false);
                Profiler.EndSample();
                Profiler.BeginSample("ClearLightmapData");
                ChiselGeneratedComponentManager.ClearLightmapData(state, this);
                Profiler.EndSample();
            }
#endif
        }
        static readonly List <GeneratedMeshContents> __foundContents = new List <GeneratedMeshContents>(); // static to avoid allocations
        public void Update(ChiselModel model, GameObjectState state, GeneratedMeshDescription[] meshDescriptions, int startIndex, int endIndex)
        {
            bool meshIsModified = false;

            // Retrieve the generatedMeshes and its materials, combine them into a single Unity Mesh/Material array
            try
            {
                for (int i = startIndex; i < endIndex; i++)
                {
                    ref var meshDescription       = ref meshDescriptions[i];
                    var     generatedMeshContents = model.Node.GetGeneratedMesh(meshDescription);
                    if (generatedMeshContents == null)
                    {
                        continue;
                    }
                    if (generatedMeshContents.indices.Length == 0)
                    {
                        generatedMeshContents.Dispose();
                        continue;
                    }
                    var renderMaterial = ChiselBrushMaterialManager.GetRenderMaterialByInstanceID(meshDescription.surfaceParameter);
                    __foundContents.Add(generatedMeshContents);
                    __foundMaterials.Add(renderMaterial);
                }
                triangleBrushes.Clear();
                if (__foundContents.Count == 0)
                {
                    if (sharedMesh.vertexCount > 0)
                    {
                        sharedMesh.Clear(keepVertexLayout: true);
                    }
                }
                else
                {
                    sharedMesh.CopyFrom(__foundContents, triangleBrushes);
#if UNITY_EDITOR
                    ChiselGeneratedComponentManager.SetHasLightmapUVs(sharedMesh, false);
#endif
                }
                if (renderMaterials != null &&
                    renderMaterials.Length == __foundMaterials.Count)
                {
                    __foundMaterials.CopyTo(renderMaterials);
                }
                else
                {
                    renderMaterials = __foundMaterials.ToArray();
                }
                if (meshFilter.sharedMesh != sharedMesh)
                {
                    meshFilter.sharedMesh = sharedMesh;
                    meshIsModified        = true;
                }
                meshRenderer.sharedMaterials = renderMaterials;
                meshRenderer.enabled         = sharedMesh.vertexCount > 0;
            }