Skip to content

Commit 8d657fc

Browse files
committed
Remove Comments
1 parent 4fcf99f commit 8d657fc

File tree

1 file changed

+6
-74
lines changed

1 file changed

+6
-74
lines changed

Common_glTF_Exporter/Export/Draco.cs

Lines changed: 6 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
namespace Common_glTF_Exporter.Export
1313
{
14-
// ------------------------------------------------------------
15-
// Util GLB simple para .NET Framework (sin tuples)
16-
// ------------------------------------------------------------
14+
1715
internal sealed class GlbData
1816
{
1917
public string Json;
@@ -25,10 +23,6 @@ public GlbData(string json, byte[] bin)
2523
}
2624
}
2725

28-
// ------------------------------------------------------------
29-
// Patcher: copia EXTRAS del original → temp, mergea extensiones
30-
// y EMBEBE imágenes en .gltf (y .glb si hiciera falta), borrando archivos externos.
31-
// ------------------------------------------------------------
3226
internal static class GltfExtrasPatcher
3327
{
3428
public static void PatchExtras(string originalPath, string tempPath)
@@ -47,22 +41,15 @@ public static void PatchExtras(string originalPath, string tempPath)
4741
}
4842
}
4943

50-
// --------- .gltf (JSON externo) ----------
5144
private static void PatchExtrasGltf(string originalGltf, string tempGltf)
5245
{
5346
JObject src = JObject.Parse(File.ReadAllText(originalGltf));
5447
JObject dst = JObject.Parse(File.ReadAllText(tempGltf));
5548

56-
// 1) copiar EXTRAS + extensiones desconocidas en NODES
5749
PatchArrayByIndex(src, dst, "nodes", PatchNodeLike);
5850

59-
// (Opcional) si querés también en meshes/primitives:
60-
// PatchMeshesAndPrimitives(src, dst);
61-
62-
// 2) mergear extensionsUsed / extensionsRequired
6351
MergeExtensionsUsedAndRequired(src, dst);
6452

65-
// 3) EMBEBER imágenes en el .bin del .gltf (usar SIEMPRE el bin TEMP) y BORRAR archivos externos
6653
string baseDir = Path.GetDirectoryName(tempGltf);
6754
string tempBinFileName = Path.GetFileName(tempGltf).Replace(".gltf", ".bin"); // ej: MyModelTemp.bin
6855

@@ -78,7 +65,6 @@ private static void PatchExtrasGltf(string originalGltf, string tempGltf)
7865
File.WriteAllText(tempGltf, dst.ToString(Formatting.None));
7966
}
8067

81-
// --------- .glb (JSON embebido) ----------
8268
private static void PatchExtrasGlb(string originalGlb, string tempGlb)
8369
{
8470
GlbData srcGlb = ReadGlb(originalGlb);
@@ -87,63 +73,25 @@ private static void PatchExtrasGlb(string originalGlb, string tempGlb)
8773
JObject src = JObject.Parse(srcGlb.Json);
8874
JObject dst = JObject.Parse(dstGlb.Json);
8975

90-
// 1) copiar EXTRAS + extensiones desconocidas en NODES
9176
PatchArrayByIndex(src, dst, "nodes", PatchNodeLike);
9277

93-
// (Opcional) meshes/primitives:
94-
// PatchMeshesAndPrimitives(src, dst);
9578

96-
// 2) mergear extensionsUsed/Required
9779
MergeExtensionsUsedAndRequired(src, dst);
9880

99-
// 3) EMBEBER imágenes en el BIN del GLB si por algún motivo vinieran por uri
10081
byte[] glbBin = dstGlb.Bin;
10182
string baseDir = Path.GetDirectoryName(tempGlb);
10283
InlineExternalImagesIntoBin_JObject(dst, baseDir, null, ref glbBin, true, true);
10384

10485
string newJson = dst.ToString(Formatting.None);
105-
WriteGlb(tempGlb, newJson, glbBin); // re-escribe GLB con JSON parcheado
86+
WriteGlb(tempGlb, newJson, glbBin);
10687
}
10788

