mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-24 11:57:21 -05:00
Export 時の自動判定を実装
* Unlit & multiply 設定 => VColor を エクスポートする * それ以外 VColor をエクスポートしない
This commit is contained in:
parent
74335d9540
commit
dbe302d53c
|
|
@ -64,14 +64,10 @@ namespace UniGLTF
|
|||
// MorphTarget を Position だけにする(normal とか捨てる)
|
||||
public bool ExportOnlyBlendShapePosition;
|
||||
|
||||
// VertexColor が存在していても捨てる
|
||||
public bool RemoveVertexColor;
|
||||
|
||||
public static MeshExportSettings Default => new MeshExportSettings
|
||||
{
|
||||
UseSparseAccessorForMorphTarget = false,
|
||||
ExportOnlyBlendShapePosition = false,
|
||||
RemoveVertexColor = false,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -80,8 +76,7 @@ namespace UniGLTF
|
|||
static glTFMesh ExportPrimitives(glTF gltf, int bufferIndex,
|
||||
string rendererName,
|
||||
Mesh mesh, Material[] materials,
|
||||
List<Material> unityMaterials,
|
||||
bool removeVertexColor)
|
||||
List<Material> unityMaterials)
|
||||
{
|
||||
var positions = mesh.vertices.Select(y => y.ReverseZ()).ToArray();
|
||||
var positionAccessorIndex = gltf.ExtendBufferAndGetAccessorIndex(bufferIndex, positions, glBufferTarget.ARRAY_BUFFER);
|
||||
|
|
@ -95,8 +90,16 @@ namespace UniGLTF
|
|||
var uvAccessorIndex = gltf.ExtendBufferAndGetAccessorIndex(bufferIndex, mesh.uv.Select(y => y.ReverseUV()).ToArray(), glBufferTarget.ARRAY_BUFFER);
|
||||
|
||||
var colorAccessorIndex = -1;
|
||||
if (!removeVertexColor)
|
||||
colorAccessorIndex = gltf.ExtendBufferAndGetAccessorIndex(bufferIndex, mesh.colors, glBufferTarget.ARRAY_BUFFER);
|
||||
if (mesh.colors != null && mesh.colors.Length == mesh.vertexCount)
|
||||
{
|
||||
// この Mesh が 頂点カラーを保持していて
|
||||
if (materials.Any(x => x.shader.name == UniGLTF.UniUnlit.Utils.ShaderName
|
||||
&& UniGLTF.UniUnlit.Utils.GetVColBlendMode(x) == UniUnlit.UniUnlitVertexColorBlendOp.Multiply))
|
||||
{
|
||||
// UniUnlit で Multiply 設定になっている
|
||||
colorAccessorIndex = gltf.ExtendBufferAndGetAccessorIndex(bufferIndex, mesh.colors, glBufferTarget.ARRAY_BUFFER);
|
||||
}
|
||||
}
|
||||
|
||||
var boneweights = mesh.boneWeights;
|
||||
var weightAccessorIndex = gltf.ExtendBufferAndGetAccessorIndex(bufferIndex, boneweights.Select(y => new Vector4(y.weight0, y.weight1, y.weight2, y.weight3)).ToArray(), glBufferTarget.ARRAY_BUFFER);
|
||||
|
|
@ -306,7 +309,7 @@ namespace UniGLTF
|
|||
|
||||
var gltfMesh = ExportPrimitives(gltf, bufferIndex,
|
||||
x.Renderer.name,
|
||||
mesh, materials, unityMaterials, settings.RemoveVertexColor);
|
||||
mesh, materials, unityMaterials);
|
||||
|
||||
var blendShapeIndexMap = new Dictionary<int, int>();
|
||||
int exportBlendShapes = 0;
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@ namespace VRM
|
|||
/// </summary>
|
||||
/// <param name="path">出力先</param>
|
||||
/// <param name="settings">エクスポート設定</param>
|
||||
public static void Export(string path, GameObject exportRoot, VRMMetaObject meta, VRMExportSettings settings)
|
||||
public static void Export(string path, GameObject exportRoot, VRMMetaObject meta, VRMExportSettings settings, IReadOnlyList<MeshExportInfo> info)
|
||||
{
|
||||
List<GameObject> destroy = new List<GameObject>();
|
||||
try
|
||||
{
|
||||
Export(path, exportRoot, meta, settings, destroy);
|
||||
Export(path, exportRoot, meta, settings, info, destroy);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
@ -136,7 +136,9 @@ namespace VRM
|
|||
/// <param name="path"></param>
|
||||
/// <param name="settings"></param>
|
||||
/// <param name="destroy">作業が終わったらDestoryするべき一時オブジェクト</param>
|
||||
static void Export(string path, GameObject exportRoot, VRMMetaObject meta, VRMExportSettings settings, List<GameObject> destroy)
|
||||
static void Export(string path, GameObject exportRoot, VRMMetaObject meta,
|
||||
VRMExportSettings settings, IReadOnlyList<UniGLTF.MeshExportInfo> info,
|
||||
List<GameObject> destroy)
|
||||
{
|
||||
var target = exportRoot;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VRM
|
||||
|
|
@ -42,17 +43,10 @@ namespace VRM
|
|||
[Tooltip("Remove blendShapeClip that preset is Unknown")]
|
||||
public bool ReduceBlendshapeClip = false;
|
||||
|
||||
/// <summary>
|
||||
/// 頂点カラーを削除する
|
||||
/// </summary>
|
||||
[Tooltip("Remove vertex color")]
|
||||
public bool RemoveVertexColor = false;
|
||||
|
||||
public UniGLTF.MeshExportSettings MeshExportSettings => new UniGLTF.MeshExportSettings
|
||||
{
|
||||
UseSparseAccessorForMorphTarget = UseSparseAccessor,
|
||||
ExportOnlyBlendShapePosition = OnlyBlendshapePosition,
|
||||
RemoveVertexColor = RemoveVertexColor,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,19 +78,12 @@ namespace VRM
|
|||
[Tooltip("Remove blendShapeClip that preset is Unknown")]
|
||||
public bool ReduceBlendshapeClip = false;
|
||||
|
||||
/// <summary>
|
||||
/// 頂点カラーを削除する
|
||||
/// </summary>
|
||||
[Tooltip("Remove vertex color")]
|
||||
public bool RemoveVertexColor = false;
|
||||
|
||||
CheckBoxProp m_forceTPose;
|
||||
CheckBoxProp m_poseFreeze;
|
||||
CheckBoxProp m_useSparseAccessor;
|
||||
CheckBoxProp m_onlyBlendShapePosition;
|
||||
CheckBoxProp m_reduceBlendShape;
|
||||
CheckBoxProp m_reduceBlendShapeClip;
|
||||
CheckBoxProp m_removeVertexColor;
|
||||
|
||||
static string Msg(Options key)
|
||||
{
|
||||
|
|
@ -140,7 +133,6 @@ namespace VRM
|
|||
m_onlyBlendShapePosition = new CheckBoxProp(serializedObject.FindProperty(nameof(OnlyBlendshapePosition)), Options.BLENDSHAPE_EXCLUDE_NORMAL_AND_TANGENT);
|
||||
m_reduceBlendShape = new CheckBoxProp(serializedObject.FindProperty(nameof(ReduceBlendshape)), Options.BLENDSHAPE_ONLY_CLIP_USE);
|
||||
m_reduceBlendShapeClip = new CheckBoxProp(serializedObject.FindProperty(nameof(ReduceBlendshapeClip)), Options.BLENDSHAPE_EXCLUDE_UNKNOWN);
|
||||
m_removeVertexColor = new CheckBoxProp(serializedObject.FindProperty(nameof(RemoveVertexColor)), Options.REMOVE_VERTEX_COLOR);
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
|
|
@ -153,7 +145,6 @@ namespace VRM
|
|||
m_onlyBlendShapePosition.Draw();
|
||||
m_reduceBlendShape.Draw();
|
||||
m_reduceBlendShapeClip.Draw();
|
||||
m_removeVertexColor.Draw();
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -361,7 +361,7 @@ namespace VRM
|
|||
m_lastExportDir = Path.GetDirectoryName(path).Replace("\\", "/");
|
||||
|
||||
// export
|
||||
VRMEditorExporter.Export(path, ExportRoot, Meta != null ? Meta : m_tmpMeta, m_settings);
|
||||
VRMEditorExporter.Export(path, ExportRoot, Meta != null ? Meta : m_tmpMeta, m_settings, m_meshes.Meshes);
|
||||
}
|
||||
|
||||
void OnWizardUpdate()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user