icon预览和自动生成

This commit is contained in:
Bob.Song
2025-10-28 17:46:08 +08:00
parent af4dbc5cde
commit 7b8c6d5cec
204 changed files with 8454 additions and 174 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using Newtonsoft.Json;
using UnityEngine;
using Color = UnityEngine.Color;
@@ -9,17 +10,12 @@ namespace NBF
[Serializable]
public class ModelViewerSettings
{
//Object Settings
//物体设置
public Vector3 objectPosition;
public Vector3 objectRotation;
public Vector3 objectScale;
//Hierarchy Settings
[NonSerialized] public Dictionary<string, bool> subObjectEnables;
public List<string> soeStrings;
public List<bool> soeBools;
//Camera Settings
//摄像机设置
public Vector3 cameraPosition;
public Vector3 cameraTarget;
public bool autoPosition;
@@ -30,47 +26,42 @@ namespace NBF
public float camerasScaleFactor;
public float perspLastScale;
//Lighting Settings
//灯光设置
public Color lightColour;
public Vector3 lightDir;
public float lightIntensity;
public Color ambientLightColour;
//Animation Settings
public AnimationClip animationClip;
public float animationOffset;
public string animationPath;
//Post-Processing Settings
public List<Material> postProcessingMaterials;
public Dictionary<Material, String> materialDisplayNames;
public Dictionary<Material, bool> materialToggles;
public enum FixEdgesModes
public static ModelViewerSettings Load(uint id)
{
None,
Regular,
WithDepthTexture
};
public FixEdgesModes fixEdgesMode;
public FilterMode filterMode;
var configAsset = Resources.Load<TextAsset>($"config/Viewer/{id}");
if (configAsset != null)
{
return JsonConvert.DeserializeObject<ModelViewerSettings>(configAsset.text);
}
return null;
}
public ModelViewerSettings()
{
//Do nothing
//---Initialise Icon---//
//Object Settings
SetDefValues();
}
public ModelViewerSettings(Shader objRenderShader, string rapidIconRootFolder, GameObject rootObject)
{
SetDefValues();
}
private void SetDefValues()
{
objectPosition = Vector3.zero;
objectRotation = Vector3.zero;
objectScale = Vector3.one;
autoPosition = true;
//Hierarchy Settings
subObjectEnables = new Dictionary<string, bool>();
//Camera Settings
cameraPosition = new Vector3(1, Mathf.Sqrt(2), 1);
perspLastScale = 1;
cameraOrtho = false;
@@ -80,69 +71,10 @@ namespace NBF
cameraTarget = Vector3.zero;
autoScale = true;
//Lighting Settings
ambientLightColour = Color.gray;
lightColour = Color.white;
lightDir = new Vector3(50, -30, 0);
lightIntensity = 1;
//Post-Processing Settings
postProcessingMaterials = new List<Material>();
materialDisplayNames = new Dictionary<Material, string>();
materialToggles = new Dictionary<Material, bool>();
filterMode = FilterMode.Point;
fixEdgesMode = FixEdgesModes.Regular;
}
public ModelViewerSettings(Shader objRenderShader, string rapidIconRootFolder, GameObject rootObject)
{
//---Initialise Icon---//
//Object Settings
objectPosition = Vector3.zero;
objectRotation = Vector3.zero;
objectScale = Vector3.one;
autoPosition = true;
//Hierarchy Settings
subObjectEnables = new Dictionary<string, bool>();
//Camera Settings
cameraPosition = new Vector3(1, Mathf.Sqrt(2), 1);
perspLastScale = 1;
cameraOrtho = true;
cameraFov = 60;
cameraSize = 5;
camerasScaleFactor = 1;
cameraTarget = Vector3.zero;
autoScale = true;
//Lighting Settings
ambientLightColour = Color.gray;
lightColour = Color.white;
lightDir = new Vector3(50, -30, 0);
lightIntensity = 1;
//Post-Processing Settings
postProcessingMaterials = new List<Material>();
materialDisplayNames = new Dictionary<Material, string>();
materialToggles = new Dictionary<Material, bool>();
filterMode = FilterMode.Point;
fixEdgesMode = FixEdgesModes.Regular;
// Material defaultRender = new Material(objRenderShader);
// postProcessingMaterials.Add(defaultRender);
// materialDisplayNames.Add(defaultRender, "Object Render");
// materialToggles.Add(defaultRender, true);
}
void SetSubObjectEnables(GameObject obj, int childIdx, string lastPath)
{
string path = lastPath + "/" + childIdx;
subObjectEnables.Add(path, true);
for (int i = 0; i < obj.transform.childCount; i++)
{
SetSubObjectEnables(obj.transform.GetChild(i).gameObject, i, path);
}
}
}
}