108-
// ---------- LÓGICA DE PARCHE ----------
10989
private static void PatchNodeLike(JObject srcNode, JObject dstNode)
11090
{
11191
CopyExtras(srcNode, dstNode);
11292
CopyUnknownExtensions(srcNode, dstNode, new[] { "KHR_draco_mesh_compression" });
11393
}
11494

115-
private static void PatchMeshesAndPrimitives(JObject src, JObject dst)
116-
{
117-
JArray srcMeshes = src["meshes"] as JArray;
118-
JArray dstMeshes = dst["meshes"] as JArray;
119-
if (srcMeshes == null || dstMeshes == null) return;
120-
121-
int count = Math.Min(srcMeshes.Count, dstMeshes.Count);
122-
for (int i = 0; i < count; i++)
123-
{
124-
JObject s = (JObject)srcMeshes[i];
125-
JObject d = (JObject)dstMeshes[i];
126-
127-
CopyExtras(s, d);
128-
CopyUnknownExtensions(s, d, new[] { "KHR_draco_mesh_compression" });
129-
130-
JArray sPrims = s["primitives"] as JArray;
131-
JArray dPrims = d["primitives"] as JArray;
132-
if (sPrims == null || dPrims == null) continue;
133-
134-
int pc = Math.Min(sPrims.Count, dPrims.Count);
135-
for (int j = 0; j < pc; j++)
136-
{
137-
JObject sp = (JObject)sPrims[j];
138-
JObject dp = (JObject)dPrims[j];
139-
140-
// NO tocar KHR_draco_mesh_compression del temp
141-
CopyExtras(sp, dp);
142-
CopyUnknownExtensions(sp, dp, new[] { "KHR_draco_mesh_compression" });
143-
}
144-
}
145-
}
146-
14795
private static void PatchArrayByIndex(JObject src, JObject dst, string name, Action<JObject, JObject> patchItem)
14896
{
14997
JArray sa = src[name] as JArray;
@@ -159,7 +107,6 @@ private static void CopyExtras(JObject src, JObject dst)
159107
{
160108
if (src["extras"] != null)
161109
dst["extras"] = src["extras"].DeepClone();
162-
// si src no tiene extras, no tocamos los del dst
163110
}
164111

165112
private static void CopyUnknownExtensions(JObject src, JObject dst, IEnumerable<string> keepKnown)
@@ -174,7 +121,6 @@ private static void CopyUnknownExtensions(JObject src, JObject dst, IEnumerable<
174121

175122
foreach (JProperty prop in sExt.Properties())
176123
{
177-
// no sobreescribir Draco si ya está en el destino
178124
if (known.Contains(prop.Name) && dExt[prop.Name] != null) continue;
179125

180126
dExt[prop.Name] = prop.Value.DeepClone();
@@ -186,7 +132,6 @@ private static void CopyUnknownExtensions(JObject src, JObject dst, IEnumerable<
186132

187133
private static void MergeExtensionsUsedAndRequired(JObject src, JObject dst)
188134
{
189-
// merge extensionsUsed
190135
JArray srcUsed = src["extensionsUsed"] as JArray;
191136
if (srcUsed != null && srcUsed.Count > 0)
192137
{
@@ -203,7 +148,6 @@ private static void MergeExtensionsUsedAndRequired(JObject src, JObject dst)
203148
}
204149
}
205150

206-
// merge extensionsRequired (opcional pero recomendable)
207151
JArray srcReq = src["extensionsRequired"] as JArray;
208152
if (srcReq != null && srcReq.Count > 0)
209153
{
@@ -232,9 +176,6 @@ private static void EnsureExtInArray(JObject dst, string arrayName, string ext)
232176
arr.Add(ext);
233177
}
234178

235-
// ====== INLINE DE IMÁGENES EN BIN / GLB ======
236-
// desiredBinFileName: nombre del BIN *TEMP* para .gltf (ej. "MyModelTemp.bin").
237-
// removeExternalImageFiles: si true, borra los .png/.jpg que se incrustaron.
238179
private static void InlineExternalImagesIntoBin_JObject(
239180
JObject model,
240181
string baseDir,
@@ -254,7 +195,6 @@ private static void InlineExternalImagesIntoBin_JObject(
254195

255196
if (!isGlb)
256197
{
257-
// Fuerza a usar SIEMPRE el bin TEMP (que luego renombrás)
258198
if (string.IsNullOrEmpty(desiredBinFileName)) desiredBinFileName = "sceneTemp.bin";
259199
buf0["uri"] = desiredBinFileName;
260200

@@ -353,7 +293,6 @@ private static byte[] AppendBytes(byte[] bin, byte[] add, bool padTo4, byte padB
353293
return outArr;
354294
}
355295

356-
// ------------- GLB IO mínimo: JSON chunk + BIN chunk -------------
357296
private static GlbData ReadGlb(string path)
358297
{
359298
using (FileStream fs = File.OpenRead(path))
@@ -432,10 +371,6 @@ private static byte[] PadTo4(byte[] data, byte padByte)
432371
return outArr;
433372
}
434373
}
435-
436-
// ------------------------------------------------------------
437-
// Tu compresor Draco con llamada al patch antes del cleanup
438-
// ------------------------------------------------------------
439374
public static class Draco
440375
{
441376
public static void Compress(Preferences preferences)
@@ -460,7 +395,6 @@ public static void Compress(Preferences preferences)
460395
}
461396

462397
#if REVIT2025 || REVIT2026
463-
// En .NET Framework se compila el #else; este bloque queda para tus builds nuevos
464398
var loadContext = new NonCollectibleAssemblyLoadContext();
465399
string programDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
466400
string assemblyPath = Path.Combine(programDataPath, "Autodesk", "ApplicationPlugins", "leia.bundle", "Contents", "2025", "DracoWrapper.dll");
@@ -496,10 +430,8 @@ public static void Compress(Preferences preferences)
496430
encoder.EncodeSceneToFile(scene, fileToCompressTemp);
497431
#endif
498432

499-
// --- Parchea EXTRAS de NODES + mergea extensiones + EMBEBE imágenes (y borra las externas) ---
500433
GltfExtrasPatcher.PatchExtras(fileToCompress, fileToCompressTemp);
501434

502-
// --- Cleanup / rename final ---
503435
foreach (var x in files)
504436
{
505437
try { if (File.Exists(x)) File.Delete(x); } catch { /* ignore */ }
@@ -508,15 +440,15 @@ public static void Compress(Preferences preferences)
508440

509441
if (preferences.format == FormatEnum.gltf)
510442
{
511-
string binTemp = fileToCompressTemp.Replace(".gltf", ".bin"); // ej: MyModelTemp.bin
512-
string binFinal = fileToCompressTemp.Replace("Temp.gltf", ".bin"); // ej: MyModel.bin
443+
string binTemp = fileToCompressTemp.Replace(".gltf", ".bin");
444+
string binFinal = fileToCompressTemp.Replace("Temp.gltf", ".bin");
513445

514446
if (File.Exists(binTemp))
515447
{
516448
File_MoveOverwrite(binTemp, binFinal);
517449
}
518450

519-
// Corrige nombre del .bin referenciado en el JSON final (Temp → final)
451+
520452
if (File.Exists(fileToCompress))
521453
{
522454
string text = File.ReadAllText(fileToCompress);
@@ -531,7 +463,7 @@ public static void Compress(Preferences preferences)
531463
}
532464
}
533465

534-
// Helper .NET Framework: mover reemplazando si existe
466+
535467
private static void File_MoveOverwrite(string src, string dst)
536468
{
537469
if (File.Exists(dst))

0 commit comments

Comments
 (0)