From 35bf236e75dc6d7721a1ff38a9dbebb339ae4ba5 Mon Sep 17 00:00:00 2001 From: Tim Aidley Date: Wed, 31 May 2023 23:04:30 -0700 Subject: [PATCH] Not-working color export --- Assets/Scripts/Export/ExportCollector.cs | 69 ++++++++++++++---------- Assets/Scripts/Export/ExportFbx.cs | 12 +++-- 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/Assets/Scripts/Export/ExportCollector.cs b/Assets/Scripts/Export/ExportCollector.cs index 8667f7e863..253e5a38a8 100644 --- a/Assets/Scripts/Export/ExportCollector.cs +++ b/Assets/Scripts/Export/ExportCollector.cs @@ -273,39 +273,50 @@ static ExportUtils.GroupPayload BuildGroupPayload(SceneStatePayload payload, GeometryPool geometry = batch.pool; List strokes = batch.strokes; - string legacyUniqueName = $"{desc.m_DurableName}_{desc.m_Guid}_{group.id}_i{batchIndex}"; - string friendlyGeometryName = $"brush_{desc.m_DurableName}_g{group.id}_b{batchIndex}"; + int strokeIndex = 0; + foreach (var stroke in strokes) + { + Color32 color = geometry.m_Colors[geometry.m_Tris[stroke.m_BatchSubset.m_iTriIndex]]; - UnityEngine.Profiling.Profiler.BeginSample("ConvertToMetersAndChangeBasis"); - ExportUtils.ConvertUnitsAndChangeBasis(geometry, payload); - UnityEngine.Profiling.Profiler.EndSample(); + string legacyUniqueName = $"{desc.m_DurableName}_{desc.m_Guid}_{group.id}_i{batchIndex}_s{strokeIndex}_c{color.r:X2}{color.g:X2}{color.b:X2}{color.a:X2}"; + string friendlyGeometryName = $"brush_{desc.m_DurableName}_g{group.id}_b{batchIndex}_s{strokeIndex}_c{color.r:X2}{color.g:X2}{color.b:X2}{color.a:X2}"; - if (payload.reverseWinding) - { - // Note: this triangle flip intentionally un-does the Unity FBX import flip. - ExportUtils.ReverseTriangleWinding(geometry, 1, 2); - } + UnityEngine.Profiling.Profiler.BeginSample("ConvertToMetersAndChangeBasis"); + ExportUtils.ConvertUnitsAndChangeBasis(geometry, payload); + UnityEngine.Profiling.Profiler.EndSample(); - if (App.PlatformConfig.EnableExportMemoryOptimization && - payload.temporaryDirectory != null) - { - string filename = Path.Combine( - payload.temporaryDirectory, - legacyUniqueName + ".Gpoo"); - geometry.MakeGeometryNotResident(filename); + if (payload.reverseWinding) + { + // Note: this triangle flip intentionally un-does the Unity FBX import flip. + ExportUtils.ReverseTriangleWinding(geometry, 1, 2); + } + + if (App.PlatformConfig.EnableExportMemoryOptimization && + payload.temporaryDirectory != null) + { + string filename = Path.Combine( + payload.temporaryDirectory, + legacyUniqueName + ".Gpoo"); + geometry.MakeGeometryNotResident(filename); + } + + List oneStroke = new List(1); + oneStroke.Add(stroke); + brush.m_desc.ColorParams["Color"] = new Color(color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f); + + group.brushMeshes.Add(new ExportUtils.BrushMeshPayload( + payload.groupIdMapping.GetId(exportGroup.m_group)) + { + legacyUniqueName = legacyUniqueName, + // This is the only instance of the mesh, so the node doesn't need an extra instance id + nodeName = friendlyGeometryName, + xform = Matrix4x4.identity, + geometry = geometry, + geometryName = friendlyGeometryName, + exportableMaterial = brush.m_desc, + strokes = oneStroke, + }); } - group.brushMeshes.Add(new ExportUtils.BrushMeshPayload( - payload.groupIdMapping.GetId(exportGroup.m_group)) - { - legacyUniqueName = legacyUniqueName, - // This is the only instance of the mesh, so the node doesn't need an extra instance id - nodeName = friendlyGeometryName, - xform = Matrix4x4.identity, - geometry = geometry, - geometryName = friendlyGeometryName, - exportableMaterial = brush.m_desc, - strokes = strokes, - }); } } return group; diff --git a/Assets/Scripts/Export/ExportFbx.cs b/Assets/Scripts/Export/ExportFbx.cs index 6f80b9bdaa..4c38479031 100644 --- a/Assets/Scripts/Export/ExportFbx.cs +++ b/Assets/Scripts/Export/ExportFbx.cs @@ -98,14 +98,14 @@ public FbxSurfaceMaterial GetOrCreateFbxMaterial( // Since TBT can't detect reference-equality of FbxMaterial, we have to help it by // making name-equality the same as reference-equality. IOW distinct materials need // distinct names. - if (m_createdMaterials.TryGetValue(exportableMaterial, out FbxSurfaceMaterial mtl)) { - return mtl; - } else { + // if (m_createdMaterials.TryGetValue(exportableMaterial, out FbxSurfaceMaterial mtl)) { + // return mtl; + // } else { FbxSurfaceMaterial newMtl = ExportFbx.CreateFbxMaterial( this, meshNamespace, exportableMaterial, m_createdMaterialNames); m_createdMaterials[exportableMaterial] = newMtl; return newMtl; - } + // } } } @@ -260,7 +260,9 @@ internal static FbxSurfaceMaterial CreateFbxMaterial( FbxSurfaceLambert material = FbxSurfaceLambert.Create(G.m_scene, materialName); material.Ambient.Set(new FbxDouble3(0, 0, 0)); - material.Diffuse.Set(new FbxDouble3(1.0, 1.0, 1.0)); + Color color = Color.white; + exportableMaterial.ColorParams.TryGetValue("Color", out color); + material.Diffuse.Set(new FbxDouble3(color.r, color.g, color.b)); if (exportableMaterial.EmissiveFactor > 0) { material.EmissiveFactor.Set(exportableMaterial.EmissiveFactor); material.Emissive.Set(new FbxDouble3(1.0, 1.0, 1.0));