private void UpdatePaintedMats() { // Mark foreach (var mat in scene.Mats) { foreach (var slot in mat.Slots) { slot.Dirty = true; } } /* * if (mat.Template != null) * { * foreach (var slot in mat.Template.Slots) * { * if (paintedGroups.Contains(slot.WriteR.SourceGroup) == true || * paintedGroups.Contains(slot.WriteG.SourceGroup) == true || * paintedGroups.Contains(slot.WriteB.SourceGroup) == true || * paintedGroups.Contains(slot.WriteA.SourceGroup) == true) * { * var matSlot = mat.Slots.Find(s => s.Name == slot.Name); * * if (matSlot != null) * { * matSlot.Dirty = true; * } * } * } * } * } */ scene.UpdateMergedLayers(currentLayer); foreach (var mat in scene.Mats) { if (mat.Template != null) { foreach (var templateSlot in mat.Template.Slots) { var sceneSlot = mat.GetSlot(templateSlot.Name); if (sceneSlot.Texture == null) { sceneSlot.Texture = P3dHelper.GetRenderTexture(mat.Desc); } var textureR = mat.GetFinalTexture(templateSlot.WriteR.SourceGroup); var textureG = mat.GetFinalTexture(templateSlot.WriteG.SourceGroup); var textureB = mat.GetFinalTexture(templateSlot.WriteB.SourceGroup); var textureA = mat.GetFinalTexture(templateSlot.WriteA.SourceGroup); var channelR = P3dHelper.IndexToVector((int)templateSlot.WriteR.SourceChannel); var channelG = P3dHelper.IndexToVector((int)templateSlot.WriteG.SourceChannel); var channelB = P3dHelper.IndexToVector((int)templateSlot.WriteB.SourceChannel); var channelA = P3dHelper.IndexToVector((int)templateSlot.WriteA.SourceChannel); P3dPaintReplaceChannels.Blit(sceneSlot.Texture, textureR, textureG, textureB, textureA, channelR, channelG, channelB, channelA); } } } // Sweep foreach (var mat in scene.Mats) { for (var i = 0; i < mat.Slots.Count; i++) { var slot = mat.Slots[i]; if (slot.Dirty == true) { P3dHelper.ReleaseRenderTexture(slot.Texture); mat.Slots.RemoveAt(i); } } } }
private void DrawNextPaint() { if (P3dPaintMaterial.CachedInstances.Count > 0) { if (paintIndex >= P3dPaintMaterial.CachedInstances.Count) { paintIndex = 0; } var paint = P3dPaintMaterial.CachedInstances[paintIndex++]; DestroyImmediate(paint.Thumbnail); paint.Thumbnail = null; if (paint != null && paint.Thumbnail == null && paint.Material != null) { var tempTextures = new List <RenderTexture>(); if (paintProperties == null) { paintProperties = new MaterialPropertyBlock(); } else { paintProperties.Clear(); } if (paint.Template != null) { foreach (var slot in paint.Template.Slots) { var slotR = paint.GetSlot(slot.WriteR.SourceGroup); var slotG = paint.GetSlot(slot.WriteG.SourceGroup); var slotB = paint.GetSlot(slot.WriteB.SourceGroup); var slotA = paint.GetSlot(slot.WriteA.SourceGroup); if (slotR != null || slotG != null || slotB != null || slotA != null) { var tempTexture = P3dHelper.GetRenderTexture(new RenderTextureDescriptor(1024, 1024, RenderTextureFormat.ARGB32, 0)); tempTextures.Add(tempTexture); var textureR = P3dHelper.GetRenderTexture(tempTexture.descriptor); var textureG = P3dHelper.GetRenderTexture(tempTexture.descriptor); var textureB = P3dHelper.GetRenderTexture(tempTexture.descriptor); var textureA = P3dHelper.GetRenderTexture(tempTexture.descriptor); WriteThumbnailTex(textureR, slotR, slot.WriteR); WriteThumbnailTex(textureG, slotG, slot.WriteG); WriteThumbnailTex(textureB, slotB, slot.WriteB); WriteThumbnailTex(textureA, slotA, slot.WriteA); var channelR = P3dHelper.IndexToVector((int)slot.WriteR.SourceChannel); var channelG = P3dHelper.IndexToVector((int)slot.WriteG.SourceChannel); var channelB = P3dHelper.IndexToVector((int)slot.WriteB.SourceChannel); var channelA = P3dHelper.IndexToVector((int)slot.WriteA.SourceChannel); P3dPaintReplaceChannels.Blit(tempTexture, textureR, textureG, textureB, textureA, channelR, channelG, channelB, channelA); P3dHelper.ReleaseRenderTexture(textureR); P3dHelper.ReleaseRenderTexture(textureG); P3dHelper.ReleaseRenderTexture(textureB); P3dHelper.ReleaseRenderTexture(textureA); paintProperties.SetTexture(slot.Name, tempTexture); } } } BeginPreview(thumbnailUtil, new Rect(0, 0, settings.ThumbnailSize, settings.ThumbnailSize)); var probeAnchor = default(Transform); var probeExists = false; if (settings.Environment != null) { probeAnchor = settings.Environment.transform; probeExists = true; } switch (paint.Style) { case P3dPaintMaterial.StyleType.Seamless: { thumbnailUtil.DrawMesh(P3dHelper.GetSphereMesh(), Matrix4x4.identity, paint.Material, 0, paintProperties, probeAnchor, probeExists); } break; case P3dPaintMaterial.StyleType.Decal: { thumbnailUtil.DrawMesh(P3dHelper.GetQuadMesh(), Matrix4x4.identity, paint.Material, 0, paintProperties, probeAnchor, probeExists); } break; } paint.Thumbnail = P3dHelper.GetReadableCopy(EndPreview(thumbnailUtil)); foreach (var tempTexture in tempTextures) { P3dHelper.ReleaseRenderTexture(tempTexture); } } } }