public async Task <VRMMetaObject> ReadMetaAsync(IAwaitCaller awaitCaller = null, bool createThumbnail = false) { awaitCaller = awaitCaller ?? new ImmediateCaller(); var meta = ScriptableObject.CreateInstance <VRMMetaObject>(); meta.name = "Meta"; meta.ExporterVersion = VRM.exporterVersion; var gltfMeta = VRM.meta; meta.Version = gltfMeta.version; // model version meta.Author = gltfMeta.author; meta.ContactInformation = gltfMeta.contactInformation; meta.Reference = gltfMeta.reference; meta.Title = gltfMeta.title; if (gltfMeta.texture >= 0) { var(key, param) = GltfTextureImporter.CreateSRGB(Data, gltfMeta.texture, Vector2.zero, Vector2.one); meta.Thumbnail = await TextureFactory.GetTextureAsync(param, awaitCaller) as Texture2D; } meta.AllowedUser = gltfMeta.allowedUser; meta.ViolentUssage = gltfMeta.violentUssage; meta.SexualUssage = gltfMeta.sexualUssage; meta.CommercialUssage = gltfMeta.commercialUssage; meta.OtherPermissionUrl = gltfMeta.otherPermissionUrl; meta.LicenseType = gltfMeta.licenseType; meta.OtherLicenseUrl = gltfMeta.otherLicenseUrl; return(meta); }
public static bool TryGetTextureFromMaterialProperty(GltfData data, glTF_VRM_Material vrmMaterial, string textureKey, out (SubAssetKey, TextureDescriptor) texture) { // 任意の shader の import を許容する if (/*vrmMaterial.shader == MToon.Utils.ShaderName &&*/ vrmMaterial.textureProperties.TryGetValue(textureKey, out var textureIdx)) { var(offset, scale) = (new Vector2(0, 0), new Vector2(1, 1)); if (TryGetTextureOffsetAndScale(vrmMaterial, textureKey, out var os)) { offset = os.offset; scale = os.scale; } switch (textureKey) { case MToon.Utils.PropBumpMap: texture = GltfTextureImporter.CreateNormal(data, textureIdx, offset, scale); break; default: texture = GltfTextureImporter.CreateSRGB(data, textureIdx, offset, scale); break; } return(true); } texture = default; return(false); }
private static bool TryGetThumbnailTexture(GltfData data, glTF_VRM_extensions vrm, out (SubAssetKey, TextureDescriptor) texture) { if (vrm.meta.texture > -1) { texture = GltfTextureImporter.CreateSRGB(data, vrm.meta.texture, Vector2.zero, Vector2.one); return(true); } texture = default; return(false); }
public static (SubAssetKey, TextureImportParam) Create(GltfParser parser, int index, Vector2 offset, Vector2 scale, string prop, float metallicFactor, float roughnessFactor) { switch (prop) { case TextureImportParam.NORMAL_PROP: return(GltfTextureImporter.CreateNormal(parser, index, offset, scale)); default: return(GltfTextureImporter.CreateSRGB(parser, index, offset, scale)); case TextureImportParam.OCCLUSION_PROP: case TextureImportParam.METALLIC_GLOSS_PROP: throw new NotImplementedException(); } }
private static bool TryGetSRGBTexture(GltfParser parser, Vrm10TextureInfo info, out (SubAssetKey, TextureImportParam) pair) { try { var(offset, scale) = GetTextureOffsetAndScale(info); pair = GltfTextureImporter.CreateSRGB(parser, info.index, offset, scale); return(true); } catch (NullReferenceException) { pair = default; return(false); } catch (ArgumentOutOfRangeException) { pair = default; return(false); } }
/// <summary> /// VMRC_materials_mtoon の場合にマテリアル生成情報を作成する /// </summary> /// <param name="parser"></param> /// <param name="i"></param> /// <param name="param"></param> /// <returns></returns> public static bool TryCreateParam(GltfParser parser, int i, out MaterialImportParam param) { var m = parser.GLTF.materials[i]; if (!UniGLTF.Extensions.VRMC_materials_mtoon.GltfDeserializer.TryGet(m.extensions, out UniGLTF.Extensions.VRMC_materials_mtoon.VRMC_materials_mtoon mtoon)) { // fallback to gltf param = default; return(false); } // use material.name, because material name may renamed in GltfParser. param = new MaterialImportParam(m.name, MToon.Utils.ShaderName); param.Actions.Add(material => { // Texture 以外をここで設定。Texture は TextureSlots へ { // material.SetFloat(PropVersion, mtoon.Version); } { // var rendering = mtoon.Rendering; // SetRenderMode(material, rendering.RenderMode, rendering.RenderQueueOffsetNumber, // useDefaultRenderQueue: false); // SetCullMode(material, rendering.CullMode); } { // var color = mtoon.Color; material.SetColor(MToon.Utils.PropColor, m.pbrMetallicRoughness.baseColorFactor.ToColor4()); material.SetColor(MToon.Utils.PropShadeColor, mtoon.ShadeFactor.ToColor3()); material.SetFloat(MToon.Utils.PropCutoff, m.alphaCutoff); } { { material.SetFloat(MToon.Utils.PropShadeShift, mtoon.ShadingShiftFactor.Value); material.SetFloat(MToon.Utils.PropShadeToony, mtoon.ShadingToonyFactor.Value); // material.SetFloat(PropReceiveShadowRate, mtoon.prop.ShadowReceiveMultiplierValue); // material.SetFloat(PropShadingGradeRate, mtoon.mix prop.LitAndShadeMixingMultiplierValue); } { material.SetFloat(MToon.Utils.PropLightColorAttenuation, mtoon.LightColorAttenuationFactor.Value); material.SetFloat(MToon.Utils.PropIndirectLightIntensity, mtoon.GiIntensityFactor.Value); } } { material.SetColor(MToon.Utils.PropEmissionColor, m.emissiveFactor.ToColor3()); } { material.SetColor(MToon.Utils.PropRimColor, mtoon.RimFactor.ToColor3()); material.SetFloat(MToon.Utils.PropRimLightingMix, mtoon.RimLightingMixFactor.Value); material.SetFloat(MToon.Utils.PropRimFresnelPower, mtoon.RimFresnelPowerFactor.Value); material.SetFloat(MToon.Utils.PropRimLift, mtoon.RimLiftFactor.Value); } { material.SetFloat(MToon.Utils.PropOutlineWidth, mtoon.OutlineWidthFactor.Value); material.SetFloat(MToon.Utils.PropOutlineScaledMaxDistance, mtoon.OutlineScaledMaxDistanceFactor.Value); material.SetColor(MToon.Utils.PropOutlineColor, mtoon.OutlineFactor.ToColor3()); material.SetFloat(MToon.Utils.PropOutlineLightingMix, mtoon.OutlineLightingMixFactor.Value); // private // MToon.Utils.SetOutlineMode(material, outline.OutlineWidthMode, outline.OutlineColorMode); } { // material.SetTextureScale(PropMainTex, mtoon.MainTextureLeftBottomOriginScale); // material.SetTextureOffset(PropMainTex, mtoon.MainTextureLeftBottomOriginOffset); material.SetFloat(MToon.Utils.PropUvAnimScrollX, mtoon.UvAnimationScrollXSpeedFactor.Value); material.SetFloat(MToon.Utils.PropUvAnimScrollY, mtoon.UvAnimationScrollYSpeedFactor.Value); material.SetFloat(MToon.Utils.PropUvAnimRotation, mtoon.UvAnimationRotationSpeedFactor.Value); } MToon.Utils.ValidateProperties(material, isBlendModeChangedByUser: false); }); // SetTexture(material, PropMainTex, color.LitMultiplyTexture); // SetNormalMapping(material, prop.NormalTexture, prop.NormalScaleValue); // SetTexture(material, PropEmissionMap, emission.EmissionMultiplyTexture); if (m.pbrMetallicRoughness != null) { // base color if (m.pbrMetallicRoughness?.baseColorTexture != null) { param.TextureSlots.Add("_MainTex", GltfPBRMaterial.BaseColorTexture(parser, m)); } } if (m.normalTexture != null && m.normalTexture.index != -1) { // normal map param.Actions.Add(material => material.EnableKeyword("_NORMALMAP")); var textureParam = GltfPBRMaterial.NormalTexture(parser, m); param.TextureSlots.Add("_BumpMap", textureParam); param.FloatValues.Add("_BumpScale", m.normalTexture.scale); } if (m.emissiveTexture != null && m.emissiveTexture.index != -1) { var(offset, scale) = GltfMaterialImporter.GetTextureOffsetAndScale(m.emissiveTexture); var textureParam = GltfTextureImporter.CreateSRGB(parser, m.emissiveTexture.index, offset, scale); param.TextureSlots.Add("_EmissionMap", textureParam); } // TODO: if (mtoon.ShadeMultiplyTexture.HasValue) { var textureParam = GltfTextureImporter.CreateSRGB(parser, mtoon.ShadeMultiplyTexture.Value, Vector2.zero, Vector2.one); param.TextureSlots.Add("_ShadeTexture", textureParam); } if (mtoon.OutlineWidthMultiplyTexture.HasValue) { var textureParam = GltfTextureImporter.CreateSRGB(parser, mtoon.OutlineWidthMultiplyTexture.Value, Vector2.zero, Vector2.one); param.TextureSlots.Add("_OutlineWidthTexture", textureParam); } if (mtoon.AdditiveTexture.HasValue) { var textureParam = GltfTextureImporter.CreateSRGB(parser, mtoon.AdditiveTexture.Value, Vector2.zero, Vector2.one); param.TextureSlots.Add("_SphereAdd", textureParam); } if (mtoon.RimMultiplyTexture.HasValue) { var textureParam = GltfTextureImporter.CreateSRGB(parser, mtoon.RimMultiplyTexture.Value, Vector2.zero, Vector2.one); param.TextureSlots.Add("_RimTexture", textureParam);; } if (mtoon.UvAnimationMaskTexture.HasValue) { var textureParam = GltfTextureImporter.CreateSRGB(parser, mtoon.UvAnimationMaskTexture.Value, Vector2.zero, Vector2.one); param.TextureSlots.Add("_UvAnimMaskTexture", textureParam); } return(true); }