- UI SFX v3: procedurally synthesized one-shots (Tools/synth_ui_sfx.py) wired to buttons, rewards, errors and red dots via UiSfx, gated by the SFX setting. - Five formal enemies (Hornlet, Dashlet, Shellhorn, HornCaptain, GreatHorn): Hunyuan 50k -> 2000-tri XPbr, DGXA TokenRig, Idle/Walk/Attack, nested per type in PrototypeArena; PrototypeBattle.Enemy gains presentation-only Moving/Strikes. - Formal partners for all ten pets in the arena and portraits, including new VineSprite, ThunderLeopard and TideWhale. - Pipeline fixes: reject local TokenRig fallback, drop loose mesh islands, configurable Unity run_script timeout, companion static stage. - Also includes concurrent work from another tool in this working tree (FlameLion, enemy combat FX, challenge mode, home explorer, server updates). - Resources registered in Doc/ResDesc_*.md; verified on isolated :18081. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
79 lines
5.3 KiB
C#
79 lines
5.3 KiB
C#
#if UNITY_EDITOR
|
|
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using Object=UnityEngine.Object;
|
|
|
|
/// <summary>Isolated static or sampled-pose views; preserves all open scene contents.</summary>
|
|
public static class AuditCharacterVisual
|
|
{
|
|
public static string Capture(string prefabPath,string outputDirectory,float height=.55f,string clipPath="",float phase=0)
|
|
{
|
|
string dir=Path.GetFullPath(Path.Combine(Application.dataPath,"../..",outputDirectory));Directory.CreateDirectory(dir);
|
|
var scene=EditorSceneManager.NewPreviewScene();
|
|
try
|
|
{
|
|
var prefab=AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
|
|
if(prefab==null)throw new Exception("Missing visual prefab: "+prefabPath);
|
|
var unit=(GameObject)PrefabUtility.InstantiatePrefab(prefab,scene);
|
|
var animator=unit.GetComponentInChildren<Animator>();if(animator!=null)animator.enabled=false;
|
|
if(animator==null)
|
|
{
|
|
var filters=unit.GetComponentsInChildren<MeshFilter>();
|
|
var points=filters.SelectMany(m=>m.sharedMesh.vertices.Select(v=>m.transform.TransformPoint(v))).ToArray();
|
|
if(points.Length==0)throw new Exception("No static geometry");
|
|
float minY=points.Min(v=>v.y),actualHeight=points.Max(v=>v.y)-minY;
|
|
int triangles=filters.Sum(m=>m.sharedMesh.triangles.Length/3);
|
|
if(Mathf.Abs(minY)>.002f || Mathf.Abs(actualHeight-height)>.002f)throw new Exception("Static height/bottom invalid");
|
|
if(unit.GetComponentsInChildren<Renderer>().Any(r=>r.sharedMaterial==null || r.sharedMaterial.shader.name!="Test/XPbr"))throw new Exception("Static XPbr material missing");
|
|
File.WriteAllText(Path.Combine(dir,"static_verification.txt"),$"height={actualHeight:F6} bottom={minY:F6} triangles={triangles} XPbr=True; facing verified in front/side/back views");
|
|
}
|
|
if(!string.IsNullOrEmpty(clipPath))
|
|
{
|
|
var clip=AssetDatabase.LoadAssetAtPath<AnimationClip>(clipPath);
|
|
if(clip==null || animator==null)throw new Exception("Missing clip/animator");
|
|
clip.SampleAnimation(animator.gameObject,clip.length*phase);
|
|
}
|
|
var light=new GameObject("AuditLight").AddComponent<Light>();SceneManager.MoveGameObjectToScene(light.gameObject,scene);
|
|
light.type=LightType.Directional;light.intensity=1.4f;light.transform.rotation=Quaternion.Euler(40,-30,0);
|
|
var camera=new GameObject("AuditCamera").AddComponent<Camera>();SceneManager.MoveGameObjectToScene(camera.gameObject,scene);camera.scene=scene;
|
|
camera.clearFlags=CameraClearFlags.SolidColor;camera.backgroundColor=new Color(.56f,.64f,.7f);
|
|
camera.orthographic=true;camera.orthographicSize=height*.68f;camera.nearClipPlane=.01f;camera.farClipPlane=10;
|
|
var visualPoints=unit.GetComponentsInChildren<MeshFilter>().SelectMany(m=>m.sharedMesh.vertices.Select(v=>m.transform.TransformPoint(v))).ToList();
|
|
foreach(var skin in unit.GetComponentsInChildren<SkinnedMeshRenderer>())
|
|
{
|
|
var mesh=skin.sharedMesh;var weights=mesh.boneWeights;
|
|
var matrices=skin.bones.Select((b,i)=>b.localToWorldMatrix*mesh.bindposes[i]).ToArray();
|
|
visualPoints.AddRange(mesh.vertices.Select((v,i)=> {
|
|
var w=weights[i];return matrices[w.boneIndex0].MultiplyPoint3x4(v)*w.weight0+matrices[w.boneIndex1].MultiplyPoint3x4(v)*w.weight1+
|
|
matrices[w.boneIndex2].MultiplyPoint3x4(v)*w.weight2+matrices[w.boneIndex3].MultiplyPoint3x4(v)*w.weight3;
|
|
}));
|
|
}
|
|
var bounds=new Bounds(visualPoints[0],Vector3.zero);foreach(var p in visualPoints)bounds.Encapsulate(p);
|
|
var rt=new RenderTexture(640,640,24);var tex=new Texture2D(640,640,TextureFormat.RGB24,false);var previous=RenderTexture.active;
|
|
try
|
|
{
|
|
var directions=new[]{new Vector3(0,.22f,-1),new Vector3(1,.22f,0),new Vector3(0,.22f,1),new Vector3(.7f,.3f,-1)};
|
|
string[] names={"front","side","back","perspective"};
|
|
for(int i=0;i<directions.Length;i++)
|
|
{
|
|
var center=bounds.center;camera.transform.position=center+directions[i]*Mathf.Max(height,bounds.size.magnitude)*3;
|
|
camera.transform.LookAt(center);camera.targetTexture=rt;
|
|
// Broad quadrupeds must fit horizontally as well as vertically.
|
|
camera.orthographicSize=1.15f*Mathf.Max(visualPoints.Max(p=>Mathf.Abs(Vector3.Dot(p-center,camera.transform.right))),visualPoints.Max(p=>Mathf.Abs(Vector3.Dot(p-center,camera.transform.up))));
|
|
camera.Render();RenderTexture.active=rt;
|
|
tex.ReadPixels(new Rect(0,0,640,640),0,0);tex.Apply();File.WriteAllBytes(Path.Combine(dir,names[i]+".png"),tex.EncodeToPNG());
|
|
}
|
|
}
|
|
finally {RenderTexture.active=previous;camera.targetTexture=null;rt.Release();Object.DestroyImmediate(rt);Object.DestroyImmediate(tex);}
|
|
}
|
|
finally {EditorSceneManager.ClosePreviewScene(scene);}
|
|
return dir;
|
|
}
|
|
}
|
|
#endif
|