public static void OnSetRendererActive(int rendererGUID, bool active) { Debug.Assert(m_Renderers.Count > rendererGUID); SMeshDesc renderer = m_Renderers[rendererGUID]; renderer.m_RenderingObject.SetActive(active); }
//---------------------------------------------------------------------------- private static bool ResizeParticleMeshBuffer(Mesh mesh, SMeshDesc renderer, uint usedVertexCount, uint usedIndexCount, uint reservedVertexCount, uint reservedIndexCount, bool useLargeIdx) { bool hasBeenResized = false; if (mesh.vertexCount < usedVertexCount) { // We only do the transition from uint16 to uint32 because the transition clear the index buffer... if (useLargeIdx == true && mesh.indexFormat == IndexFormat.UInt16) { mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; } else if (useLargeIdx == false && mesh.indexFormat == IndexFormat.UInt32) { mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt16; } mesh.Clear(); mesh.vertices = new Vector3[reservedVertexCount]; // positions if (renderer.HasMaterialFlag(EMaterialFlags.Has_Color)) { mesh.colors = new Color[reservedVertexCount]; // color } if (renderer.HasMaterialFlag(EMaterialFlags.Has_Lighting)) { mesh.normals = new Vector3[reservedVertexCount]; // normal } if (renderer.HasMaterialFlag(EMaterialFlags.Has_RibbonComplex)) { mesh.uv = new Vector2[reservedVertexCount]; // uvFactors mesh.uv2 = new Vector2[reservedVertexCount]; // uvScale mesh.uv3 = new Vector2[reservedVertexCount]; // uvOffset if (renderer.HasMaterialFlag(EMaterialFlags.Has_AlphaRemap)) { mesh.uv4 = new Vector2[reservedVertexCount]; // alpha cursor } } else if (renderer.HasMaterialFlag(EMaterialFlags.Has_AnimBlend)) { mesh.uv = new Vector2[reservedVertexCount]; // uv0 mesh.uv2 = new Vector2[reservedVertexCount]; // uv1 mesh.uv3 = new Vector2[reservedVertexCount]; // atlas id and if Has_AlphaRemap, alpha cursor } else { if (renderer.HasMaterialFlag(EMaterialFlags.Has_Diffuse)) { mesh.uv = new Vector2[reservedVertexCount]; // uv0 } if (renderer.HasMaterialFlag(EMaterialFlags.Has_AlphaRemap)) { mesh.uv2 = new Vector2[reservedVertexCount]; // alpha cursor } } hasBeenResized = true; } if (mesh.GetIndexCount(0) < usedIndexCount) { int[] triangles = new int[reservedIndexCount]; // index //fix to set the right vertex buffer size on PS4 : fill the index buffer with vertex ids if (Application.platform == RuntimePlatform.PS4) { for (int i = 0; i < mesh.vertexCount; ++i) { triangles[i] = i; } } mesh.triangles = triangles; hasBeenResized = true; } return(hasBeenResized); }
public static bool OnRendererResize(int rendererGUID, int vertexCount, int indexCount, int growLarger) { Debug.Assert(m_Renderers.Count > rendererGUID); Debug.Assert(indexCount % 3 == 0); SMeshDesc renderer = m_Renderers[rendererGUID]; MeshFilter filter = renderer.m_Slice; Debug.Assert(filter != null); // Load the default size configuration string particleMeshGeneratedName = renderer.m_BatchDesc.m_GeneratedName; PKFxSettings.SParticleMeshDefaultSize meshSizeToUpdate = GetParticleMeshDefaultSizeSettings(particleMeshGeneratedName); uint usedVertexCount = (uint)vertexCount; uint usedIndexCount = (uint)indexCount; uint reserveVertexCount = usedVertexCount; uint reserveIndexCount = usedIndexCount; Bounds initBounds = new Bounds(); // If we need to grow buffer but did not find a setting for the buffer size if (growLarger == 1) { reserveVertexCount += (uint)(usedVertexCount * PKFxSettings.VertexBufferSizeMultiplicator); reserveIndexCount += (uint)(usedIndexCount * PKFxSettings.IndexBufferSizeMultiplicator); reserveIndexCount += 3 - (reserveIndexCount % 3); if (meshSizeToUpdate == null) // Did not find a setting for this buffer { #if UNITY_EDITOR if (PKFxSettings.AutomaticMeshResizing) { // If in editor mode, we register the size of the buffers in a new particle mesh default size entry meshSizeToUpdate = new PKFxSettings.SParticleMeshDefaultSize(); meshSizeToUpdate.m_GeneratedName = particleMeshGeneratedName; meshSizeToUpdate.m_EffectNames = renderer.m_BatchDesc.m_EffectNames; meshSizeToUpdate.m_DefaultVertexBufferSize = (int)reserveVertexCount; meshSizeToUpdate.m_DefaultIndexBufferSize = (int)reserveIndexCount; PKFxSettings.MeshesDefaultSize.Add(meshSizeToUpdate); } #endif } else // We did find a setting for this buffer { if (usedVertexCount < meshSizeToUpdate.m_DefaultVertexBufferSize) // The registered { reserveVertexCount = (uint)meshSizeToUpdate.m_DefaultVertexBufferSize; // Otherwise, just update the reserved count usedVertexCount = reserveVertexCount; // Forces the mesh to get resized to this size if we found a config } #if UNITY_EDITOR else if (PKFxSettings.AutomaticMeshResizing) { meshSizeToUpdate.m_DefaultVertexBufferSize = (int)reserveVertexCount; // Update the settings IFN } #endif if (usedIndexCount < meshSizeToUpdate.m_DefaultIndexBufferSize) { reserveIndexCount = (uint)meshSizeToUpdate.m_DefaultIndexBufferSize; // Otherwise, just update the reserved count usedIndexCount = reserveIndexCount; // Forces the mesh to get resized to this size if we found a config } #if UNITY_EDITOR else if (PKFxSettings.AutomaticMeshResizing) { meshSizeToUpdate.m_DefaultIndexBufferSize = (int)reserveIndexCount; // Update the settings IFN } #endif initBounds = meshSizeToUpdate.m_StaticWorldBounds; } } // We choose to use large indices or not here: bool useLargeIndices = reserveVertexCount > UInt16.MaxValue; Mesh mesh = filter.mesh; mesh.bounds = initBounds; bool ok = ResizeParticleMeshBuffer(mesh, renderer, usedVertexCount, usedIndexCount, reserveVertexCount, reserveIndexCount, useLargeIndices); return(ok); }