mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-07 19:38:13 -05:00
WIP vrm, material
This commit is contained in:
@@ -1,100 +0,0 @@
|
||||
using System;
|
||||
using UniGLTF;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public static class ImageAdapter
|
||||
{
|
||||
public static VrmLib.Image FromGltf(this glTFImage x, Vrm10Storage storage)
|
||||
{
|
||||
if (x.bufferView == -1)
|
||||
{
|
||||
// 外部参照?
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
var view = storage.Gltf.bufferViews[x.bufferView];
|
||||
|
||||
var buffer = storage.Gltf.buffers[view.buffer];
|
||||
|
||||
// テクスチャの用途を調べる
|
||||
var usage = default(VrmLib.ImageUsage);
|
||||
foreach (var material in storage.Gltf.materials)
|
||||
{
|
||||
var colorImage = GetColorImage(storage, material);
|
||||
if (colorImage == x)
|
||||
{
|
||||
usage |= VrmLib.ImageUsage.Color;
|
||||
}
|
||||
|
||||
var normalImage = GetNormalImage(storage, material);
|
||||
if (normalImage == x)
|
||||
{
|
||||
usage |= VrmLib.ImageUsage.Normal;
|
||||
}
|
||||
}
|
||||
|
||||
var memory = storage.GetBufferBytes(buffer);
|
||||
return new VrmLib.Image(x.name,
|
||||
x.mimeType,
|
||||
usage,
|
||||
memory.Slice(view.byteOffset, view.byteLength));
|
||||
}
|
||||
|
||||
static glTFImage GetTexture(Vrm10Storage storage, int index)
|
||||
{
|
||||
if (index < 0 || index >= storage.Gltf.textures.Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var texture = storage.Gltf.textures[index];
|
||||
if (texture.source < 0 || texture.source >= storage.Gltf.images.Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return storage.Gltf.images[texture.source];
|
||||
}
|
||||
|
||||
static glTFImage GetColorImage(Vrm10Storage storage, glTFMaterial m)
|
||||
{
|
||||
if (m.pbrMetallicRoughness == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (m.pbrMetallicRoughness.baseColorTexture == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (!m.pbrMetallicRoughness.baseColorTexture.index.TryGetValidIndex(storage.TextureCount, out int index))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return GetTexture(storage, index);
|
||||
}
|
||||
|
||||
static glTFImage GetNormalImage(Vrm10Storage storage, glTFMaterial m)
|
||||
{
|
||||
if (m.normalTexture == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (!m.normalTexture.index.TryGetValidIndex(storage.TextureCount, out int index))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return GetTexture(storage, index);
|
||||
}
|
||||
|
||||
public static glTFImage ToGltf(this VrmLib.Image src, Vrm10Storage storage)
|
||||
{
|
||||
var viewIndex = storage.AppendToBuffer(0, src.Bytes);
|
||||
var gltf = storage.Gltf;
|
||||
return new glTFImage
|
||||
{
|
||||
name = src.Name,
|
||||
mimeType = src.MimeType,
|
||||
bufferView = viewIndex,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d48a6bb715d0d024fa5af64bb63f695e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,131 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using VrmLib.MToon;
|
||||
using VrmLib;
|
||||
using UniGLTF;
|
||||
using UniGLTF.Extensions.VRMC_materials_mtoon;
|
||||
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public static class MToonAdapter
|
||||
{
|
||||
static (string, bool) GetRenderMode(RenderMode mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case RenderMode.Opaque: return ("OPAQUE", false);
|
||||
case RenderMode.Cutout: return ("MASK", false);
|
||||
case RenderMode.Transparent: return ("BLEND", false);
|
||||
case RenderMode.TransparentWithZWrite: return ("BLEND", true);
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static glTFMaterial MToonToGltf(this MToonMaterial mtoon, List<Texture> textures)
|
||||
{
|
||||
var material = mtoon.UnlitToGltf(textures);
|
||||
|
||||
var dst = new VRMC_materials_mtoon();
|
||||
|
||||
// Color
|
||||
material.pbrMetallicRoughness.baseColorFactor = mtoon.Definition.Color.LitColor.ToFloat4();
|
||||
if (mtoon.Definition.Color.LitMultiplyTexture != null)
|
||||
{
|
||||
material.pbrMetallicRoughness.baseColorTexture = new glTFMaterialBaseColorTextureInfo
|
||||
{
|
||||
index = mtoon.Definition.Color.LitMultiplyTexture.ToIndex(textures).Value
|
||||
};
|
||||
}
|
||||
dst.ShadeFactor = mtoon.Definition.Color.ShadeColor.ToFloat3();
|
||||
dst.ShadeMultiplyTexture = mtoon.Definition.Color.ShadeMultiplyTexture.ToIndex(textures);
|
||||
material.alphaCutoff = mtoon.Definition.Color.CutoutThresholdValue;
|
||||
|
||||
// Outline
|
||||
dst.OutlineColorMode = (UniGLTF.Extensions.VRMC_materials_mtoon.OutlineColorMode)mtoon.Definition.Outline.OutlineColorMode;
|
||||
dst.OutlineFactor = mtoon.Definition.Outline.OutlineColor.ToFloat3();
|
||||
dst.OutlineLightingMixFactor = mtoon.Definition.Outline.OutlineLightingMixValue;
|
||||
dst.OutlineScaledMaxDistanceFactor = mtoon.Definition.Outline.OutlineScaledMaxDistanceValue;
|
||||
dst.OutlineWidthMode = (UniGLTF.Extensions.VRMC_materials_mtoon.OutlineWidthMode)mtoon.Definition.Outline.OutlineWidthMode;
|
||||
dst.OutlineWidthFactor = mtoon.Definition.Outline.OutlineWidthValue;
|
||||
dst.OutlineWidthMultiplyTexture = mtoon.Definition.Outline.OutlineWidthMultiplyTexture.ToIndex(textures);
|
||||
|
||||
// Emission
|
||||
material.emissiveFactor = mtoon.Definition.Emission.EmissionColor.ToFloat3();
|
||||
if (mtoon.Definition.Emission.EmissionMultiplyTexture != null)
|
||||
{
|
||||
material.emissiveTexture = new glTFMaterialEmissiveTextureInfo
|
||||
{
|
||||
index = textures.IndexOfNullable(mtoon.Definition.Emission.EmissionMultiplyTexture.Texture).Value
|
||||
};
|
||||
}
|
||||
|
||||
// Light
|
||||
dst.GiIntensityFactor = mtoon.Definition.Lighting.LightingInfluence.GiIntensityValue;
|
||||
dst.LightColorAttenuationFactor = mtoon.Definition.Lighting.LightingInfluence.LightColorAttenuationValue;
|
||||
dst.ShadingShiftFactor = mtoon.Definition.Lighting.LitAndShadeMixing.ShadingShiftValue;
|
||||
dst.ShadingToonyFactor = mtoon.Definition.Lighting.LitAndShadeMixing.ShadingToonyValue;
|
||||
if (mtoon.Definition.Lighting.Normal.NormalTexture != null)
|
||||
{
|
||||
material.normalTexture = new glTFMaterialNormalTextureInfo
|
||||
{
|
||||
index = textures.IndexOfNullable(mtoon.Definition.Lighting.Normal.NormalTexture.Texture).Value,
|
||||
scale = mtoon.Definition.Lighting.Normal.NormalScaleValue
|
||||
};
|
||||
}
|
||||
|
||||
// matcap
|
||||
dst.AdditiveTexture = mtoon.Definition.MatCap.AdditiveTexture.ToIndex(textures);
|
||||
|
||||
// rendering
|
||||
switch (mtoon.Definition.Rendering.CullMode)
|
||||
{
|
||||
case CullMode.Back:
|
||||
material.doubleSided = false;
|
||||
break;
|
||||
|
||||
case CullMode.Off:
|
||||
material.doubleSided = true;
|
||||
break;
|
||||
|
||||
case CullMode.Front:
|
||||
// GLTF not support
|
||||
material.doubleSided = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
(material.alphaMode, dst.TransparentWithZWrite) = GetRenderMode(mtoon.Definition.Rendering.RenderMode);
|
||||
dst.RenderQueueOffsetNumber = mtoon.Definition.Rendering.RenderQueueOffsetNumber;
|
||||
|
||||
// rim
|
||||
dst.RimFactor = mtoon.Definition.Rim.RimColor.ToFloat3();
|
||||
dst.RimMultiplyTexture = mtoon.Definition.Rim.RimMultiplyTexture.ToIndex(textures);
|
||||
dst.RimLiftFactor = mtoon.Definition.Rim.RimLiftValue;
|
||||
dst.RimFresnelPowerFactor = mtoon.Definition.Rim.RimFresnelPowerValue;
|
||||
dst.RimLightingMixFactor = mtoon.Definition.Rim.RimLightingMixValue;
|
||||
|
||||
// texture option
|
||||
dst.UvAnimationMaskTexture = mtoon.Definition.TextureOption.UvAnimationMaskTexture.ToIndex(textures);
|
||||
dst.UvAnimationRotationSpeedFactor = mtoon.Definition.TextureOption.UvAnimationRotationSpeedValue;
|
||||
dst.UvAnimationScrollXSpeedFactor = mtoon.Definition.TextureOption.UvAnimationScrollXSpeedValue;
|
||||
dst.UvAnimationScrollYSpeedFactor = mtoon.Definition.TextureOption.UvAnimationScrollYSpeedValue;
|
||||
if (material.pbrMetallicRoughness.baseColorTexture != null)
|
||||
{
|
||||
var offset = mtoon.Definition.TextureOption.MainTextureLeftBottomOriginOffset;
|
||||
var scale = mtoon.Definition.TextureOption.MainTextureLeftBottomOriginScale;
|
||||
glTF_KHR_texture_transform.Serialize(
|
||||
material.pbrMetallicRoughness.baseColorTexture,
|
||||
(offset.X, offset.Y),
|
||||
(scale.X, scale.Y)
|
||||
);
|
||||
}
|
||||
|
||||
UniGLTF.Extensions.VRMC_materials_mtoon.GltfSerializer.SerializeTo(ref material.extensions, dst);
|
||||
|
||||
return material;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dfbed4ddbad0e1941862133ed8219c4c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,312 +0,0 @@
|
||||
using Color = System.Numerics.Vector4;
|
||||
using Material = UniGLTF.glTFMaterial;
|
||||
using System.Collections.Generic;
|
||||
using VrmLib;
|
||||
using VrmLib.MToon;
|
||||
using System;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public static partial class Utils
|
||||
{
|
||||
public static void ToProtobuf(this LinearColor color, Action<float> add, bool hasAlpha)
|
||||
{
|
||||
add(color.RGBA.X);
|
||||
add(color.RGBA.Y);
|
||||
add(color.RGBA.Z);
|
||||
if (hasAlpha)
|
||||
{
|
||||
add(color.RGBA.W);
|
||||
}
|
||||
}
|
||||
|
||||
// public static void SetMToonParametersToMaterial(Material material, MToonDefinition parameters, List<Texture> textures)
|
||||
// {
|
||||
// var mtoon = material.Extensions.VRMCMaterialsMtoon;
|
||||
|
||||
// {
|
||||
// var meta = parameters.Meta;
|
||||
// mtoon.Version = meta.VersionNumber.ToString();
|
||||
// }
|
||||
// // TODO:
|
||||
// // {
|
||||
// // var rendering = parameters.Rendering;
|
||||
// // ValidateBlendMode(material, rendering.RenderMode, isChangedByUser: true);
|
||||
// // ValidateCullMode(material, rendering.CullMode);
|
||||
// // ValidateRenderQueue(material, offset: rendering.RenderQueueOffsetNumber);
|
||||
// // }
|
||||
// {
|
||||
// var color = parameters.Color;
|
||||
|
||||
// // SetColor(material, MToonUtils.PropColor, color.LitColor);
|
||||
// color.LitColor.ToProtobuf(mtoon.LitFactor.Add, true);
|
||||
|
||||
// // SetTexture(material, MToonUtils.PropMainTex, color.LitMultiplyTexture, textures);
|
||||
// mtoon.LitMultiplyTexture = textures.IndexOfNullable(color.LitMultiplyTexture.Texture);
|
||||
|
||||
// // SetColor(material, MToonUtils.PropShadeColor, color.ShadeColor);
|
||||
// color.ShadeColor.ToProtobuf(mtoon.ShadeFactor.Add, false);
|
||||
|
||||
// // SetTexture(material, MToonUtils.PropShadeTexture, color.ShadeMultiplyTexture, textures);
|
||||
// mtoon.ShadeMultiplyTexture = textures.IndexOfNullable(color.ShadeMultiplyTexture.Texture);
|
||||
|
||||
// // SetValue(material, MToonUtils.PropCutoff, color.CutoutThresholdValue);
|
||||
// mtoon.CutoutThresholdFactor = color.CutoutThresholdValue;
|
||||
// }
|
||||
// {
|
||||
// var lighting = parameters.Lighting;
|
||||
// {
|
||||
// var prop = lighting.LitAndShadeMixing;
|
||||
// // SetValue(material, MToonUtils.PropShadeShift, prop.ShadingShiftValue);
|
||||
// mtoon.ShadingShiftFactor = prop.ShadingShiftValue;
|
||||
|
||||
// // SetValue(material, MToonUtils.PropShadeToony, prop.ShadingToonyValue);
|
||||
// mtoon.ShadingToonyFactor = prop.ShadingToonyValue;
|
||||
// }
|
||||
// {
|
||||
// var prop = lighting.LightingInfluence;
|
||||
// // SetValue(material, MToonUtils.PropLightColorAttenuation, prop.LightColorAttenuationValue);
|
||||
// mtoon.LightColorAttenuationFactor = prop.LightColorAttenuationValue;
|
||||
|
||||
// // SetValue(material, MToonUtils.PropIndirectLightIntensity, prop.GiIntensityValue);
|
||||
// mtoon.GiIntensityFactor = prop.GiIntensityValue;
|
||||
// }
|
||||
// {
|
||||
// var prop = lighting.Normal;
|
||||
// // SetTexture(material, MToonUtils.PropBumpMap, prop.NormalTexture, textures);
|
||||
// mtoon.NormalTexture = textures.IndexOfNullable(prop.NormalTexture.Texture);
|
||||
|
||||
// // SetValue(material, MToonUtils.PropBumpScale, prop.NormalScaleValue);
|
||||
// mtoon.NormalScaleFactor = prop.NormalScaleValue;
|
||||
// }
|
||||
// }
|
||||
// {
|
||||
// var emission = parameters.Emission;
|
||||
// // SetColor(material, MToonUtils.PropEmissionColor, emission.EmissionColor);
|
||||
// emission.EmissionColor.ToProtobuf(mtoon.EmissionFactor.Add, false);
|
||||
|
||||
// // SetTexture(material, MToonUtils.PropEmissionMap, emission.EmissionMultiplyTexture, textures);
|
||||
// mtoon.EmissionMultiplyTexture = textures.IndexOfNullable(emission.EmissionMultiplyTexture.Texture);
|
||||
// }
|
||||
// {
|
||||
// var matcap = parameters.MatCap;
|
||||
// // SetTexture(material, MToonUtils.PropSphereAdd, matcap.AdditiveTexture, textures);
|
||||
// mtoon.AdditiveTexture = textures.IndexOfNullable(matcap.AdditiveTexture.Texture);
|
||||
// }
|
||||
// {
|
||||
// var rim = parameters.Rim;
|
||||
// // SetColor(material, MToonUtils.PropRimColor, rim.RimColor);
|
||||
// rim.RimColor.ToProtobuf(mtoon.RimFactor.Add, false);
|
||||
|
||||
// // SetTexture(material, MToonUtils.PropRimTexture, rim.RimMultiplyTexture, textures);
|
||||
// mtoon.RimMultiplyTexture = textures.IndexOfNullable(rim.RimMultiplyTexture.Texture);
|
||||
|
||||
// // SetValue(material, MToonUtils.PropRimLightingMix, rim.RimLightingMixValue);
|
||||
// mtoon.RimLightingMixFactor = rim.RimLightingMixValue;
|
||||
|
||||
// // SetValue(material, MToonUtils.PropRimFresnelPower, rim.RimFresnelPowerValue);
|
||||
// mtoon.RimFresnelPowerFactor = rim.RimFresnelPowerValue;
|
||||
|
||||
// // SetValue(material, MToonUtils.PropRimLift, rim.RimLiftValue);
|
||||
// mtoon.RimLiftFactor = rim.RimLiftValue;
|
||||
// }
|
||||
// {
|
||||
// var outline = parameters.Outline;
|
||||
// // SetValue(material, MToonUtils.PropOutlineWidth, outline.OutlineWidthValue);
|
||||
// mtoon.OutlineWidthFactor = outline.OutlineWidthValue;
|
||||
|
||||
// // SetTexture(material, MToonUtils.PropOutlineWidthTexture, outline.OutlineWidthMultiplyTexture, textures);
|
||||
// mtoon.OutlineWidthMultiplyTexture = textures.IndexOfNullable(outline.OutlineWidthMultiplyTexture.Texture);
|
||||
|
||||
// // SetValue(material, MToonUtils.PropOutlineScaledMaxDistance, outline.OutlineScaledMaxDistanceValue);
|
||||
// mtoon.OutlineScaledMaxDistanceFactor = outline.OutlineScaledMaxDistanceValue;
|
||||
|
||||
// // SetColor(material, MToonUtils.PropOutlineColor, outline.OutlineColor);
|
||||
// outline.OutlineColor.ToProtobuf(mtoon.OutlineFactor.Add, false);
|
||||
|
||||
// // SetValue(material, MToonUtils.PropOutlineLightingMix, outline.OutlineLightingMixValue);
|
||||
// mtoon.OutlineLightingMixFactor = outline.OutlineLightingMixValue;
|
||||
|
||||
// // ValidateOutlineMode(material, outline.OutlineWidthMode, outline.OutlineColorMode);
|
||||
// }
|
||||
// {
|
||||
// var textureOptions = parameters.TextureOption;
|
||||
// // TODO:
|
||||
// // material.SetTextureScale(MToonUtils.PropMainTex, textureOptions.MainTextureLeftBottomOriginScale);
|
||||
// // material.SetTextureOffset(MToonUtils.PropMainTex, textureOptions.MainTextureLeftBottomOriginOffset);
|
||||
|
||||
// // material.SetTexture(MToonUtils.PropUvAnimMaskTexture, textureOptions.UvAnimationMaskTexture, textures);
|
||||
// mtoon.UvAnimationMaskTexture = textures.IndexOfNullable(textureOptions.UvAnimationMaskTexture.Texture);
|
||||
|
||||
// // material.SetFloat(MToonUtils.PropUvAnimScrollX, textureOptions.UvAnimationScrollXSpeedValue);
|
||||
// mtoon.UvAnimationScrollXSpeedFactor = textureOptions.UvAnimationScrollXSpeedValue;
|
||||
|
||||
// // material.SetFloat(MToonUtils.PropUvAnimScrollY, textureOptions.UvAnimationScrollYSpeedValue);
|
||||
// mtoon.UvAnimationScrollYSpeedFactor = textureOptions.UvAnimationScrollYSpeedValue;
|
||||
|
||||
// // material.SetFloat(MToonUtils.PropUvAnimRotation, textureOptions.UvAnimationRotationSpeedValue);
|
||||
// mtoon.UvAnimationRotationSpeedFactor = textureOptions.UvAnimationRotationSpeedValue;
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Validate properties and Set hidden properties, keywords.
|
||||
// /// if isBlendModeChangedByUser is true, renderQueue will set specified render mode's default value.
|
||||
// /// </summary>
|
||||
// /// <param name="material"></param>
|
||||
// /// <param name="isBlendModeChangedByUser"></param>
|
||||
// public static void ValidateProperties(Material material, List<Texture> textures, bool isBlendModeChangedByUser = false)
|
||||
// {
|
||||
// ValidateBlendMode(material, (RenderMode)material.GetFloat(MToonUtils.PropBlendMode), isBlendModeChangedByUser);
|
||||
// ValidateNormalMode(material, material.GetTexture(MToonUtils.PropBumpMap, textures) != null);
|
||||
// ValidateOutlineMode(material,
|
||||
// (OutlineWidthMode)material.GetFloat(MToonUtils.PropOutlineWidthMode),
|
||||
// (OutlineColorMode)material.GetFloat(MToonUtils.PropOutlineColorMode));
|
||||
// ValidateDebugMode(material, (DebugMode)material.GetFloat(MToonUtils.PropDebugMode));
|
||||
// ValidateCullMode(material, (CullMode)material.GetFloat(MToonUtils.PropCullMode));
|
||||
|
||||
// var mainTex = material.GetTexture(MToonUtils.PropMainTex, textures);
|
||||
// var shadeTex = material.GetTexture(MToonUtils.PropShadeTexture, textures);
|
||||
// if (mainTex != null && shadeTex == null)
|
||||
// {
|
||||
// material.SetTexture(MToonUtils.PropShadeTexture, mainTex, textures);
|
||||
// }
|
||||
// }
|
||||
|
||||
// private static void ValidateDebugMode(Material material, DebugMode debugMode)
|
||||
// {
|
||||
// switch (debugMode)
|
||||
// {
|
||||
// case DebugMode.None:
|
||||
// SetKeyword(material, MToonUtils.KeyDebugNormal, false);
|
||||
// SetKeyword(material, MToonUtils.KeyDebugLitShadeRate, false);
|
||||
// break;
|
||||
// case DebugMode.Normal:
|
||||
// SetKeyword(material, MToonUtils.KeyDebugNormal, true);
|
||||
// SetKeyword(material, MToonUtils.KeyDebugLitShadeRate, false);
|
||||
// break;
|
||||
// case DebugMode.LitShadeRate:
|
||||
// SetKeyword(material, MToonUtils.KeyDebugNormal, false);
|
||||
// SetKeyword(material, MToonUtils.KeyDebugLitShadeRate, true);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// public static void ValidateBlendMode(Material material, RenderMode renderMode, bool isChangedByUser)
|
||||
// {
|
||||
// switch (renderMode)
|
||||
// {
|
||||
// case RenderMode.Opaque:
|
||||
// material.SetOverrideTag(MToonUtils.TagRenderTypeKey, MToonUtils.TagRenderTypeValueOpaque);
|
||||
// material.SetInt(MToonUtils.PropSrcBlend, BlendMode.One);
|
||||
// material.SetInt(MToonUtils.PropDstBlend, BlendMode.Zero);
|
||||
// material.SetInt(MToonUtils.PropZWrite, MToonUtils.EnabledIntValue);
|
||||
// material.SetInt(MToonUtils.PropAlphaToMask, MToonUtils.DisabledIntValue);
|
||||
// SetKeyword(material, MToonUtils.KeyAlphaTestOn, false);
|
||||
// SetKeyword(material, MToonUtils.KeyAlphaBlendOn, false);
|
||||
// SetKeyword(material, MToonUtils.KeyAlphaPremultiplyOn, false);
|
||||
// break;
|
||||
// case RenderMode.Cutout:
|
||||
// material.SetOverrideTag(MToonUtils.TagRenderTypeKey, MToonUtils.TagRenderTypeValueTransparentCutout);
|
||||
// material.SetInt(MToonUtils.PropSrcBlend, BlendMode.One);
|
||||
// material.SetInt(MToonUtils.PropDstBlend, BlendMode.Zero);
|
||||
// material.SetInt(MToonUtils.PropZWrite, MToonUtils.EnabledIntValue);
|
||||
// material.SetInt(MToonUtils.PropAlphaToMask, MToonUtils.EnabledIntValue);
|
||||
// SetKeyword(material, MToonUtils.KeyAlphaTestOn, true);
|
||||
// SetKeyword(material, MToonUtils.KeyAlphaBlendOn, false);
|
||||
// SetKeyword(material, MToonUtils.KeyAlphaPremultiplyOn, false);
|
||||
// break;
|
||||
// case RenderMode.Transparent:
|
||||
// material.SetOverrideTag(MToonUtils.TagRenderTypeKey, MToonUtils.TagRenderTypeValueTransparent);
|
||||
// material.SetInt(MToonUtils.PropSrcBlend, BlendMode.SrcAlpha);
|
||||
// material.SetInt(MToonUtils.PropDstBlend, BlendMode.OneMinusSrcAlpha);
|
||||
// material.SetInt(MToonUtils.PropZWrite, MToonUtils.DisabledIntValue);
|
||||
// material.SetInt(MToonUtils.PropAlphaToMask, MToonUtils.DisabledIntValue);
|
||||
// SetKeyword(material, MToonUtils.KeyAlphaTestOn, false);
|
||||
// SetKeyword(material, MToonUtils.KeyAlphaBlendOn, true);
|
||||
// SetKeyword(material, MToonUtils.KeyAlphaPremultiplyOn, false);
|
||||
// break;
|
||||
// case RenderMode.TransparentWithZWrite:
|
||||
// material.SetOverrideTag(MToonUtils.TagRenderTypeKey, MToonUtils.TagRenderTypeValueTransparent);
|
||||
// material.SetInt(MToonUtils.PropSrcBlend, BlendMode.SrcAlpha);
|
||||
// material.SetInt(MToonUtils.PropDstBlend, BlendMode.OneMinusSrcAlpha);
|
||||
// material.SetInt(MToonUtils.PropZWrite, MToonUtils.EnabledIntValue);
|
||||
// material.SetInt(MToonUtils.PropAlphaToMask, MToonUtils.DisabledIntValue);
|
||||
// SetKeyword(material, MToonUtils.KeyAlphaTestOn, false);
|
||||
// SetKeyword(material, MToonUtils.KeyAlphaBlendOn, true);
|
||||
// SetKeyword(material, MToonUtils.KeyAlphaPremultiplyOn, false);
|
||||
// break;
|
||||
// }
|
||||
|
||||
// if (isChangedByUser)
|
||||
// {
|
||||
// // ValidateRenderQueue(material, offset: 0);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var requirement = MToonUtils.GetRenderQueueRequirement(renderMode);
|
||||
// // ValidateRenderQueue(material, offset: material.renderQueue - requirement.DefaultValue);
|
||||
// }
|
||||
// }
|
||||
|
||||
// private static void ValidateRenderQueue(Material material, int offset)
|
||||
// {
|
||||
// var requirement = MToonUtils.GetRenderQueueRequirement(GetBlendMode(material));
|
||||
// var value = Mathf.Clamp(requirement.DefaultValue + offset, requirement.MinValue, requirement.MaxValue);
|
||||
// material.renderQueue = value;
|
||||
// }
|
||||
|
||||
// private static void ValidateOutlineMode(Material material, OutlineWidthMode outlineWidthMode,
|
||||
// OutlineColorMode outlineColorMode)
|
||||
// {
|
||||
// var isFixed = outlineColorMode == OutlineColorMode.FixedColor;
|
||||
// var isMixed = outlineColorMode == OutlineColorMode.MixedLighting;
|
||||
|
||||
// switch (outlineWidthMode)
|
||||
// {
|
||||
// case OutlineWidthMode.None:
|
||||
// SetKeyword(material, MToonUtils.KeyOutlineWidthWorld, false);
|
||||
// SetKeyword(material, MToonUtils.KeyOutlineWidthScreen, false);
|
||||
// SetKeyword(material, MToonUtils.KeyOutlineColorFixed, false);
|
||||
// SetKeyword(material, MToonUtils.KeyOutlineColorMixed, false);
|
||||
// break;
|
||||
// case OutlineWidthMode.WorldCoordinates:
|
||||
// SetKeyword(material, MToonUtils.KeyOutlineWidthWorld, true);
|
||||
// SetKeyword(material, MToonUtils.KeyOutlineWidthScreen, false);
|
||||
// SetKeyword(material, MToonUtils.KeyOutlineColorFixed, isFixed);
|
||||
// SetKeyword(material, MToonUtils.KeyOutlineColorMixed, isMixed);
|
||||
// break;
|
||||
// case OutlineWidthMode.ScreenCoordinates:
|
||||
// SetKeyword(material, MToonUtils.KeyOutlineWidthWorld, false);
|
||||
// SetKeyword(material, MToonUtils.KeyOutlineWidthScreen, true);
|
||||
// SetKeyword(material, MToonUtils.KeyOutlineColorFixed, isFixed);
|
||||
// SetKeyword(material, MToonUtils.KeyOutlineColorMixed, isMixed);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// private static void ValidateNormalMode(Material material, bool requireNormalMapping)
|
||||
// {
|
||||
// SetKeyword(material, MToonUtils.KeyNormalMap, requireNormalMapping);
|
||||
// }
|
||||
|
||||
// private static void ValidateCullMode(Material material, CullMode cullMode)
|
||||
// {
|
||||
// switch (cullMode)
|
||||
// {
|
||||
// case CullMode.Back:
|
||||
// material.SetInt(MToonUtils.PropCullMode, CullMode.Back);
|
||||
// material.SetInt(MToonUtils.PropOutlineCullMode, CullMode.Front);
|
||||
// break;
|
||||
// case CullMode.Front:
|
||||
// material.SetInt(MToonUtils.PropCullMode, CullMode.Front);
|
||||
// material.SetInt(MToonUtils.PropOutlineCullMode, CullMode.Back);
|
||||
// break;
|
||||
// case CullMode.Off:
|
||||
// material.SetInt(MToonUtils.PropCullMode, CullMode.Off);
|
||||
// material.SetInt(MToonUtils.PropOutlineCullMode, CullMode.Front);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 269eb140bd3b26043a6afac332268766
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,128 +0,0 @@
|
||||
using VrmLib;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using UniJSON;
|
||||
using UniGLTF;
|
||||
using System;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public static class MaterialAdapter
|
||||
{
|
||||
static string CastAlphaMode(VrmLib.AlphaModeType alphaMode)
|
||||
{
|
||||
if (alphaMode == AlphaModeType.BLEND_ZWRITE)
|
||||
{
|
||||
return "BLEND";
|
||||
}
|
||||
return alphaMode.ToString();
|
||||
}
|
||||
|
||||
static glTFMaterial ToGltf(this VrmLib.Material src, List<Texture> textures)
|
||||
{
|
||||
var material = new glTFMaterial
|
||||
{
|
||||
name = src.Name,
|
||||
pbrMetallicRoughness = new glTFPbrMetallicRoughness
|
||||
{
|
||||
baseColorFactor = src.BaseColorFactor.ToFloat4(),
|
||||
},
|
||||
alphaMode = CastAlphaMode(src.AlphaMode),
|
||||
alphaCutoff = src.AlphaCutoff,
|
||||
doubleSided = src.DoubleSided,
|
||||
};
|
||||
if (src.BaseColorTexture != null)
|
||||
{
|
||||
material.pbrMetallicRoughness.baseColorTexture = new glTFMaterialBaseColorTextureInfo
|
||||
{
|
||||
index = textures.IndexOfNullable(src.BaseColorTexture.Texture).Value,
|
||||
};
|
||||
}
|
||||
return material;
|
||||
}
|
||||
|
||||
public static glTFMaterial PBRToGltf(this PBRMaterial pbr, List<Texture> textures)
|
||||
{
|
||||
var material = pbr.ToGltf(textures);
|
||||
|
||||
// MetallicRoughness
|
||||
material.pbrMetallicRoughness.baseColorFactor = pbr.BaseColorFactor.ToFloat4();
|
||||
if (pbr.BaseColorTexture != null)
|
||||
{
|
||||
material.pbrMetallicRoughness.baseColorTexture = new glTFMaterialBaseColorTextureInfo
|
||||
{
|
||||
index = textures.IndexOfNullable(pbr.BaseColorTexture.Texture).Value,
|
||||
};
|
||||
}
|
||||
material.pbrMetallicRoughness.metallicFactor = pbr.MetallicFactor;
|
||||
material.pbrMetallicRoughness.roughnessFactor = pbr.RoughnessFactor;
|
||||
if (pbr.MetallicRoughnessTexture != null)
|
||||
{
|
||||
material.pbrMetallicRoughness.metallicRoughnessTexture = new glTFMaterialMetallicRoughnessTextureInfo
|
||||
{
|
||||
index = textures.IndexOfNullable(pbr.MetallicRoughnessTexture).Value,
|
||||
};
|
||||
}
|
||||
|
||||
// Normal
|
||||
if (pbr.NormalTexture != null)
|
||||
{
|
||||
material.normalTexture = new glTFMaterialNormalTextureInfo
|
||||
{
|
||||
index = textures.IndexOfNullable(pbr.NormalTexture).Value,
|
||||
scale = pbr.NormalTextureScale
|
||||
};
|
||||
}
|
||||
|
||||
// Occlusion
|
||||
if (pbr.OcclusionTexture != null)
|
||||
{
|
||||
material.occlusionTexture = new glTFMaterialOcclusionTextureInfo
|
||||
{
|
||||
index = textures.IndexOfNullable(pbr.OcclusionTexture).Value,
|
||||
strength = pbr.OcclusionTextureStrength,
|
||||
};
|
||||
}
|
||||
|
||||
// Emissive
|
||||
if (pbr.EmissiveTexture != null)
|
||||
{
|
||||
material.emissiveTexture = new glTFMaterialEmissiveTextureInfo
|
||||
{
|
||||
index = textures.IndexOfNullable(pbr.EmissiveTexture).Value,
|
||||
};
|
||||
}
|
||||
material.emissiveFactor = pbr.EmissiveFactor.ToFloat3();
|
||||
|
||||
// AlphaMode
|
||||
material.alphaMode = CastAlphaMode(pbr.AlphaMode);
|
||||
|
||||
// AlphaCutoff
|
||||
material.alphaCutoff = pbr.AlphaCutoff;
|
||||
|
||||
// DoubleSided
|
||||
material.doubleSided = pbr.DoubleSided;
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
public static glTFMaterial UnlitToGltf(this UnlitMaterial unlit, List<Texture> textures)
|
||||
{
|
||||
var material = unlit.ToGltf(textures);
|
||||
|
||||
if (!(material.extensions is glTFExtensionExport extensions))
|
||||
{
|
||||
extensions = new glTFExtensionExport();
|
||||
material.extensions = extensions;
|
||||
}
|
||||
extensions.Add(
|
||||
glTF_KHR_materials_unlit.ExtensionName,
|
||||
new ArraySegment<byte>(glTF_KHR_materials_unlit.Raw));
|
||||
|
||||
material.pbrMetallicRoughness.roughnessFactor = 0.9f;
|
||||
material.pbrMetallicRoughness.metallicFactor = 0.0f;
|
||||
|
||||
return material;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82c26e1eaa170df4a876714ae8e73046
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,21 +0,0 @@
|
||||
using VrmLib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UniGLTF;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public static class TextureAdapter
|
||||
{
|
||||
public static glTFTextureSampler ToGltf(this TextureSampler src)
|
||||
{
|
||||
return new glTFTextureSampler
|
||||
{
|
||||
wrapS = (glWrap)src.WrapS,
|
||||
wrapT = (glWrap)src.WrapT,
|
||||
minFilter = (glFilter)src.MinFilter,
|
||||
magFilter = (glFilter)src.MagFilter,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d307745b90c1da4297bba9f3ff4b325
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UniGLTF;
|
||||
using UniJSON;
|
||||
@@ -63,67 +62,6 @@ namespace UniVRM10
|
||||
Storage.Reserve(bytesLength);
|
||||
}
|
||||
|
||||
public void ExportImageAndTextures(List<Image> images, List<Texture> textures)
|
||||
{
|
||||
foreach (var x in images)
|
||||
{
|
||||
Storage.Gltf.images.Add(x.ToGltf(Storage));
|
||||
}
|
||||
foreach (var x in textures)
|
||||
{
|
||||
if (x is ImageTexture imageTexture)
|
||||
{
|
||||
var samplerIndex = Storage.Gltf.samplers.Count;
|
||||
Storage.Gltf.samplers.Add(x.Sampler.ToGltf());
|
||||
Storage.Gltf.textures.Add(new glTFTexture
|
||||
{
|
||||
name = x.Name,
|
||||
source = images.IndexOfThrow(imageTexture.Image),
|
||||
sampler = samplerIndex,
|
||||
// extensions
|
||||
// = imageTexture.Image.MimeType.Equals("image/webp") ? new GltfTextureExtensions() { EXT_texture_webp = new EXT_texture_webp() { source = images.IndexOf(imageTexture.Image) } }
|
||||
// : imageTexture.Image.MimeType.Equals("image/vnd-ms.dds") ? new GltfTextureExtensions() { MSFT_texture_dds = new MSFT_texture_dds() { source = images.IndexOf(imageTexture.Image) } }
|
||||
// : null
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ExportMaterialPBR(Material src, PBRMaterial pbr, List<Texture> textures)
|
||||
{
|
||||
var material = pbr.PBRToGltf(textures);
|
||||
Storage.Gltf.materials.Add(material);
|
||||
}
|
||||
|
||||
public void ExportMaterialUnlit(Material src, UnlitMaterial unlit, List<Texture> textures)
|
||||
{
|
||||
var material = unlit.UnlitToGltf(textures);
|
||||
Storage.Gltf.materials.Add(material);
|
||||
if (!Storage.Gltf.extensionsUsed.Contains(UnlitMaterial.ExtensionName))
|
||||
{
|
||||
Storage.Gltf.extensionsUsed.Add(UnlitMaterial.ExtensionName);
|
||||
}
|
||||
}
|
||||
|
||||
public void ExportMaterialMToon(Material src, MToonMaterial mtoon, List<Texture> textures)
|
||||
{
|
||||
if (!Storage.Gltf.extensionsUsed.Contains(UnlitMaterial.ExtensionName))
|
||||
{
|
||||
Storage.Gltf.extensionsUsed.Add(UnlitMaterial.ExtensionName);
|
||||
}
|
||||
|
||||
var material = mtoon.MToonToGltf(textures);
|
||||
Storage.Gltf.materials.Add(material);
|
||||
if (!Storage.Gltf.extensionsUsed.Contains(MToonMaterial.ExtensionName))
|
||||
{
|
||||
Storage.Gltf.extensionsUsed.Add(MToonMaterial.ExtensionName);
|
||||
}
|
||||
}
|
||||
|
||||
public void ExportMeshes(List<MeshGroup> groups, List<Material> materials, ExportArgs option)
|
||||
{
|
||||
foreach (var group in groups)
|
||||
|
||||
@@ -44,29 +44,6 @@ namespace UniVRM10
|
||||
exporter.Reserve(reserveBytes);
|
||||
}
|
||||
|
||||
exporter.ExportImageAndTextures(m.Images, m.Textures);
|
||||
|
||||
// material
|
||||
foreach (var src in m.Materials)
|
||||
{
|
||||
if (src is MToonMaterial mtoon)
|
||||
{
|
||||
exporter.ExportMaterialMToon(src, mtoon, m.Textures);
|
||||
}
|
||||
else if (src is UnlitMaterial unlit)
|
||||
{
|
||||
exporter.ExportMaterialUnlit(src, unlit, m.Textures);
|
||||
}
|
||||
else if (src is PBRMaterial pbr)
|
||||
{
|
||||
exporter.ExportMaterialPBR(src, pbr, m.Textures);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
// mesh
|
||||
exporter.ExportMeshes(m.MeshGroups, m.Materials, option);
|
||||
|
||||
|
||||
@@ -1,236 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using VrmLib;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public static class ExpressionAdapter
|
||||
{
|
||||
public static VrmLib.Expression FromGltf(this UniGLTF.Extensions.VRMC_vrm.Expression x, List<VrmLib.Node> nodes, List<VrmLib.Material> materials)
|
||||
{
|
||||
var expression = new VrmLib.Expression(x.Preset.ToVrmFormat(),
|
||||
x.Name,
|
||||
x.IsBinary.HasValue && x.IsBinary.Value)
|
||||
{
|
||||
OverrideBlink = EnumUtil.Cast<VrmLib.ExpressionOverrideType>(x.OverrideBlink),
|
||||
OverrideLookAt = EnumUtil.Cast<VrmLib.ExpressionOverrideType>(x.OverrideLookAt),
|
||||
OverrideMouth = EnumUtil.Cast<VrmLib.ExpressionOverrideType>(x.OverrideMouth),
|
||||
};
|
||||
|
||||
if (x.MorphTargetBinds != null)
|
||||
{
|
||||
foreach (var y in x.MorphTargetBinds)
|
||||
{
|
||||
var node = nodes[y.Node.Value];
|
||||
var blendShapeName = node.Mesh.MorphTargets[y.Index.Value].Name;
|
||||
var blendShapeBind = new MorphTargetBind(node, blendShapeName, y.Weight.Value);
|
||||
expression.MorphTargetBinds.Add(blendShapeBind);
|
||||
}
|
||||
}
|
||||
|
||||
if (x.MaterialColorBinds != null)
|
||||
{
|
||||
foreach (var y in x.MaterialColorBinds)
|
||||
{
|
||||
var material = materials[y.Material.Value];
|
||||
var materialColorBind = new MaterialColorBind(material, EnumUtil.Cast<MaterialBindType>(y.Type), y.TargetValue.ToVector4(Vector4.Zero));
|
||||
expression.MaterialColorBinds.Add(materialColorBind);
|
||||
}
|
||||
}
|
||||
|
||||
if (x.TextureTransformBinds != null)
|
||||
{
|
||||
foreach (var y in x.TextureTransformBinds)
|
||||
{
|
||||
var material = materials[y.Material.Value];
|
||||
var materialUVBind = new TextureTransformBind(material,
|
||||
y.Scaling.ToVector2(Vector2.One),
|
||||
y.Offset.ToVector2(Vector2.Zero));
|
||||
expression.TextureTransformBinds.Add(materialUVBind);
|
||||
}
|
||||
}
|
||||
|
||||
return expression;
|
||||
}
|
||||
// public static ExpressionManager FromGltf(this UniGLTF.VRMC_vrm.Expression master, List<VrmLib.Node> nodes, List<VrmLib.Material> materials)
|
||||
// {
|
||||
// var manager = new ExpressionManager();
|
||||
// foreach (var x in master.BlendShapeGroups)
|
||||
// {
|
||||
// VrmLib.Expression expression = FromGltf(x, nodes, materials);
|
||||
|
||||
// manager.ExpressionList.Add(expression);
|
||||
// };
|
||||
// return manager;
|
||||
// }
|
||||
|
||||
public static UniGLTF.Extensions.VRMC_vrm.MorphTargetBind ToGltf(this MorphTargetBind self, List<VrmLib.Node> nodes)
|
||||
{
|
||||
var name = self.Name;
|
||||
var value = self.Value;
|
||||
var index = self.Node.Mesh.MorphTargets.FindIndex(x => x.Name == name);
|
||||
if (index < 0)
|
||||
{
|
||||
throw new IndexOutOfRangeException(string.Format("MorphTargetName {0} is not found", name));
|
||||
}
|
||||
|
||||
return new UniGLTF.Extensions.VRMC_vrm.MorphTargetBind
|
||||
{
|
||||
Node = nodes.IndexOfThrow(self.Node),
|
||||
Index = self.Node.Mesh.MorphTargets.FindIndex(x => x.Name == name),
|
||||
Weight = value,
|
||||
};
|
||||
}
|
||||
|
||||
public static UniGLTF.Extensions.VRMC_vrm.MaterialColorBind ToGltf(this MaterialColorBind self, List<VrmLib.Material> materials)
|
||||
{
|
||||
var m = new UniGLTF.Extensions.VRMC_vrm.MaterialColorBind
|
||||
{
|
||||
Material = materials.IndexOfThrow(self.Material),
|
||||
Type = EnumUtil.Cast<UniGLTF.Extensions.VRMC_vrm.MaterialColorType>(self.BindType),
|
||||
TargetValue = self.Property.Value.ToFloat4()
|
||||
};
|
||||
return m;
|
||||
}
|
||||
|
||||
public static UniGLTF.Extensions.VRMC_vrm.TextureTransformBind ToGltf(this TextureTransformBind self, List<VrmLib.Material> materials)
|
||||
{
|
||||
var m = new UniGLTF.Extensions.VRMC_vrm.TextureTransformBind
|
||||
{
|
||||
Material = materials.IndexOfThrow(self.Material),
|
||||
Scaling = self.Scale.ToFloat2(),
|
||||
Offset = self.Offset.ToFloat2(),
|
||||
};
|
||||
return m;
|
||||
}
|
||||
|
||||
public static UniGLTF.Extensions.VRMC_vrm.Expression ToGltf(this VrmLib.Expression x, List<VrmLib.Node> nodes, List<VrmLib.Material> materials)
|
||||
{
|
||||
var g = new UniGLTF.Extensions.VRMC_vrm.Expression
|
||||
{
|
||||
Preset = x.Preset.ToGltfFormat(),
|
||||
Name = x.Name,
|
||||
IsBinary = x.IsBinary,
|
||||
OverrideBlink = EnumUtil.Cast<UniGLTF.Extensions.VRMC_vrm.ExpressionOverrideType>(x.OverrideBlink),
|
||||
OverrideLookAt = EnumUtil.Cast<UniGLTF.Extensions.VRMC_vrm.ExpressionOverrideType>(x.OverrideLookAt),
|
||||
OverrideMouth = EnumUtil.Cast<UniGLTF.Extensions.VRMC_vrm.ExpressionOverrideType>(x.OverrideMouth),
|
||||
};
|
||||
|
||||
g.MorphTargetBinds = new List<UniGLTF.Extensions.VRMC_vrm.MorphTargetBind>();
|
||||
foreach (var blendShapeBind in x.MorphTargetBinds)
|
||||
{
|
||||
g.MorphTargetBinds.Add(blendShapeBind.ToGltf(nodes));
|
||||
}
|
||||
|
||||
g.MaterialColorBinds = new List<UniGLTF.Extensions.VRMC_vrm.MaterialColorBind>();
|
||||
foreach (var materialColorBind in x.MaterialColorBinds)
|
||||
{
|
||||
g.MaterialColorBinds.Add(materialColorBind.ToGltf(materials));
|
||||
}
|
||||
|
||||
g.TextureTransformBinds = new List<UniGLTF.Extensions.VRMC_vrm.TextureTransformBind>();
|
||||
foreach (var materialUVBind in x.TextureTransformBinds)
|
||||
{
|
||||
g.TextureTransformBinds.Add(materialUVBind.ToGltf(materials));
|
||||
}
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
// public static UniGLTF.VRMC_vrm.BlendShape ToGltf(this ExpressionManager src, List<VrmLib.Node> nodes, List<VrmLib.Material> materials)
|
||||
// {
|
||||
// var blendShape = new UniGLTF.VRMC_vrm.BlendShape
|
||||
// {
|
||||
// };
|
||||
// if (src != null)
|
||||
// {
|
||||
// foreach (var x in src.ExpressionList)
|
||||
// {
|
||||
// blendShape.BlendShapeGroups.Add(x.ToGltf(nodes, materials));
|
||||
// }
|
||||
// }
|
||||
// return blendShape;
|
||||
// }
|
||||
|
||||
private static UniGLTF.Extensions.VRMC_vrm.ExpressionPreset ToGltfFormat(this VrmLib.ExpressionPreset preset)
|
||||
{
|
||||
switch (preset)
|
||||
{
|
||||
case ExpressionPreset.Custom:
|
||||
return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.custom;
|
||||
// 喜怒哀楽驚
|
||||
case ExpressionPreset.Happy:
|
||||
return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.happy;
|
||||
case ExpressionPreset.Angry:
|
||||
return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.angry;
|
||||
case ExpressionPreset.Sad:
|
||||
return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.sad;
|
||||
case ExpressionPreset.Relaxed:
|
||||
return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.relaxed;
|
||||
case ExpressionPreset.Surprised:
|
||||
return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.surprised;
|
||||
// Procedural(LipSync)
|
||||
case ExpressionPreset.Aa:
|
||||
return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.aa;
|
||||
case ExpressionPreset.Ih:
|
||||
return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.ih;
|
||||
case ExpressionPreset.Ou:
|
||||
return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.ou;
|
||||
case ExpressionPreset.Ee:
|
||||
return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.ee;
|
||||
case ExpressionPreset.Oh:
|
||||
return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.oh;
|
||||
// Procedural(Blink)
|
||||
case ExpressionPreset.Blink:
|
||||
return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.blink;
|
||||
case ExpressionPreset.BlinkLeft:
|
||||
return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.blinkLeft;
|
||||
case ExpressionPreset.BlinkRight:
|
||||
return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.blinkRight;
|
||||
// Procedural(LookAt)
|
||||
case ExpressionPreset.LookUp:
|
||||
return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookUp;
|
||||
case ExpressionPreset.LookDown:
|
||||
return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookDown;
|
||||
case ExpressionPreset.LookLeft:
|
||||
return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookLeft;
|
||||
case ExpressionPreset.LookRight:
|
||||
return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookRight;
|
||||
// Other
|
||||
case ExpressionPreset.Neutral:
|
||||
return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.neutral;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(preset), preset, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static VrmLib.ExpressionPreset ToVrmFormat(this UniGLTF.Extensions.VRMC_vrm.ExpressionPreset preset)
|
||||
{
|
||||
switch (preset)
|
||||
{
|
||||
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.custom: return ExpressionPreset.Custom;
|
||||
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.aa: return ExpressionPreset.Aa;
|
||||
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.ih: return ExpressionPreset.Ih;
|
||||
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.ou: return ExpressionPreset.Ou;
|
||||
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.ee: return ExpressionPreset.Ee;
|
||||
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.oh: return ExpressionPreset.Oh;
|
||||
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.blink: return ExpressionPreset.Blink;
|
||||
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.happy: return ExpressionPreset.Happy;
|
||||
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.angry: return ExpressionPreset.Angry;
|
||||
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.sad: return ExpressionPreset.Sad;
|
||||
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.relaxed: return ExpressionPreset.Relaxed;
|
||||
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookUp: return ExpressionPreset.LookUp;
|
||||
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.surprised: return ExpressionPreset.Surprised;
|
||||
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookDown: return ExpressionPreset.LookDown;
|
||||
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookLeft: return ExpressionPreset.LookLeft;
|
||||
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookRight: return ExpressionPreset.LookRight;
|
||||
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.blinkLeft: return ExpressionPreset.BlinkLeft;
|
||||
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.blinkRight: return ExpressionPreset.BlinkRight;
|
||||
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.neutral: return ExpressionPreset.Neutral;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(preset), preset, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cadc48d0e68ee5847b158dcef9b7b9a8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,57 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using VrmLib;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public static class FirstPersonAdapter
|
||||
{
|
||||
public static VrmLib.FirstPersonMeshType FromGltf(this UniGLTF.Extensions.VRMC_vrm.FirstPersonType src)
|
||||
{
|
||||
switch (src)
|
||||
{
|
||||
case UniGLTF.Extensions.VRMC_vrm.FirstPersonType.auto: return FirstPersonMeshType.Auto;
|
||||
case UniGLTF.Extensions.VRMC_vrm.FirstPersonType.both: return FirstPersonMeshType.Both;
|
||||
case UniGLTF.Extensions.VRMC_vrm.FirstPersonType.firstPersonOnly: return FirstPersonMeshType.FirstPersonOnly;
|
||||
case UniGLTF.Extensions.VRMC_vrm.FirstPersonType.thirdPersonOnly: return FirstPersonMeshType.ThirdPersonOnly;
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static FirstPerson FromGltf(this UniGLTF.Extensions.VRMC_vrm.FirstPerson fp, List<Node> nodes)
|
||||
{
|
||||
var self = new FirstPerson();
|
||||
|
||||
if (fp.MeshAnnotations != null)
|
||||
{
|
||||
self.Annotations.AddRange(fp.MeshAnnotations
|
||||
.Select(x => new FirstPersonMeshAnnotation(nodes[x.Node.Value], x.FirstPersonType.FromGltf())));
|
||||
}
|
||||
return self;
|
||||
}
|
||||
public static UniGLTF.Extensions.VRMC_vrm.FirstPerson ToGltf(this FirstPerson self, List<Node> nodes)
|
||||
{
|
||||
if (self == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var firstPerson = new UniGLTF.Extensions.VRMC_vrm.FirstPerson
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
foreach (var x in self.Annotations)
|
||||
{
|
||||
firstPerson.MeshAnnotations.Add(new UniGLTF.Extensions.VRMC_vrm.MeshAnnotation
|
||||
{
|
||||
Node = nodes.IndexOfThrow(x.Node),
|
||||
FirstPersonType = EnumUtil.Cast<UniGLTF.Extensions.VRMC_vrm.FirstPersonType>(x.FirstPersonFlag),
|
||||
});
|
||||
}
|
||||
return firstPerson;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32f13c918ad866647bfc8f91f3ec7815
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,64 +0,0 @@
|
||||
using System;
|
||||
using VrmLib;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public static class LookAtAdapter
|
||||
{
|
||||
public static LookAtRangeMap FromGltf(this UniGLTF.Extensions.VRMC_vrm.LookAtRangeMap map)
|
||||
{
|
||||
return new LookAtRangeMap
|
||||
{
|
||||
InputMaxValue = map.InputMaxValue.Value,
|
||||
OutputScaling = map.OutputScale.Value,
|
||||
};
|
||||
}
|
||||
|
||||
public static LookAtType FromGltf(this UniGLTF.Extensions.VRMC_vrm.LookAtType src)
|
||||
{
|
||||
switch (src)
|
||||
{
|
||||
case UniGLTF.Extensions.VRMC_vrm.LookAtType.bone: return LookAtType.Bone;
|
||||
case UniGLTF.Extensions.VRMC_vrm.LookAtType.expression: return LookAtType.Expression;
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static LookAt FromGltf(this UniGLTF.Extensions.VRMC_vrm.LookAt src)
|
||||
{
|
||||
return new LookAt
|
||||
{
|
||||
OffsetFromHeadBone = src.OffsetFromHeadBone.ToVector3(),
|
||||
LookAtType = src.LookAtType.FromGltf(),
|
||||
HorizontalInner = src.LookAtHorizontalInner.FromGltf(),
|
||||
HorizontalOuter = src.LookAtHorizontalOuter.FromGltf(),
|
||||
VerticalUp = src.LookAtVerticalUp.FromGltf(),
|
||||
VerticalDown = src.LookAtVerticalDown.FromGltf(),
|
||||
};
|
||||
}
|
||||
|
||||
public static UniGLTF.Extensions.VRMC_vrm.LookAtRangeMap ToGltf(this LookAtRangeMap map)
|
||||
{
|
||||
return new UniGLTF.Extensions.VRMC_vrm.LookAtRangeMap
|
||||
{
|
||||
InputMaxValue = map.InputMaxValue,
|
||||
OutputScale = map.OutputScaling,
|
||||
};
|
||||
}
|
||||
|
||||
public static UniGLTF.Extensions.VRMC_vrm.LookAt ToGltf(this LookAt lookAt)
|
||||
{
|
||||
var dst = new UniGLTF.Extensions.VRMC_vrm.LookAt
|
||||
{
|
||||
LookAtType = (UniGLTF.Extensions.VRMC_vrm.LookAtType)lookAt.LookAtType,
|
||||
LookAtHorizontalInner = lookAt.HorizontalInner.ToGltf(),
|
||||
LookAtHorizontalOuter = lookAt.HorizontalOuter.ToGltf(),
|
||||
LookAtVerticalUp = lookAt.VerticalUp.ToGltf(),
|
||||
LookAtVerticalDown = lookAt.VerticalDown.ToGltf(),
|
||||
OffsetFromHeadBone = lookAt.OffsetFromHeadBone.ToFloat3(),
|
||||
};
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68385357d73a5a3428e68eb49742baa9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,100 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using VrmLib;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public static class VrmMetaAdapter
|
||||
{
|
||||
public static AvatarPermission ToAvaterPermission(this UniGLTF.Extensions.VRMC_vrm.Meta self)
|
||||
{
|
||||
return new AvatarPermission
|
||||
{
|
||||
AvatarUsage = (AvatarUsageType)self.AvatarPermission,
|
||||
IsAllowedViolentUsage = self.AllowExcessivelyViolentUsage.Value,
|
||||
IsAllowedSexualUsage = self.AllowExcessivelySexualUsage.Value,
|
||||
CommercialUsage = (CommercialUsageType)self.CommercialUsage,
|
||||
// OtherPermissionUrl = self.OtherPermissionUrl,
|
||||
IsAllowedPoliticalOrReligiousUsage = self.AllowPoliticalOrReligiousUsage.Value,
|
||||
};
|
||||
}
|
||||
|
||||
public static RedistributionLicense ToRedistributionLicense(this UniGLTF.Extensions.VRMC_vrm.Meta self)
|
||||
{
|
||||
return new RedistributionLicense
|
||||
{
|
||||
CreditNotation = (CreditNotationType)self.CreditNotation,
|
||||
IsAllowRedistribution = self.AllowRedistribution.Value,
|
||||
ModificationLicense = (ModificationLicenseType)self.Modification,
|
||||
OtherLicenseUrl = self.OtherLicenseUrl,
|
||||
};
|
||||
}
|
||||
|
||||
public static Meta FromGltf(this UniGLTF.Extensions.VRMC_vrm.Meta self, List<Texture> textures)
|
||||
{
|
||||
var meta = new Meta
|
||||
{
|
||||
Name = self.Name,
|
||||
Version = self.Version,
|
||||
ContactInformation = self.ContactInformation,
|
||||
AvatarPermission = ToAvaterPermission(self),
|
||||
RedistributionLicense = ToRedistributionLicense(self),
|
||||
};
|
||||
if (self.References != null)
|
||||
{
|
||||
meta.References.AddRange(self.References);
|
||||
}
|
||||
if (self.Authors != null)
|
||||
{
|
||||
meta.Authors.AddRange(self.Authors);
|
||||
}
|
||||
if (self.ThumbnailImage.HasValue)
|
||||
{
|
||||
var texture = textures[self.ThumbnailImage.Value] as ImageTexture;
|
||||
if (texture != null)
|
||||
{
|
||||
meta.Thumbnail = texture.Image;
|
||||
}
|
||||
}
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
public static UniGLTF.Extensions.VRMC_vrm.Meta ToGltf(this Meta self, List<Texture> textures)
|
||||
{
|
||||
var meta = new UniGLTF.Extensions.VRMC_vrm.Meta
|
||||
{
|
||||
Name = self.Name,
|
||||
Version = self.Version,
|
||||
ContactInformation = self.ContactInformation,
|
||||
CopyrightInformation = self.CopyrightInformation,
|
||||
// AvatarPermission
|
||||
AvatarPermission = (UniGLTF.Extensions.VRMC_vrm.AvatarPermissionType)self.AvatarPermission.AvatarUsage,
|
||||
AllowExcessivelyViolentUsage = self.AvatarPermission.IsAllowedViolentUsage,
|
||||
AllowExcessivelySexualUsage = self.AvatarPermission.IsAllowedSexualUsage,
|
||||
CommercialUsage = (UniGLTF.Extensions.VRMC_vrm.CommercialUsageType)self.AvatarPermission.CommercialUsage,
|
||||
AllowPoliticalOrReligiousUsage = self.AvatarPermission.IsAllowedPoliticalOrReligiousUsage,
|
||||
// OtherPermissionUrl = self.AvatarPermission.OtherPermissionUrl,
|
||||
// RedistributionLicense
|
||||
CreditNotation = (UniGLTF.Extensions.VRMC_vrm.CreditNotationType)self.RedistributionLicense.CreditNotation,
|
||||
AllowRedistribution = self.RedistributionLicense.IsAllowRedistribution,
|
||||
Modification = (UniGLTF.Extensions.VRMC_vrm.ModificationType)self.RedistributionLicense.ModificationLicense,
|
||||
OtherLicenseUrl = self.RedistributionLicense.OtherLicenseUrl,
|
||||
References = self.References,
|
||||
Authors = self.Authors,
|
||||
};
|
||||
if (self.Thumbnail != null)
|
||||
{
|
||||
for (int i = 0; i < textures.Count; ++i)
|
||||
{
|
||||
var texture = textures[i] as ImageTexture;
|
||||
if (texture.Image == self.Thumbnail)
|
||||
{
|
||||
meta.ThumbnailImage = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return meta;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba45f21a0e4c4fd488473e928f70cd98
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,111 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UniGLTF;
|
||||
using UniGLTF.Extensions.VRMC_springBone;
|
||||
using UniGLTF.Extensions.VRMC_node_collider;
|
||||
using VrmLib;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public static class SpringBoneAdapter
|
||||
{
|
||||
public static VRMC_springBone ToGltf(this SpringBoneManager self, List<Node> nodes,
|
||||
List<glTFNode> gltfNodes)
|
||||
{
|
||||
if (self == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var springBone = new VRMC_springBone
|
||||
{
|
||||
Springs = new List<Spring>(),
|
||||
};
|
||||
|
||||
//
|
||||
// VRMC_node_collider
|
||||
//
|
||||
foreach (var nodeCollider in self.Springs.SelectMany(x => x.Colliders))
|
||||
{
|
||||
var index = nodes.IndexOfThrow(nodeCollider.Node);
|
||||
var gltfCollider = new VRMC_node_collider
|
||||
{
|
||||
Shapes = new List<ColliderShape>(),
|
||||
};
|
||||
foreach (var y in nodeCollider.Colliders)
|
||||
{
|
||||
switch (y.ColliderType)
|
||||
{
|
||||
case VrmSpringBoneColliderTypes.Sphere:
|
||||
{
|
||||
var sphere = new ColliderShapeSphere
|
||||
{
|
||||
Radius = y.Radius,
|
||||
Offset = y.Offset.ToFloat3(),
|
||||
};
|
||||
gltfCollider.Shapes.Add(new ColliderShape
|
||||
{
|
||||
Sphere = sphere,
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
case VrmSpringBoneColliderTypes.Capsule:
|
||||
{
|
||||
var capsule = new ColliderShapeCapsule
|
||||
{
|
||||
Radius = y.Radius,
|
||||
Offset = y.Offset.ToFloat3(),
|
||||
Tail = y.CapsuleTail.ToFloat3(),
|
||||
};
|
||||
gltfCollider.Shapes.Add(new ColliderShape
|
||||
{
|
||||
Capsule = capsule,
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// add to node.extensions
|
||||
//
|
||||
UniGLTF.Extensions.VRMC_node_collider.GltfSerializer.SerializeTo(ref gltfNodes[index].extensions, gltfCollider);
|
||||
}
|
||||
|
||||
//
|
||||
// VRMC_springBone
|
||||
//
|
||||
foreach (var x in self.Springs)
|
||||
{
|
||||
var spring = new Spring
|
||||
{
|
||||
Name = x.Comment,
|
||||
Colliders = x.Colliders.Select(y => nodes.IndexOfThrow(y.Node)).ToArray(),
|
||||
Joints = new List<SpringBoneJoint>(),
|
||||
};
|
||||
|
||||
foreach (var y in x.Joints)
|
||||
{
|
||||
spring.Joints.Add(new SpringBoneJoint
|
||||
{
|
||||
Node = nodes.IndexOfThrow(y.Node),
|
||||
HitRadius = y.HitRadius,
|
||||
DragForce = y.DragForce,
|
||||
GravityDir = y.GravityDir.ToFloat3(),
|
||||
GravityPower = y.GravityPower,
|
||||
Stiffness = y.Stiffness,
|
||||
});
|
||||
}
|
||||
|
||||
springBone.Springs.Add(spring);
|
||||
}
|
||||
|
||||
return springBone;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d523ab537ffdbe40ae4fbd372693cb3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -70,32 +70,6 @@ namespace UniVRM10
|
||||
}
|
||||
}
|
||||
|
||||
static (UniGLTF.glTFMaterial, bool) ToProtobufMaterial(VrmLib.Material vrmlibMaterial, List<VrmLib.Texture> textures)
|
||||
{
|
||||
if (vrmlibMaterial is VrmLib.MToonMaterial mtoon)
|
||||
{
|
||||
// MToon
|
||||
var protobufMaterial = UniVRM10.MToonAdapter.MToonToGltf(mtoon, textures);
|
||||
return (protobufMaterial, true);
|
||||
}
|
||||
else if (vrmlibMaterial is VrmLib.UnlitMaterial unlit)
|
||||
{
|
||||
// Unlit
|
||||
var protobufMaterial = UniVRM10.MaterialAdapter.UnlitToGltf(unlit, textures);
|
||||
return (protobufMaterial, true);
|
||||
}
|
||||
else if (vrmlibMaterial is VrmLib.PBRMaterial pbr)
|
||||
{
|
||||
// PBR
|
||||
var protobufMaterial = UniVRM10.MaterialAdapter.PBRToGltf(pbr, textures);
|
||||
return (protobufMaterial, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
static void CompareUnityMaterial(Material lhs, Material rhs)
|
||||
{
|
||||
Assert.AreEqual(lhs.name, rhs.name);
|
||||
@@ -189,20 +163,20 @@ namespace UniVRM10
|
||||
var vrmLibMaterial = converter.Export10(src, (a, b, c, d) => null);
|
||||
Assert.AreEqual(vrmLibMaterialType, vrmLibMaterial.GetType());
|
||||
|
||||
// vrmlib => gltf
|
||||
var textures = new List<VrmLib.Texture>();
|
||||
var (gltfMaterial, hasKhrUnlit) = ToProtobufMaterial(vrmLibMaterial, textures);
|
||||
if (gltfMaterial.extensions != null)
|
||||
{
|
||||
gltfMaterial.extensions = gltfMaterial.extensions.Deserialize();
|
||||
}
|
||||
Assert.AreEqual(hasKhrUnlit, glTF_KHR_materials_unlit.IsEnable(gltfMaterial));
|
||||
// // vrmlib => gltf
|
||||
// var textures = new List<VrmLib.Texture>();
|
||||
// var (gltfMaterial, hasKhrUnlit) = ToProtobufMaterial(vrmLibMaterial, textures);
|
||||
// if (gltfMaterial.extensions != null)
|
||||
// {
|
||||
// gltfMaterial.extensions = gltfMaterial.extensions.Deserialize();
|
||||
// }
|
||||
// Assert.AreEqual(hasKhrUnlit, glTF_KHR_materials_unlit.IsEnable(gltfMaterial));
|
||||
|
||||
// gltf => json
|
||||
var jsonMaterial = Serialize(gltfMaterial, UniGLTF.GltfSerializer.Serialize_gltf_materials_ITEM);
|
||||
// // gltf => json
|
||||
// var jsonMaterial = Serialize(gltfMaterial, UniGLTF.GltfSerializer.Serialize_gltf_materials_ITEM);
|
||||
|
||||
// gltf <= json
|
||||
var deserialized = UniGLTF.GltfDeserializer.Deserialize_gltf_materials_LIST(jsonMaterial.ParseAsJson());
|
||||
// // gltf <= json
|
||||
// var deserialized = UniGLTF.GltfDeserializer.Deserialize_gltf_materials_LIST(jsonMaterial.ParseAsJson());
|
||||
|
||||
// // vrmlib <= gltf
|
||||
// var loaded = deserialized.FromGltf(textures);
|
||||
@@ -249,46 +223,46 @@ namespace UniVRM10
|
||||
OverrideMouth = VrmLib.ExpressionOverrideType.Blend,
|
||||
};
|
||||
|
||||
// export
|
||||
var gltf = UniVRM10.ExpressionAdapter.ToGltf(expression, new List<VrmLib.Node>(), new List<VrmLib.Material>());
|
||||
Assert.AreEqual(UniGLTF.Extensions.VRMC_vrm.ExpressionOverrideType.none, gltf.OverrideBlink);
|
||||
Assert.AreEqual(UniGLTF.Extensions.VRMC_vrm.ExpressionOverrideType.block, gltf.OverrideLookAt);
|
||||
Assert.AreEqual(UniGLTF.Extensions.VRMC_vrm.ExpressionOverrideType.blend, gltf.OverrideMouth);
|
||||
// // export
|
||||
// var gltf = UniVRM10.ExpressionAdapter.ToGltf(expression, new List<VrmLib.Node>(), new List<VrmLib.Material>());
|
||||
// Assert.AreEqual(UniGLTF.Extensions.VRMC_vrm.ExpressionOverrideType.none, gltf.OverrideBlink);
|
||||
// Assert.AreEqual(UniGLTF.Extensions.VRMC_vrm.ExpressionOverrideType.block, gltf.OverrideLookAt);
|
||||
// Assert.AreEqual(UniGLTF.Extensions.VRMC_vrm.ExpressionOverrideType.blend, gltf.OverrideMouth);
|
||||
|
||||
// import
|
||||
var imported = UniVRM10.ExpressionAdapter.FromGltf(gltf, new List<VrmLib.Node>(), new List<VrmLib.Material>());
|
||||
Assert.AreEqual(VrmLib.ExpressionOverrideType.None, imported.OverrideBlink);
|
||||
Assert.AreEqual(VrmLib.ExpressionOverrideType.Block, imported.OverrideLookAt);
|
||||
Assert.AreEqual(VrmLib.ExpressionOverrideType.Blend, imported.OverrideMouth);
|
||||
// // import
|
||||
// var imported = UniVRM10.ExpressionAdapter.FromGltf(gltf, new List<VrmLib.Node>(), new List<VrmLib.Material>());
|
||||
// Assert.AreEqual(VrmLib.ExpressionOverrideType.None, imported.OverrideBlink);
|
||||
// Assert.AreEqual(VrmLib.ExpressionOverrideType.Block, imported.OverrideLookAt);
|
||||
// Assert.AreEqual(VrmLib.ExpressionOverrideType.Blend, imported.OverrideMouth);
|
||||
}
|
||||
|
||||
{
|
||||
// export
|
||||
foreach (var preset in Enum.GetValues(typeof(VrmLib.ExpressionPreset)) as VrmLib.ExpressionPreset[])
|
||||
{
|
||||
var expression = new VrmLib.Expression(preset, "", false);
|
||||
// // export
|
||||
// foreach (var preset in Enum.GetValues(typeof(VrmLib.ExpressionPreset)) as VrmLib.ExpressionPreset[])
|
||||
// {
|
||||
// var expression = new VrmLib.Expression(preset, "", false);
|
||||
|
||||
// expect no exception
|
||||
var gltf = ExpressionAdapter.ToGltf(
|
||||
expression,
|
||||
new List<VrmLib.Node>(),
|
||||
new List<VrmLib.Material>());
|
||||
}
|
||||
// // expect no exception
|
||||
// var gltf = ExpressionAdapter.ToGltf(
|
||||
// expression,
|
||||
// new List<VrmLib.Node>(),
|
||||
// new List<VrmLib.Material>());
|
||||
// }
|
||||
|
||||
// import
|
||||
foreach (var preset in Enum.GetValues(typeof(UniGLTF.Extensions.VRMC_vrm.ExpressionPreset)) as UniGLTF.Extensions.VRMC_vrm.ExpressionPreset[])
|
||||
{
|
||||
var gltf = new UniGLTF.Extensions.VRMC_vrm.Expression
|
||||
{
|
||||
Preset = preset,
|
||||
};
|
||||
// // import
|
||||
// foreach (var preset in Enum.GetValues(typeof(UniGLTF.Extensions.VRMC_vrm.ExpressionPreset)) as UniGLTF.Extensions.VRMC_vrm.ExpressionPreset[])
|
||||
// {
|
||||
// var gltf = new UniGLTF.Extensions.VRMC_vrm.Expression
|
||||
// {
|
||||
// Preset = preset,
|
||||
// };
|
||||
|
||||
// expect no exception
|
||||
ExpressionAdapter.FromGltf(
|
||||
gltf,
|
||||
new List<VrmLib.Node>(),
|
||||
new List<VrmLib.Material>());
|
||||
}
|
||||
// // expect no exception
|
||||
// ExpressionAdapter.FromGltf(
|
||||
// gltf,
|
||||
// new List<VrmLib.Node>(),
|
||||
// new List<VrmLib.Material>());
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user