From ac417884e526caec3fceb9a541ce292b5607ef54 Mon Sep 17 00:00:00 2001 From: IzayoiJiichan Date: Fri, 17 Jan 2020 00:00:00 +0900 Subject: [PATCH] version 0.6.0 --- CHANGELOG.md | 4 + .../schema/VRMC_materials_mtoon.schema.json | 212 +++++++++++ .../0.4/schema/material.vgo.schema.json | 11 + .../schema/materials.extensions.schema.json | 16 + .../0.4/schema/node.vgo.collider.schema.json | 51 +++ .../0.4/schema/node.vgo.colliders.schema.json | 8 + .../schema/node.vgo.gameobject.schema.json | 25 ++ .../0.4/schema/node.vgo.light.schema.json | 110 ++++++ .../node.vgo.physicMaterial.schema.json | 35 ++ .../0.4/schema/node.vgo.rigidbody.schema.json | 47 +++ .../nodes.extensions.vgo_nodes.schema.json | 22 ++ .../0.4/schema/vgo.meta.schema.json | 19 + .../0.4/schema/vgo.right.schema.json | 39 ++ .../specification/0.4/schema/vgo.schema.json | 13 + README.ja.md | 149 +++++++- README.md | 147 +++++++- .../Runtime/IO/MaterialExporter.cs | 42 ++- .../Runtime/IO/MaterialImporter.cs | 4 +- UniGLTFforUniVgo/Runtime/IO/ShaderStore.cs | 16 +- .../Runtime/Schema/Extensions/glTFMaterial.cs | 22 +- .../Schema/Extensions/glTF_VGO_materials.cs | 23 ++ .../Extensions/glTF_VGO_materials.cs.meta | 11 + .../Extensions/glTF_VRMC_materials_mtoon.cs | 256 +++++++++++++ .../glTF_VRMC_materials_mtoon.cs.meta | 11 + .../Schema/glTFPbrMetallicRoughness.cs | 11 +- .../Runtime/Schema/glTFTextureInfo.cs | 6 +- .../Serialization/VgoContractResolver.cs | 8 + UniVgo/README.ja.md | 28 +- UniVgo/README.md | 30 +- UniVgo/Runtime/IO/VgoExporter.cs | 17 +- UniVgo/Runtime/IO/VgoImporter.cs | 1 + UniVgo/Runtime/IO/VgoMaterialExporter.cs | 307 +++++++++++++++ UniVgo/Runtime/IO/VgoMaterialExporter.cs.meta | 11 + UniVgo/Runtime/IO/VgoMaterialImporter.cs | 350 ++++++++++++++++++ UniVgo/Runtime/IO/VgoMaterialImporter.cs.meta | 11 + UniVgo/Runtime/IO/VgoShaderStore.cs | 192 ++++++++++ UniVgo/Runtime/IO/VgoShaderStore.cs.meta | 11 + UniVgo/Runtime/UniVgo.asmdef | 1 + UniVgo/Runtime/Utils/MaterialAlphaMode.cs | 21 ++ .../Runtime/Utils/MaterialAlphaMode.cs.meta | 11 + UniVgo/Runtime/Utils/ShaderName.cs | 45 +++ UniVgo/Runtime/Utils/ShaderName.cs.meta | 11 + UniVgo/Runtime/Vgo.cs | 2 +- UniVgo/Runtime/VgoVersion.cs | 4 +- package.json | 2 +- 45 files changed, 2280 insertions(+), 93 deletions(-) create mode 100644 Documentation~/VGO/specification/0.4/schema/VRMC_materials_mtoon.schema.json create mode 100644 Documentation~/VGO/specification/0.4/schema/material.vgo.schema.json create mode 100644 Documentation~/VGO/specification/0.4/schema/materials.extensions.schema.json create mode 100644 Documentation~/VGO/specification/0.4/schema/node.vgo.collider.schema.json create mode 100644 Documentation~/VGO/specification/0.4/schema/node.vgo.colliders.schema.json create mode 100644 Documentation~/VGO/specification/0.4/schema/node.vgo.gameobject.schema.json create mode 100644 Documentation~/VGO/specification/0.4/schema/node.vgo.light.schema.json create mode 100644 Documentation~/VGO/specification/0.4/schema/node.vgo.physicMaterial.schema.json create mode 100644 Documentation~/VGO/specification/0.4/schema/node.vgo.rigidbody.schema.json create mode 100644 Documentation~/VGO/specification/0.4/schema/nodes.extensions.vgo_nodes.schema.json create mode 100644 Documentation~/VGO/specification/0.4/schema/vgo.meta.schema.json create mode 100644 Documentation~/VGO/specification/0.4/schema/vgo.right.schema.json create mode 100644 Documentation~/VGO/specification/0.4/schema/vgo.schema.json create mode 100644 UniGLTFforUniVgo/Runtime/Schema/Extensions/glTF_VGO_materials.cs create mode 100644 UniGLTFforUniVgo/Runtime/Schema/Extensions/glTF_VGO_materials.cs.meta create mode 100644 UniGLTFforUniVgo/Runtime/Schema/Extensions/glTF_VRMC_materials_mtoon.cs create mode 100644 UniGLTFforUniVgo/Runtime/Schema/Extensions/glTF_VRMC_materials_mtoon.cs.meta create mode 100644 UniVgo/Runtime/IO/VgoMaterialExporter.cs create mode 100644 UniVgo/Runtime/IO/VgoMaterialExporter.cs.meta create mode 100644 UniVgo/Runtime/IO/VgoMaterialImporter.cs create mode 100644 UniVgo/Runtime/IO/VgoMaterialImporter.cs.meta create mode 100644 UniVgo/Runtime/IO/VgoShaderStore.cs create mode 100644 UniVgo/Runtime/IO/VgoShaderStore.cs.meta create mode 100644 UniVgo/Runtime/Utils/MaterialAlphaMode.cs create mode 100644 UniVgo/Runtime/Utils/MaterialAlphaMode.cs.meta create mode 100644 UniVgo/Runtime/Utils/ShaderName.cs create mode 100644 UniVgo/Runtime/Utils/ShaderName.cs.meta diff --git a/CHANGELOG.md b/CHANGELOG.md index 9983b27..1098528 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [0.6.0] - 2020-01-17 +- Added `VGO_materials` property to materials extension. +- Added `VRMC_materials_mtoon` property to materials extension. + ## [0.5.0] - 2020-01-14 - Added `light` property to VGO_nodes extension. diff --git a/Documentation~/VGO/specification/0.4/schema/VRMC_materials_mtoon.schema.json b/Documentation~/VGO/specification/0.4/schema/VRMC_materials_mtoon.schema.json new file mode 100644 index 0000000..4041d9b --- /dev/null +++ b/Documentation~/VGO/specification/0.4/schema/VRMC_materials_mtoon.schema.json @@ -0,0 +1,212 @@ +{ + "VRM.VRMC_materials_mtoon": { + "title": "VRMC_materials_mtoon", + "type": "object", + "description": "", + "properties": { + "version": { + "type": "string", + "description": "Meta" + }, + "renderMode": { + "title": "RenderMode", + "type": "string", + "enum": [ + "opaque", + "cutout", + "transparent", + "transparentWithZWrite" + ], + "description": "Rendering" + }, + "cullMode": { + "title": "CullMode", + "type": "string", + "enum": [ + "off", + "front", + "back" + ] + }, + "renderQueueOffsetNumber": { + "type": "integer", + "description": "" + }, + "litFactor": { + "type": "array", + "description": "Color", + "items": { + "type": "number" + } + }, + "litMultiplyTexture": { + "type": "integer", + "description": "" + }, + "shadeFactor": { + "type": "array", + "description": "", + "items": { + "type": "number" + } + }, + "shadeMultiplyTexture": { + "type": "integer", + "description": "" + }, + "cutoutThresholdFactor": { + "type": "number", + "description": "" + }, + "shadingShiftFactor": { + "type": "number", + "description": "Lighting" + }, + "shadingToonyFactor": { + "type": "number", + "description": "" + }, + "shadowReceiveMultiplierFactor": { + "type": "number", + "description": "" + }, + "shadowReceiveMultiplierMultiplyTexture": { + "type": "integer", + "description": "" + }, + "litAndShadeMixingMultiplierFactor": { + "type": "number", + "description": "" + }, + "litAndShadeMixingMultiplierMultiplyTexture": { + "type": "integer", + "description": "" + }, + "lightColorAttenuationFactor": { + "type": "number", + "description": "" + }, + "giIntensityFactor": { + "type": "number", + "description": "" + }, + "normalTexture": { + "type": "integer", + "description": "Normal" + }, + "normalScaleFactor": { + "type": "number", + "description": "" + }, + "emissionFactor": { + "type": "array", + "description": "Emission", + "items": { + "type": "number" + } + }, + "emissionMultiplyTexture": { + "type": "integer", + "description": "" + }, + "additiveTexture": { + "type": "integer", + "description": "MatCap" + }, + "rimFactor": { + "type": "array", + "description": "Rim", + "items": { + "type": "number" + } + }, + "rimMultiplyTexture": { + "type": "integer", + "description": "" + }, + "rimLightingMixFactor": { + "type": "number", + "description": "" + }, + "rimFresnelPowerFactor": { + "type": "number", + "description": "" + }, + "rimLiftFactor": { + "type": "number", + "description": "" + }, + "outlineWidthMode": { + "title": "OutlineWidthMode", + "type": "string", + "enum": [ + "none", + "worldCoordinates", + "screenCoordinates" + ], + "description": "Outline" + }, + "outlineWidthFactor": { + "type": "number", + "description": "" + }, + "outlineWidthMultiplyTexture": { + "type": "integer", + "description": "" + }, + "outlineScaledMaxDistanceFactor": { + "type": "number", + "description": "" + }, + "outlineColorMode": { + "title": "OutlineColorMode", + "type": "string", + "enum": [ + "fixedColor", + "mixedLighting" + ] + }, + "outlineFactor": { + "type": "array", + "description": "", + "items": { + "type": "number" + } + }, + "outlineLightingMixFactor": { + "type": "number", + "description": "" + }, + "mainTextureLeftBottomOriginScale": { + "type": "array", + "description": "TextureUvCoords", + "items": { + "type": "number" + } + }, + "mainTextureLeftBottomOriginOffset": { + "type": "array", + "description": "", + "items": { + "type": "number" + } + }, + "uvAnimationMaskTexture": { + "type": "integer", + "description": "" + }, + "uvAnimationScrollXSpeedFactor": { + "type": "number", + "description": "" + }, + "uvAnimationScrollYSpeedFactor": { + "type": "number", + "description": "" + }, + "uvAnimationRotationSpeedFactor": { + "type": "number", + "description": "" + } + } + } +} \ No newline at end of file diff --git a/Documentation~/VGO/specification/0.4/schema/material.vgo.schema.json b/Documentation~/VGO/specification/0.4/schema/material.vgo.schema.json new file mode 100644 index 0000000..d99c1d0 --- /dev/null +++ b/Documentation~/VGO/specification/0.4/schema/material.vgo.schema.json @@ -0,0 +1,11 @@ +{ + "title": "material.vgo", + "description": "Material VGO.", + "type": "object", + "properties": { + "shaderName": { + "description": "The name of the shader.", + "type": "string" + } + } +} \ No newline at end of file diff --git a/Documentation~/VGO/specification/0.4/schema/materials.extensions.schema.json b/Documentation~/VGO/specification/0.4/schema/materials.extensions.schema.json new file mode 100644 index 0000000..4606c5f --- /dev/null +++ b/Documentation~/VGO/specification/0.4/schema/materials.extensions.schema.json @@ -0,0 +1,16 @@ +{ + "title": "materials.extensions", + "description": "glTF material extension.", + "type": "object", + "properties": { + "KHR_materials_unlit": { + "$ref": "glTF.KHR_materials_unlit.schema.json" + }, + "VGO_materials": { + "$ref": "material.vgo.schema.json" + }, + "VRMC_materials_mtoon": { + "$ref": "VRMC_materials_mtoon.schema.json" + } + } +} \ No newline at end of file diff --git a/Documentation~/VGO/specification/0.4/schema/node.vgo.collider.schema.json b/Documentation~/VGO/specification/0.4/schema/node.vgo.collider.schema.json new file mode 100644 index 0000000..f6b40bc --- /dev/null +++ b/Documentation~/VGO/specification/0.4/schema/node.vgo.collider.schema.json @@ -0,0 +1,51 @@ +{ + "title": "node.vgo.collider", + "description": "Node collider.", + "type": "object", + "properties": { + "type": { + "description": "Type of collider.", + "type": "string", + "enum": ["Box","Capsule","Sphere"] + }, + "enabled": { + "description": "Whether collider is enabled.", + "type": "boolean" + }, + "isTrigger": { + "description": "Is the collider a trigger?", + "type": "boolean" + }, + "center": { + "description": "The center of the collider. [x, y, z]", + "type": "array", + "items": { + "type": "number" + } + }, + "size": { + "description": "The total size of the box. [x, y, z]", + "type": "array", + "items": { + "type": "number" + } + }, + "radius": { + "description": "The radius of the capsule or sphere, measured in the object's local space.", + "type": "number", + "minimum": 0 + }, + "height": { + "description": "The height of the capsule, measured in the object's local space.", + "type": "number", + "minimum": 0 + }, + "direction": { + "description": "The direction of the capsule. [0:x, 1:y, 2:z]", + "type": "integer" + }, + "physicMaterial": { + "$ref": "node.vgo.physicMaterial.schema.json" + } + } +} \ No newline at end of file diff --git a/Documentation~/VGO/specification/0.4/schema/node.vgo.colliders.schema.json b/Documentation~/VGO/specification/0.4/schema/node.vgo.colliders.schema.json new file mode 100644 index 0000000..8e92d7c --- /dev/null +++ b/Documentation~/VGO/specification/0.4/schema/node.vgo.colliders.schema.json @@ -0,0 +1,8 @@ +{ + "title": "node.vgo.colliders", + "description": "Node colliders.", + "type": "array", + "items": { + "$ref": "node.vgo.collider.schema.json" + } +} \ No newline at end of file diff --git a/Documentation~/VGO/specification/0.4/schema/node.vgo.gameobject.schema.json b/Documentation~/VGO/specification/0.4/schema/node.vgo.gameobject.schema.json new file mode 100644 index 0000000..3547a3e --- /dev/null +++ b/Documentation~/VGO/specification/0.4/schema/node.vgo.gameobject.schema.json @@ -0,0 +1,25 @@ +{ + "title": "node.vgo.gameobject", + "description": "Node GameObject.", + "type": "object", + "properties": { + "isActive": { + "description": "Whether GameObject is active.", + "type": "boolean" + }, + "isStatic": { + "description": "Whether GameObject is static.", + "type": "boolean" + }, + "tag": { + "description": "Tag attached to GameObject.", + "type": "string" + } + "layer": { + "description": "Index of the layer where GameObject is located.", + "type": "integer", + "minimum": 0, + "maximum": 31 + } + } +} \ No newline at end of file diff --git a/Documentation~/VGO/specification/0.4/schema/node.vgo.light.schema.json b/Documentation~/VGO/specification/0.4/schema/node.vgo.light.schema.json new file mode 100644 index 0000000..04b4a0c --- /dev/null +++ b/Documentation~/VGO/specification/0.4/schema/node.vgo.light.schema.json @@ -0,0 +1,110 @@ +{ + "title": "node.vgo.light", + "description": "Node light.", + "type": "object", + "properties": { + "enabled": { + "description": "Whether the light is enable.", + "type": "boolean", + }, + "type": { + "description": "The type of the light.", + "type": "string", + "enum": ["Spot","Directional","Point","Rectangle","Disc"] + }, + "shape": { + "description": "This property describes the shape of the spot light.", + "type": "string", + "enum": ["Cone","Pyramid","Box"] + }, + "range": { + "description": "The range of the light.", + "type": "number", + "minimum": 0 + }, + "spotAngle": { + "description": "The angle of the light's spotlight cone in degrees.", + "type": "number", + "minimum": 0 + }, + "areaSize": { + "description": "The size of the area light. [x, y]", + "type": "array", + "items": { + "type": "number" + } + }, + "areaRadius": { + "description": "The radius of the area light.", + "type": "number", + "minimum": 0 + }, + "color": { + "description": "The color of the light. [r, g, b, a]", + "type": "array", + "items": { + "type": "number" + } + }, + "lightmapBakeType": { + "description": "This property describes what part of a light's contribution can be baked.", + "type": "string", + "enum": ["Realtime","Baked","Mixed"] + }, + "intensity": { + "description": "The Intensity of a light is multiplied with the Light color.", + "type": "number", + "minimum": 0 + }, + "bounceIntensity": { + "description": "The multiplier that defines the strength of the bounce lighting.", + "type": "number", + "minimum": 0 + }, + "shadows": { + "description": "How this light casts shadows.", + "type": "string", + "enum": ["None","Hard","Soft"] + }, + "shadowAngle": { + "description": "Controls the amount of artificial softening applied to the edges of shadows cast by directional lights.", + "type": "number", + "minimum": 0 + }, + "shadowStrength": { + "description": "Strength of light's shadows.", + "type": "number", + "minimum": 0 + }, + "shadowResolution": { + "description": "The resolution of the shadow map.", + "type": "string", + "enum": ["FromQualitySettings","Low","Medium","High","VeryHigh"] + }, + "shadowBias": { + "description": "Shadow mapping constant bias.", + "type": "number", + "minimum": 0 + }, + "shadowNormalBias": { + "description": "Shadow mapping normal-based bias.", + "type": "number", + "minimum": 0 + }, + "shadowNearPlane": { + "description": "Near plane value to use for shadow frustums.", + "type": "number", + "minimum": 0 + }, + "renderMode": { + "description": "How to render the light.", + "type": "string", + "enum": ["Auto","ForcePixel","ForceVertex"] + }, + "cullingMask": { + "description": "This is used to light certain objects in the Scene selectively.", + "type": "integer", + "minimum": -1 + } + } +} \ No newline at end of file diff --git a/Documentation~/VGO/specification/0.4/schema/node.vgo.physicMaterial.schema.json b/Documentation~/VGO/specification/0.4/schema/node.vgo.physicMaterial.schema.json new file mode 100644 index 0000000..08c45d2 --- /dev/null +++ b/Documentation~/VGO/specification/0.4/schema/node.vgo.physicMaterial.schema.json @@ -0,0 +1,35 @@ +{ + "title": "node.vgo.physicMaterial", + "description": "Physic material.", + "type": "object", + "properties": { + "dynamicFriction": { + "description": "The friction used when already moving.", + "type": "number", + "minimum": 0, + "maximum": 1 + }, + "staticFriction": { + "description": "The friction coefficient used when an object is lying on a surface.", + "type": "number", + "minimum": 0, + "maximum": 1 + }, + "bounciness": { + "description": "How bouncy is the surface?", + "type": "number", + "minimum": 0, + "maximum": 1 + }, + "frictionCombine": { + "description": "Determines how the friction is combined.", + "type": "string", + "enum": ["Average","Multiply","Minimum","Maximum"] + }, + "bounceCombine": { + "description": "Determines how the bounciness is combined.", + "type": "string", + "enum": ["Average","Multiply","Minimum","Maximum"] + } + } +} \ No newline at end of file diff --git a/Documentation~/VGO/specification/0.4/schema/node.vgo.rigidbody.schema.json b/Documentation~/VGO/specification/0.4/schema/node.vgo.rigidbody.schema.json new file mode 100644 index 0000000..972f501 --- /dev/null +++ b/Documentation~/VGO/specification/0.4/schema/node.vgo.rigidbody.schema.json @@ -0,0 +1,47 @@ +{ + "title": "node.vgo.rigidbody", + "description": "Node rigidbody.", + "type": "object", + "properties": { + "mass": { + "description": "The mass of the body. [0.0000001, 1000000000]", + "type": "number", + "minimum": 0.0000001, + "maximum": 1000000000 + }, + "drag": { + "description": "The linear drag coefficient. [0, infinity]", + "type": "number", + "minimum": 0 + }, + "angularDrag": { + "description": "The angular drag coefficient. [0, infinity]", + "type": "number", + "minimum": 0 + }, + "useGravity": { + "description": "Controls whether gravity affects this rigidbody.", + "type": "boolean" + }, + "isKinematic": { + "description": "Controls whether physics affects the rigidbody.", + "type": "boolean" + }, + "interpolation": { + "description": "Interpolation allows you to smooth out the effect of running physics at a fixed frame rate.", + "type": "string", + "enum": ["None","Interpolate","Extrapolate"] + }, + "collisionDetectionMode": { + "description": "The Rigidbody's collision detection mode.", + "type": "string", + "enum": ["Discrete","Continuous","ContinuousDynamic","ContinuousSpeculative"] + }, + "constraints": { + "description": "The flags to constrain motion of rigidbodies. [2|4|8|16|32|64]", + "type": "integer", + "minimum": 0, + "maximum": 126 + } + } +} \ No newline at end of file diff --git a/Documentation~/VGO/specification/0.4/schema/nodes.extensions.vgo_nodes.schema.json b/Documentation~/VGO/specification/0.4/schema/nodes.extensions.vgo_nodes.schema.json new file mode 100644 index 0000000..e38624f --- /dev/null +++ b/Documentation~/VGO/specification/0.4/schema/nodes.extensions.vgo_nodes.schema.json @@ -0,0 +1,22 @@ +{ + "title": "nodes.extensions.VGO_nodes", + "description": "Node extension for VGO.", + "type": "object", + "properties": { + "gameObject": { + "$ref": "node.vgo.gameobject.schema.json" + }, + "colliders": { + "$ref": "node.vgo.colliders.schema.json" + }, + "rigidbody": { + "$ref": "node.vgo.rigidbody.schema.json" + }, + "light": { + "$ref": "node.vgo.light.schema.json" + }, + "right": { + "$ref": "vgo.right.schema.json" + } + } +} \ No newline at end of file diff --git a/Documentation~/VGO/specification/0.4/schema/vgo.meta.schema.json b/Documentation~/VGO/specification/0.4/schema/vgo.meta.schema.json new file mode 100644 index 0000000..522f9f3 --- /dev/null +++ b/Documentation~/VGO/specification/0.4/schema/vgo.meta.schema.json @@ -0,0 +1,19 @@ +{ + "title": "vgo.meta", + "description": "VGO meta information.", + "type": "object", + "properties": { + "generatorName": { + "description": "The VGO generator name.", + "type": "string" + }, + "generatorVersion": { + "description": "The VGO generator version.", + "type": "string" + }, + "specVersion": { + "description": "The VGO specification version.", + "type": "string" + } + } +} \ No newline at end of file diff --git a/Documentation~/VGO/specification/0.4/schema/vgo.right.schema.json b/Documentation~/VGO/specification/0.4/schema/vgo.right.schema.json new file mode 100644 index 0000000..47e1c63 --- /dev/null +++ b/Documentation~/VGO/specification/0.4/schema/vgo.right.schema.json @@ -0,0 +1,39 @@ +{ + "title": "vgo.right", + "description": "Rights information.", + "type": "object", + "properties": { + "title": { + "description": "The name of the model.", + "type": "string" + }, + "author": { + "description": "The name of the model creator.", + "type": "string" + }, + "organization": { + "description": "Organization to which the creator belongs.", + "type": "string" + }, + "createdDate": { + "description": "The date this model was created.", + "type": "string" + }, + "updatedDate": { + "description": "The date this model was updated.", + "type": "string" + }, + "version": { + "description": "The version of this model.", + "type": "string" + }, + "distributionUrl": { + "description": "Distribution URL for this model.", + "type": "string" + }, + "licenseUrl": { + "description": "URL that describes the license for this model.", + "type": "string" + } + } +} \ No newline at end of file diff --git a/Documentation~/VGO/specification/0.4/schema/vgo.schema.json b/Documentation~/VGO/specification/0.4/schema/vgo.schema.json new file mode 100644 index 0000000..b395fc8 --- /dev/null +++ b/Documentation~/VGO/specification/0.4/schema/vgo.schema.json @@ -0,0 +1,13 @@ +{ + "title": "vgo", + "description": "glTF extension for VGO.", + "type": "object", + "properties": { + "meta": { + "$ref": "vgo.meta.schema.json" + }, + "right": { + "$ref": "vgo.right.schema.json" + } + } +} \ No newline at end of file diff --git a/README.ja.md b/README.ja.md index 8bbc46a..396ed62 100644 --- a/README.ja.md +++ b/README.ja.md @@ -6,6 +6,7 @@ VGO とは、Collider と Rigidbody の情報を格納可能な Unity 向け3D - glTF (GLB) 2.0 の拡張フォーマットになります。 - ノードに Collider, Rigidbody, Light, 権利情報に関する拡張定義を追加しています。 - Unity の GameObject の Transform, Rigidbody, Collider, PhysicMaterial, Mesh, Material, Texture, Light を保存することができます。 +- Standard, Unlit, MToon のシェーダー設定を保存することができます。 ___ ## glTFのJSONスキーマ @@ -16,17 +17,21 @@ ___ |定義名|説明| |:---|:---| -|KHR_materials_unlit|マテリアルに Unlit シェーダーを使用可能であるという宣言です。| |VGO|VGO を使用するという宣言です。| |VGO_nodes|VGO_nodes を使用するという宣言です。| +|VGO_materials|VGO_materials を使用するという宣言です。| +|KHR_materials_unlit|マテリアルに Unlit シェーダーを使用可能であるという宣言です。| +|VRMC_materials_mtoon|マテリアルに MToon シェーダーを使用可能であるという宣言です。| ### glTF.extensionsRequired |定義名|説明| |:---|:---| -|KHR_materials_unlit|KHR_materials_unlit 拡張へのサポートを必要とします。| |VGO|VGO 拡張へのサポートを必要とします。| |VGO_nodes|VGO_nodes 拡張へのサポートを必要とします。| +|VGO_materials|VGO_materials 拡張へのサポートを必要とします。| +|KHR_materials_unlit|KHR_materials_unlit 拡張へのサポートを必要とします。| +|VRMC_materials_mtoon|VRMC_materials_mtoon 拡張へのサポートを必要とします。| ### glTF.extensions @@ -61,7 +66,9 @@ ___ |定義名|説明| |:---|:---| -|KHR_materials_unlit|Unlitマテリアル情報| +|KHR_materials_unlit|Unlit マテリアル情報| +|VGO_materials|VGO マテリアル情報| +|VRMC_materials_mtoon|MToon マテリアル情報| ___ ## 拡張定義の詳細 @@ -71,8 +78,8 @@ ___ |定義名|説明|型|固定値| |:---|:---|:---:|:---:| |generatorName|生成ツールの名前です。|string|UniVGO| -|generatorVersion|生成ツールのバージョンです。|string|0.5.0| -|specVersion|VGOの仕様バージョンです。|string|0.3| +|generatorVersion|生成ツールのバージョンです。|string|0.6.0| +|specVersion|VGOの仕様バージョンです。|string|0.4| ### vgo.right(権利情報) @@ -129,7 +136,7 @@ ___ |angularDrag|トルクによって回転する際にオブジェクトに影響する空気抵抗の大きさです。|float|[0.0, infinity]| |useGravity|オブジェクトが重力の影響を受けるかどうか。|bool|true / false| |isKinematic|物理が剛体に影響を与えるかどうかどうか。|bool|true / false| -|interpolation|補完のタイプです。|string|none / interpolate / extrapolate| +|interpolation|補完のタイプです。|string|None / Interpolate / Extrapolate| |collisionDetectionMode|衝突の検知のモードです。|string|Discrete / Continuous / ContinuousDynamic / ContinuousSpeculative| |constraints|剛体の動きを制限するフラグです。|int|FreesePositionX(2) \| FreesePositionY(4) \| FreesePositionZ(8) \| FreeseRotationX(16) \| FreeseRotationY(32) \| FreeseRotationZ(64)| @@ -161,6 +168,59 @@ ___ Cookie, Flare, Halo は対象外です。 +### VGO_materials + +|定義名|説明|型|備考| +|:---|:---|:---:|:---:| +|shaderName|シェーダー名。|string|| + +### VRMC_materials_mtoon + +|定義名|説明|型|設定値|既定値| +|:---|:---|:---:|:---:|:---:| +|version||string||32| +|renderMode||string|opaque / cutout / transparent / transparentWithZWrite|opaque| +|cullMode||string|off / flont / back|off| +|renderQueueOffsetNumber||int||| +|litFactor||float[4]|[r, g, b, a]|| +|litMultiplyTexture||int||| +|shadeFactor||float[4]|[r, g, b, a]|| +|shadeMultiplyTexture||int||| +|cutoutThresholdFactor||float|[0.0, 1.0]|| +|shadingShiftFactor||float|[-1.0, 1.0]|| +|shadingToonyFactor||float|[0.0, 1.0]|| +|shadowReceiveMultiplierFactor||float|[0.0, 1.0]|| +|shadowReceiveMultiplierMultiplyTexture||int||| +|litAndShadeMixingMultiplierFactor||float|[0.0, 1.0]|| +|litAndShadeMixingMultiplierMultiplyTexture||int||| +|lightColorAttenuationFactor||float|[0.0, 1.0]|| +|giIntensityFactor||float|[0.0, 1.0]|| +|normalTexture||int||| +|normalScaleFactor||float||| +|emissionFactor||float[3]|[r, g, b]|| +|emissionMultiplyTexture||int||| +|additiveTexture||int||| +|rimFactor||float[4]|[r, g, b, a]|| +|rimMultiplyTexture||int||| +|rimLightingMixFactor||float|[0.0, 1.0]|| +|rimFresnelPowerFactor||float|[0.0, 100.0]|| +|rimLiftFactor||float|[0.0, 1.0]|| +|outlineWidthMode||string|none / worldCoordinates / screenCoordinates|none| +|outlineWidthFactor||float|[0.01, 1.0]|| +|outlineWidthMultiplyTexture||int||| +|outlineScaledMaxDistanceFactor||float|[1.0, 10.0]|| +|outlineColorMode||string|fixedColor / mixedLighting|fixedColor| +|outlineFactor||float[4]|[r, g, b, a]|| +|outlineLightingMixFactor||float|[0.0, 1.0]|| +|mainTextureLeftBottomOriginScale||float[2]|[x, y]|| +|mainTextureLeftBottomOriginOffset||float[2]|[x, y]|| +|uvAnimationMaskTexture||int||| +|uvAnimationScrollXSpeedFactor||float||| +|uvAnimationScrollYSpeedFactor||float||| +|uvAnimationRotationSpeedFactor||float||| + +https://github.com/vrm-c/vrm-specification + ___ ## glTFのJSONの構造例 @@ -173,29 +233,33 @@ JSON{ "buffers": [ ], "extensionsUsed": [ - "KHR_materials_unlit", "VGO", - "VGO_nodes" + "VGO_nodes", + "VGO_materials", + "KHR_materials_unlit", + "VRMC_materials_mtoon" ], "extensionsRequired": [ - "KHR_materials_unlit", "VGO", - "VGO_nodes" + "VGO_nodes", + "VGO_materials", + "KHR_materials_unlit", + "VRMC_materials_mtoon" ], "extensions": { "VGO": { "meta": { "generatorName": "UniVGO", - "generatorVersion": "0.5.0", - "specVersion": "0.3" + "generatorVersion": "0.6.0", + "specVersion": "0.4" }, "right": { "title": "Test Stage", "author": "Izayoi Jiichan", "organization": "Izayoi", "createdDate": "2020-01-01", - "updatedDate": "2020-01-14", - "version": "1.2", + "updatedDate": "2020-01-17", + "version": "1.3", "distributionUrl": "https://github.com/izayoijiichan/VGO", "licenseUrl": "https://github.com/izayoijiichan/VGO/blob/master/UniVgo/LICENSE.md" } @@ -257,7 +321,7 @@ JSON{ "shape":"", "range":1.0, "spotAngle":0.0, - "areaSize":0.0, + "areaSize":[ 0.0, 0.0 ], "areaRadius":0.0, "color":[ 0.122,0.404,0.637,1.0 ], "lightmapBakeType":"Realtime", @@ -279,8 +343,8 @@ JSON{ "author": "Izayoi Jiichan", "organization": "", "createdDate": "2020-01-01", - "updatedDate": "2020-01-14", - "version": "0.3", + "updatedDate": "2020-01-17", + "version": "0.4", "distributionUrl": "", "licenseUrl": "" } @@ -297,7 +361,7 @@ JSON{ JSON{ "materials": [ { - "name": "UnlitMaterial1", + "name": "MtoonMaterial1", "pbrMetallicRoughness": { "baseColorTexture": { "index": 0, @@ -311,7 +375,52 @@ JSON{ "alphaCutoff": 0.5, "doubleSided": false, "extensions": { - "KHR_materials_unlit": {} + "KHR_materials_unlit": {}, + "VGO_materials":{ + "shaderName":"VRM/MToon" + }, + "VRMC_materials_mtoon":{ + "version":"32", + "renderMode":"opaque", + "cullMode":"back", + "renderQueueOffsetNumber":0, + "litFactor":[ 0.811,0.916,0.723,1.0 ], + "litMultiplyTexture":0, + "shadeFactor":[ 0.933,0.620,0.711,1.0 ], + "shadeMultiplyTexture":-1, + "cutoutThresholdFactor":0.5, + "shadingShiftFactor":0.0, + "shadingToonyFactor":0.9, + "shadowReceiveMultiplierFactor":1.0, + "shadowReceiveMultiplierMultiplyTexture":-1, + "litAndShadeMixingMultiplierFactor":1.0, + "litAndShadeMixingMultiplierMultiplyTexture":-1, + "lightColorAttenuationFactor":0.0, + "giIntensityFactor":0.1, + "normalTexture":-1, + "normalScaleFactor":1.0, + "emissionFactor":[ 0.0,0.0,0.0,1.0 ], + "emissionMultiplyTexture":-1, + "additiveTexture":-1, + "rimFactor":[ 0.0,0.0,0.0,1.0 ], + "rimMultiplyTexture":-1, + "rimLightingMixFactor":0.0, + "rimFresnelPowerFactor":1.0, + "rimLiftFactor":0.0, + "outlineWidthMode":"screenCoordinates", + "outlineWidthFactor":0.5, + "outlineWidthMultiplyTexture":-1, + "outlineScaledMaxDistanceFactor":1.0, + "outlineColorMode":"fixedColor", + "outlineFactor":[ 0.0,0.0,0.0,1.0 ], + "outlineLightingMixFactor":1.0, + "mainTextureLeftBottomOriginScale":[ 1.0,1.0 ], + "mainTextureLeftBottomOriginOffset":[ 0.0,0.0 ], + "uvAnimationMaskTexture":-1, + "uvAnimationScrollXSpeedFactor":0.0, + "uvAnimationScrollYSpeedFactor":0.0, + "uvAnimationRotationSpeedFactor":0.0 + } } } ] @@ -336,7 +445,7 @@ VGOファイルの中身を確認するためのツールです。 https://github.com/izayoijiichan/vgo.parameter.viewer ___ -最終更新日:2020年1月14日 +最終更新日:2020年1月17日 編集者:十六夜おじいちゃん *Copyright (C) 2020 Izayoi Jiichan. All Rights Reserved.* diff --git a/README.md b/README.md index 49835cb..18b75bb 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ VGO is a 3D data format for Unity that can store Collider and Rigidbody informat - glTF (GLB) 2.0 extended format. - Added extended definitions for Collider, Rigidbody, Light and rights information to nodes. - Unity GameObject Transform, Rigidbody, Collider, PhysicMaterial, Mesh, Material, Texture, Light can be saved. +- Standard, Unlit and MToon shader settings can be saved. + ___ ## JSON schema of glTF @@ -15,17 +17,21 @@ The following extended definitions are added: |Definition name|Description| |:---|:---| -|KHR_materials_unlit|Declares that Unlit shaders can be used for materials.| |VGO|Declaration to use VGO.| |VGO_nodes|Declaration to use VGO_nodes.| +|VGO_materials|Declaration to use VGO_materials.| +|KHR_materials_unlit|Declares that Unlit shaders can be used for materials.| +|VRMC_materials_mtoon|Declares that MToon shaders can be used for materials.| ### glTF.extensionsRequired |Definition name|Description| |:---|:---| -|KHR_materials_unlit|Requires support for the KHR_materials_unlit extension.| |VGO|Requires support for VGO extensions.| |VGO_nodes|Requires support for VGO_nodes extension.| +|VGO_materials|Requires support for VGO_materials extension.| +|KHR_materials_unlit|Requires support for the KHR_materials_unlit extension.| +|VRMC_materials_mtoon|Requires support for the VRMC_materials_mtoon extension.| ### glTF.extensions @@ -61,7 +67,8 @@ The following extended definitions are added: |definition name|description| |:---|:---| |KHR_materials_unlit|Unlit material information| - +|VGO_materials|VGO material information| +|VRMC_materials_mtoon|MToon material information| ___ ## Extended definition details @@ -70,8 +77,8 @@ ___ |definition name|description|type|fixed value| |:---|:---|:---:|:---:| |generatorName|The name of the generation tool.|string|UniVGO| -|generatorVersion|The generation tool version.|string|0.5.0| -|specVersion|VGO specification version.|string|0.3| +|generatorVersion|The generation tool version.|string|0.6.0| +|specVersion|VGO specification version.|string|0.4| ### vgo.right @@ -160,6 +167,59 @@ ___ Cookie, Flare, Halo are not supported. +### VGO_materials + +|definition name|description|type|remarks| +|:---|:---|:---:|:---:| +|shaderName|The name of shader.|string|| + +### VRMC_materials_mtoon + +|definition name|description|type|setting value|default value| +|:---|:---|:---:|:---:|:---:| +|version||string||32| +|renderMode||string|opaque / cutout / transparent / transparentWithZWrite|opaque| +|cullMode||string|off / flont / back|off| +|renderQueueOffsetNumber||int||| +|litFactor||float[4]|[r, g, b, a]|| +|litMultiplyTexture||int||| +|shadeFactor||float[4]|[r, g, b, a]|| +|shadeMultiplyTexture||int||| +|cutoutThresholdFactor||float|[0.0, 1.0]|| +|shadingShiftFactor||float|[-1.0, 1.0]|| +|shadingToonyFactor||float|[0.0, 1.0]|| +|shadowReceiveMultiplierFactor||float|[0.0, 1.0]|| +|shadowReceiveMultiplierMultiplyTexture||int||| +|litAndShadeMixingMultiplierFactor||float|[0.0, 1.0]|| +|litAndShadeMixingMultiplierMultiplyTexture||int||| +|lightColorAttenuationFactor||float|[0.0, 1.0]|| +|giIntensityFactor||float|[0.0, 1.0]|| +|normalTexture||int||| +|normalScaleFactor||float||| +|emissionFactor||float[3]|[r, g, b]|| +|emissionMultiplyTexture||int||| +|additiveTexture||int||| +|rimFactor||float[4]|[r, g, b, a]|| +|rimMultiplyTexture||int||| +|rimLightingMixFactor||float|[0.0, 1.0]|| +|rimFresnelPowerFactor||float|[0.0, 100.0]|| +|rimLiftFactor||float|[0.0, 1.0]|| +|outlineWidthMode||string|none / worldCoordinates / screenCoordinates|none| +|outlineWidthFactor||float|[0.01, 1.0]|| +|outlineWidthMultiplyTexture||int||| +|outlineScaledMaxDistanceFactor||float|[1.0, 10.0]|| +|outlineColorMode||string|fixedColor / mixedLighting|fixedColor| +|outlineFactor||float[4]|[r, g, b, a]|| +|outlineLightingMixFactor||float|[0.0, 1.0]|| +|mainTextureLeftBottomOriginScale||float[2]|[x, y]|| +|mainTextureLeftBottomOriginOffset||float[2]|[x, y]|| +|uvAnimationMaskTexture||int||| +|uvAnimationScrollXSpeedFactor||float||| +|uvAnimationScrollYSpeedFactor||float||| +|uvAnimationRotationSpeedFactor||float||| + +https://github.com/vrm-c/vrm-specification + ___ ## Example of glTF JSON structure @@ -172,29 +232,33 @@ JSON{ "buffers": [ ], "extensionsUsed": [ - "KHR_materials_unlit", "VGO", - "VGO_nodes" + "VGO_nodes", + "VGO_materials", + "KHR_materials_unlit", + "VRMC_materials_mtoon" ], "extensionsRequired": [ - "KHR_materials_unlit", "VGO", - "VGO_nodes" + "VGO_nodes", + "VGO_materials", + "KHR_materials_unlit", + "VRMC_materials_mtoon" ], "extensions": { "VGO": { "meta": { "generatorName": "UniVGO", - "generatorVersion": "0.5.0", - "specVersion": "0.3" + "generatorVersion": "0.6.0", + "specVersion": "0.4" }, "right": { "title": "Test Stage", "author": "Izayoi Jiichan", "organization": "Izayoi", "createdDate": "2020-01-01", - "updatedDate": "2020-01-14", - "version": "1.2", + "updatedDate": "2020-01-17", + "version": "1.3", "distributionUrl": "https://github.com/izayoijiichan/VGO", "licenseUrl": "https://github.com/izayoijiichan/VGO/blob/master/UniVgo/LICENSE.md" } @@ -256,7 +320,7 @@ JSON{ "shape":"", "range":1.0, "spotAngle":0.0, - "areaSize":0.0, + "areaSize":[ 0.0, 0.0 ], "areaRadius":0.0, "color":[ 0.122,0.404,0.637,1.0 ], "lightmapBakeType":"Realtime", @@ -278,8 +342,8 @@ JSON{ "author": "Izayoi Jiichan", "organization": "", "createdDate": "2020-01-01", - "updatedDate": "2020-01-14", - "version": "0.3", + "updatedDate": "2020-01-17", + "version": "0.4", "distributionUrl": "", "licenseUrl": "" } @@ -296,7 +360,7 @@ JSON{ JSON{ "materials": [ { - "name": "UnlitMaterial1", + "name": "MtoonMaterial1", "pbrMetallicRoughness": { "baseColorTexture": { "index": 0, @@ -310,7 +374,52 @@ JSON{ "alphaCutoff": 0.5, "doubleSided": false, "extensions": { - "KHR_materials_unlit": {} + "KHR_materials_unlit": {}, + "VGO_materials":{ + "shaderName":"VRM/MToon" + }, + "VRMC_materials_mtoon":{ + "version":"32", + "renderMode":"opaque", + "cullMode":"back", + "renderQueueOffsetNumber":0, + "litFactor":[ 0.811,0.916,0.723,1.0 ], + "litMultiplyTexture":0, + "shadeFactor":[ 0.933,0.620,0.711,1.0 ], + "shadeMultiplyTexture":-1, + "cutoutThresholdFactor":0.5, + "shadingShiftFactor":0.0, + "shadingToonyFactor":0.9, + "shadowReceiveMultiplierFactor":1.0, + "shadowReceiveMultiplierMultiplyTexture":-1, + "litAndShadeMixingMultiplierFactor":1.0, + "litAndShadeMixingMultiplierMultiplyTexture":-1, + "lightColorAttenuationFactor":0.0, + "giIntensityFactor":0.1, + "normalTexture":-1, + "normalScaleFactor":1.0, + "emissionFactor":[ 0.0,0.0,0.0,1.0 ], + "emissionMultiplyTexture":-1, + "additiveTexture":-1, + "rimFactor":[ 0.0,0.0,0.0,1.0 ], + "rimMultiplyTexture":-1, + "rimLightingMixFactor":0.0, + "rimFresnelPowerFactor":1.0, + "rimLiftFactor":0.0, + "outlineWidthMode":"screenCoordinates", + "outlineWidthFactor":0.5, + "outlineWidthMultiplyTexture":-1, + "outlineScaledMaxDistanceFactor":1.0, + "outlineColorMode":"fixedColor", + "outlineFactor":[ 0.0,0.0,0.0,1.0 ], + "outlineLightingMixFactor":1.0, + "mainTextureLeftBottomOriginScale":[ 1.0,1.0 ], + "mainTextureLeftBottomOriginOffset":[ 0.0,0.0 ], + "uvAnimationMaskTexture":-1, + "uvAnimationScrollXSpeedFactor":0.0, + "uvAnimationScrollYSpeedFactor":0.0, + "uvAnimationRotationSpeedFactor":0.0 + } } } ] @@ -335,7 +444,7 @@ It is distributed at the following URL. https://github.com/izayoijiichan/vgo.parameter.viewer ___ -Last updated: 14 January, 2020 +Last updated: 17 January, 2020 Editor: Izayoi Jiichan *Copyright (C) 2020 Izayoi Jiichan. All Rights Reserved.* diff --git a/UniGLTFforUniVgo/Runtime/IO/MaterialExporter.cs b/UniGLTFforUniVgo/Runtime/IO/MaterialExporter.cs index d5ae078..3d1ef7d 100644 --- a/UniGLTFforUniVgo/Runtime/IO/MaterialExporter.cs +++ b/UniGLTFforUniVgo/Runtime/IO/MaterialExporter.cs @@ -33,6 +33,18 @@ public virtual glTFMaterial ExportMaterial(Material m, TextureExportManager text Export_Occlusion(m, textureManager, material); Export_Emission(m, textureManager, material); + if ((material.pbrMetallicRoughness != null) && + (material.pbrMetallicRoughness.baseColorFactor == null) && + (material.pbrMetallicRoughness.baseColorTexture == null) && + (material.pbrMetallicRoughness.metallicFactor == -1.0f) && + (material.pbrMetallicRoughness.roughnessFactor == -1.0f) && + (material.pbrMetallicRoughness.baseColorFactor == null) && + (material.pbrMetallicRoughness.extensions == null) && + (material.pbrMetallicRoughness.extras == null)) + { + material.pbrMetallicRoughness = null; + } + return material; } @@ -195,48 +207,53 @@ protected virtual glTFMaterial CreateMaterial(Material m) /// /// /// + /// /// - static glTFMaterial CreateUnlitMaterialDefault() + static glTFMaterial CreateUnlitMaterialDefault(Material m) { return new glTFMaterial { pbrMetallicRoughness = new glTFPbrMetallicRoughness { - baseColorFactor = new float[] { 1.0f, 1.0f, 1.0f, 1.0f }, - roughnessFactor = 0.9f, - metallicFactor = 0.0f, + //baseColorFactor = new float[] { 1.0f, 1.0f, 1.0f, 1.0f }, + //roughnessFactor = 0.9f, + //metallicFactor = 0.0f, }, extensions = new glTFMaterial_extensions { KHR_materials_unlit = new glTF_KHR_materials_unlit(), + VGO_materials = new glTF_VGO_materials() + { + shaderName = m.shader.name, + } }, }; } static glTFMaterial Export_UnlitColor(Material m) { - var material = CreateUnlitMaterialDefault(); + var material = CreateUnlitMaterialDefault(m); material.alphaMode = glTFBlendMode.OPAQUE.ToString(); return material; } static glTFMaterial Export_UnlitTexture(Material m) { - var material = CreateUnlitMaterialDefault(); + var material = CreateUnlitMaterialDefault(m); material.alphaMode = glTFBlendMode.OPAQUE.ToString(); return material; } static glTFMaterial Export_UnlitTransparent(Material m) { - var material = CreateUnlitMaterialDefault(); + var material = CreateUnlitMaterialDefault(m); material.alphaMode = glTFBlendMode.BLEND.ToString(); return material; } static glTFMaterial Export_UnlitCutout(Material m) { - var material = CreateUnlitMaterialDefault(); + var material = CreateUnlitMaterialDefault(m); material.alphaMode = glTFBlendMode.MASK.ToString(); material.alphaCutoff = m.GetFloat("_Cutoff"); return material; @@ -244,7 +261,7 @@ static glTFMaterial Export_UnlitCutout(Material m) private glTFMaterial Export_UniUnlit(Material m) { - var material = CreateUnlitMaterialDefault(); + var material = CreateUnlitMaterialDefault(m); var renderMode = UniGLTF.UniUnlit.Utils.GetRenderMode(m); if (renderMode == UniUnlitRenderMode.Opaque) @@ -282,6 +299,13 @@ static glTFMaterial Export_Standard(Material m) var material = new glTFMaterial { pbrMetallicRoughness = new glTFPbrMetallicRoughness(), + extensions = new glTFMaterial_extensions + { + VGO_materials = new glTF_VGO_materials() + { + shaderName = m.shader.name, + } + }, }; switch (m.GetTag("RenderType", true)) diff --git a/UniGLTFforUniVgo/Runtime/IO/MaterialImporter.cs b/UniGLTFforUniVgo/Runtime/IO/MaterialImporter.cs index ec36988..4dfdd87 100644 --- a/UniGLTFforUniVgo/Runtime/IO/MaterialImporter.cs +++ b/UniGLTFforUniVgo/Runtime/IO/MaterialImporter.cs @@ -15,7 +15,7 @@ public interface IMaterialImporter public class MaterialImporter : IMaterialImporter { - IShaderStore m_shaderStore; + protected IShaderStore m_shaderStore; ImporterContext m_context; protected ImporterContext Context @@ -29,7 +29,7 @@ public MaterialImporter(IShaderStore shaderStore, ImporterContext context) m_context = context; } - private enum BlendMode + protected enum BlendMode { Opaque, Cutout, diff --git a/UniGLTFforUniVgo/Runtime/IO/ShaderStore.cs b/UniGLTFforUniVgo/Runtime/IO/ShaderStore.cs index f27bdfc..c0b8510 100644 --- a/UniGLTFforUniVgo/Runtime/IO/ShaderStore.cs +++ b/UniGLTFforUniVgo/Runtime/IO/ShaderStore.cs @@ -12,7 +12,7 @@ public class ShaderStore : IShaderStore { readonly string m_defaultShaderName = "Standard"; Shader m_default; - Shader Default + protected Shader Default { get { @@ -25,7 +25,7 @@ Shader Default } Shader m_vcolor; - Shader VColor + protected Shader VColor { get { @@ -35,7 +35,7 @@ Shader VColor } Shader m_uniUnlit; - Shader UniUnlit + protected Shader UniUnlit { get { @@ -45,7 +45,7 @@ Shader UniUnlit } Shader m_unlitTexture; - Shader UnlitTexture + protected Shader UnlitTexture { get { @@ -55,7 +55,7 @@ Shader UnlitTexture } Shader m_unlitColor; - Shader UnlitColor + protected Shader UnlitColor { get { @@ -65,7 +65,7 @@ Shader UnlitColor } Shader m_unlitTransparent; - Shader UnlitTransparent + protected Shader UnlitTransparent { get { @@ -75,7 +75,7 @@ Shader UnlitTransparent } Shader m_unlitCutout; - Shader UnlitCutout + protected Shader UnlitCutout { get { @@ -104,7 +104,7 @@ public static bool IsWhite(float[] color) return true; } - public Shader GetShader(glTFMaterial material) + public virtual Shader GetShader(glTFMaterial material) { if (material == null) { diff --git a/UniGLTFforUniVgo/Runtime/Schema/Extensions/glTFMaterial.cs b/UniGLTFforUniVgo/Runtime/Schema/Extensions/glTFMaterial.cs index 2f4cf53..b8bf340 100644 --- a/UniGLTFforUniVgo/Runtime/Schema/Extensions/glTFMaterial.cs +++ b/UniGLTFforUniVgo/Runtime/Schema/Extensions/glTFMaterial.cs @@ -1,10 +1,28 @@ -using System; - +// ---------------------------------------------------------------------- +// @Namespace : UniGLTFforUniVgo +// @Class : glTFMaterial_extensions +// ---------------------------------------------------------------------- namespace UniGLTFforUniVgo { + using Newtonsoft.Json; + using System; + + /// + /// glTF Material extensions + /// [Serializable] public partial class glTFMaterial_extensions : ExtensionsBase { + /// + [JsonProperty("KHR_materials_unlit")] public glTF_KHR_materials_unlit KHR_materials_unlit; + + /// + [JsonProperty("VGO_materials")] + public glTF_VGO_materials VGO_materials; + + /// + [JsonProperty("VRMC_materials_mtoon")] + public glTF_VRMC_materials_mtoon VRMC_materials_mtoon; } } diff --git a/UniGLTFforUniVgo/Runtime/Schema/Extensions/glTF_VGO_materials.cs b/UniGLTFforUniVgo/Runtime/Schema/Extensions/glTF_VGO_materials.cs new file mode 100644 index 0000000..282f75a --- /dev/null +++ b/UniGLTFforUniVgo/Runtime/Schema/Extensions/glTF_VGO_materials.cs @@ -0,0 +1,23 @@ +// ---------------------------------------------------------------------- +// @Namespace : UniGLTFforUniVgo +// @Class : glTF_VGO_materials +// ---------------------------------------------------------------------- +namespace UniGLTFforUniVgo +{ + using Newtonsoft.Json; + using System; + + /// + /// + /// + [Serializable] + public class glTF_VGO_materials + { + /// Shader Name + [JsonProperty("shaderName", Required = Required.Always)] + public string shaderName = null; + + [JsonIgnore] + public static string ExtensionName => "VGO_materials"; + } +} diff --git a/UniGLTFforUniVgo/Runtime/Schema/Extensions/glTF_VGO_materials.cs.meta b/UniGLTFforUniVgo/Runtime/Schema/Extensions/glTF_VGO_materials.cs.meta new file mode 100644 index 0000000..d196564 --- /dev/null +++ b/UniGLTFforUniVgo/Runtime/Schema/Extensions/glTF_VGO_materials.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 639559d2a8138574cb473738ec0cb018 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UniGLTFforUniVgo/Runtime/Schema/Extensions/glTF_VRMC_materials_mtoon.cs b/UniGLTFforUniVgo/Runtime/Schema/Extensions/glTF_VRMC_materials_mtoon.cs new file mode 100644 index 0000000..6577d94 --- /dev/null +++ b/UniGLTFforUniVgo/Runtime/Schema/Extensions/glTF_VRMC_materials_mtoon.cs @@ -0,0 +1,256 @@ +// ---------------------------------------------------------------------- +// @Namespace : UniGLTFforUniVgo +// @Class : glTF_VRMC_materials_mtoon +// ---------------------------------------------------------------------- +namespace UniGLTFforUniVgo +{ + using Newtonsoft.Json; + using System; + using System.ComponentModel; + + #region Enums + + /// + public enum MToonCullMode + { + /// + Off = 0, + /// + Front = 1, + /// + Back = 2, + } + + /// + public enum MToonOutlineColorMode + { + /// + FixedColor = 0, + /// + MixedLighting = 1, + } + + /// + public enum MToonOutlineWidthMode + { + /// + None = 0, + /// + WorldCoordinates = 1, + /// + ScreenCoordinates = 2, + } + + /// + public enum MToonRenderMode + { + /// + Opaque = 0, + /// + Cutout = 1, + /// + Transparent = 2, + /// + TransparentWithZWrite = 3, + } + + #endregion + + /// + /// VRM/MToon shader properties + /// + [Serializable] + public class glTF_VRMC_materials_mtoon + { + /// _MToonVersion + [JsonProperty("version")] + public string version = null; + + /// _BlendMode + [JsonProperty("renderMode")] + public MToonRenderMode renderMode; + + /// _CullMode + [JsonProperty("cullMode")] + public MToonCullMode cullMode; + + /// renderQueue + [JsonProperty("renderQueueOffsetNumber", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1)] + public int renderQueueOffsetNumber = -1; + + /// _Color + [JsonProperty("litFactor")] + public float[] litFactor; + + /// _MainTex + [JsonProperty("litMultiplyTexture", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1)] + public int litMultiplyTexture = -1; + + /// _ShadeColor + [JsonProperty("shadeFactor")] + public float[] shadeFactor; + + /// _ShadeTexture + [JsonProperty("shadeMultiplyTexture", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1)] + public int shadeMultiplyTexture = -1; + + /// _Cutoff + [JsonProperty("cutoutThresholdFactor", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1.0f)] + public float cutoutThresholdFactor = -1.0f; + + /// _ShadeShift + [JsonProperty("shadingShiftFactor", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-2.0f)] + public float shadingShiftFactor = -2.0f; + + /// _ShadeToony + [JsonProperty("shadingToonyFactor", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1.0f)] + public float shadingToonyFactor = -1.0f; + + /// _ReceiveShadowRate + [JsonProperty("shadowReceiveMultiplierFactor", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1.0f)] + public float shadowReceiveMultiplierFactor = -1.0f; + + /// _ReceiveShadowTexture + [JsonProperty("shadowReceiveMultiplierMultiplyTexture", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1)] + public int shadowReceiveMultiplierMultiplyTexture = -1; + + /// _ShadingGradeRate + [JsonProperty("litAndShadeMixingMultiplierFactor", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1.0f)] + public float litAndShadeMixingMultiplierFactor = -1.0f; + + /// _ShadingGradeTexture + [JsonProperty("litAndShadeMixingMultiplierMultiplyTexture", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1)] + public int litAndShadeMixingMultiplierMultiplyTexture = -1; + + /// _LightColorAttenuation + [JsonProperty("lightColorAttenuationFactor", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1.0f)] + public float lightColorAttenuationFactor = -1.0f; + + /// _IndirectLightIntensity + [JsonProperty("giIntensityFactor", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1.0f)] + public float giIntensityFactor = -1.0f; + + /// _BumpMap + [JsonProperty("normalTexture", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1)] + public int normalTexture = -1; + + /// _BumpScale + [JsonProperty("normalScaleFactor", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1.0f)] + public float normalScaleFactor = -1.0f; + + /// _EmissionColor + [JsonProperty("emissionFactor")] + public float[] emissionFactor; + + /// _EmissionMap + [JsonProperty("emissionMultiplyTexture", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1)] + public int emissionMultiplyTexture = -1; + + /// _SphereAdd + [JsonProperty("additiveTexture", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1)] + public int additiveTexture = -1; + + /// _RimColor + [JsonProperty("rimFactor")] + public float[] rimFactor; + + /// _RimTexture + [JsonProperty("rimMultiplyTexture", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1)] + public int rimMultiplyTexture = -1; + + /// _RimLightingMix + [JsonProperty("rimLightingMixFactor", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1.0f)] + public float rimLightingMixFactor = -1.0f; + + /// _RimFresnelPower + [JsonProperty("rimFresnelPowerFactor", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1.0f)] + public float rimFresnelPowerFactor = -1.0f; + + /// _RimLift + [JsonProperty("rimLiftFactor", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1.0f)] + public float rimLiftFactor = -1.0f; + + /// _OutlineWidthMode + [JsonProperty("outlineWidthMode")] + public MToonOutlineWidthMode outlineWidthMode; + + /// _OutlineWidth + [JsonProperty("outlineWidthFactor", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1.0f)] + public float outlineWidthFactor = -1.0f; + + /// _OutlineWidthTexture + [JsonProperty("outlineWidthMultiplyTexture", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1)] + public int outlineWidthMultiplyTexture = -1; + + /// _OutlineScaledMaxDistance + [JsonProperty("outlineScaledMaxDistanceFactor", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1.0f)] + public float outlineScaledMaxDistanceFactor = -1.0f; + + /// _OutlineColorMode + [JsonProperty("outlineColorMode")] + public MToonOutlineColorMode outlineColorMode; + + /// _OutlineColor + [JsonProperty("outlineFactor")] + public float[] outlineFactor; + + /// _OutlineLightingMix + [JsonProperty("outlineLightingMixFactor", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1.0f)] + public float outlineLightingMixFactor = -1.0f; + + /// _MainTex + [JsonProperty("mainTextureLeftBottomOriginScale")] + public float[] mainTextureLeftBottomOriginScale; + + /// _MainTex + [JsonProperty("mainTextureLeftBottomOriginOffset")] + public float[] mainTextureLeftBottomOriginOffset; + + /// _UvAnimMaskTexture + [JsonProperty("uvAnimationMaskTexture", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1)] + public int uvAnimationMaskTexture = -1; + + /// _UvAnimScrollX + [JsonProperty("uvAnimationScrollXSpeedFactor", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1.0f)] + public float uvAnimationScrollXSpeedFactor = -1.0f; + + /// _UvAnimScrollY + [JsonProperty("uvAnimationScrollYSpeedFactor", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1.0f)] + public float uvAnimationScrollYSpeedFactor = -1.0f; + + /// _UvAnimRotation + [JsonProperty("uvAnimationRotationSpeedFactor", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1.0f)] + public float uvAnimationRotationSpeedFactor = -1.0f; + + [JsonIgnore] + public static string ExtensionName => "VRMC_materials_mtoon"; + } +} diff --git a/UniGLTFforUniVgo/Runtime/Schema/Extensions/glTF_VRMC_materials_mtoon.cs.meta b/UniGLTFforUniVgo/Runtime/Schema/Extensions/glTF_VRMC_materials_mtoon.cs.meta new file mode 100644 index 0000000..b26a6a8 --- /dev/null +++ b/UniGLTFforUniVgo/Runtime/Schema/Extensions/glTF_VRMC_materials_mtoon.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1450261bb7a511d4988617b9aed922c1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UniGLTFforUniVgo/Runtime/Schema/glTFPbrMetallicRoughness.cs b/UniGLTFforUniVgo/Runtime/Schema/glTFPbrMetallicRoughness.cs index b8922f2..9382a00 100644 --- a/UniGLTFforUniVgo/Runtime/Schema/glTFPbrMetallicRoughness.cs +++ b/UniGLTFforUniVgo/Runtime/Schema/glTFPbrMetallicRoughness.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using System; +using System.ComponentModel; namespace UniGLTFforUniVgo { @@ -21,14 +22,16 @@ public class glTFPbrMetallicRoughness public glTFMaterialBaseColorTextureInfo baseColorTexture = null; /// - [JsonProperty("metallicFactor")] + [JsonProperty("metallicFactor", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1.0f)] //[JsonSchema(Minimum = 0.0, Maximum = 1.0)] - public float metallicFactor = 1.0f; + public float metallicFactor = -1.0f; /// - [JsonProperty("roughnessFactor")] + [JsonProperty("roughnessFactor", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1.0f)] //[JsonSchema(Minimum = 0.0, Maximum = 1.0)] - public float roughnessFactor = 1.0f; + public float roughnessFactor = -1.0f; /// [JsonProperty("metallicRoughnessTexture")] diff --git a/UniGLTFforUniVgo/Runtime/Schema/glTFTextureInfo.cs b/UniGLTFforUniVgo/Runtime/Schema/glTFTextureInfo.cs index 37504fa..7f0b36f 100644 --- a/UniGLTFforUniVgo/Runtime/Schema/glTFTextureInfo.cs +++ b/UniGLTFforUniVgo/Runtime/Schema/glTFTextureInfo.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using System; +using System.ComponentModel; namespace UniGLTFforUniVgo { @@ -41,9 +42,10 @@ public abstract class glTFTextureInfo : IglTFTextureinfo public int index = -1; /// - [JsonProperty("texCoord")] + [JsonProperty("texCoord", DefaultValueHandling = DefaultValueHandling.Ignore)] + [DefaultValue(-1)] //[JsonSchema(Minimum = 0)] - public int texCoord; + public int texCoord = -1; /// [JsonProperty("extensions")] diff --git a/UniGLTFforUniVgo/Runtime/Serialization/VgoContractResolver.cs b/UniGLTFforUniVgo/Runtime/Serialization/VgoContractResolver.cs index 87d0c7a..85de2a3 100644 --- a/UniGLTFforUniVgo/Runtime/Serialization/VgoContractResolver.cs +++ b/UniGLTFforUniVgo/Runtime/Serialization/VgoContractResolver.cs @@ -38,6 +38,14 @@ protected override JsonContract CreateContract(Type objectType) contract.Converter = new StringEnumConverter(new DefaultNamingStrategy(), allowIntegerValues: false); } + if ((objectType == typeof(MToonCullMode)) || + (objectType == typeof(MToonOutlineColorMode)) || + (objectType == typeof(MToonOutlineWidthMode)) || + (objectType == typeof(MToonRenderMode))) + { + contract.Converter = new StringEnumConverter(new CamelCaseNamingStrategy(), allowIntegerValues: false); + } + return contract; } } diff --git a/UniVgo/README.ja.md b/UniVgo/README.ja.md index 12199bc..c02d82d 100644 --- a/UniVgo/README.ja.md +++ b/UniVgo/README.ja.md @@ -27,7 +27,7 @@ ___ |パッケージ名|所有者|リポジトリー|仕様バージョン|プログラム バージョン|リリース日| |:---:|:---:|:---:|:---:|:---:|:---:| |newtonsoft-json-for-unity|jillejr|GitHub|12.0.2|12.0.201|2020年1月4日| -|UniVGO|IzayoiJiichan|GitHub| VGO 0.3|0.5.0|2020年1月14日| +|UniVGO|IzayoiJiichan|GitHub|VGO 0.4|0.6.0|2020年1月17日| ___ ## インストール @@ -79,7 +79,7 @@ AまたはBのいずれかを行ってください。 { "dependencies": { "com.unity.ugui": "1.0.0", - "izayoi.univgo": "https://github.com/izayoijiichan/VGO.git#v0.5.0", + "izayoi.univgo": "https://github.com/izayoijiichan/VGO.git#v0.6.0", "jillejr.newtonsoft.json-for-unity": "12.0.201", "com.unity.modules.ai": "1.0.0", ... @@ -100,8 +100,9 @@ https://github.com/izayoijiichan/VGO/releases ``` Packages - izayoi.univgo@0.5.0-preview + izayoi.univgo@0.6.0-preview DepthFirstScheduler + MToon ShaderProperty UniGLTFforUniVgo UniUnlit @@ -126,8 +127,8 @@ VGO のメタ情報です。 |定義名|説明|型|固定値| |:---|:---|:---:|:---:| |Generator Name|生成ツールの名前です。|string|UniVGO| -|Generator Version|生成ツールのバージョンです。|string|0.5.0| -|Spec Version|VGOの仕様バージョンです。|string|0.3| +|Generator Version|生成ツールのバージョンです。|string|0.6.0| +|Spec Version|VGOの仕様バージョンです。|string|0.4| - Root の GameObject に1つ付与しておく必要があります。 - ユーザーが設定可能な項目はありません。 @@ -181,7 +182,12 @@ ___ |シェーダー名|説明| |:---|:---| |Standard|標準シェーダー| -|UniGLTF/Unlit|Unlitシェーダー| +|Unlit/Color|| +|Unlit/Texture|| +|Unlit/Transparent|| +|Unlit/Transparent Cutout|| +|UniGLTF/Unlit|| +|VRM/MToon|| ___ ## VGO のセットアップ @@ -310,16 +316,18 @@ ___ |アセンブリ|説明|UniVgo|UniVgo.Editor| |:---|:---|:---:|:---:| |DepthFirstScheduler|深さ優先スケジューラー|*|*| +|MToon|MToon シェーダー ユーティリティー|*|*| +|MToon.Editor|MToon シェーダー ユーティリティー|-|*| |ShaderProperty.Runtime|シェーダーのプロパティー情報|*|*| |UniGLTFforUniVgo|UniGLTF(UniVGO用)|*|*| -|UniUnlit|Unlit シェーダー ユーティリティー|-|-| +|UniUnlit|Unlit シェーダー ユーティリティー|*|*| |UniUnlit.Editor|Unlit シェーダー ユーティリティー|-|*| |UniVgo|VGO メインプログラム|*|*| |UniVgo.Editor|VGO の入出力|-|*| - UniVgo, UniVgo.Editor それぞれについて、依存関係にあるDLLに * を付けています。 -- DepthFirstScheduler, ShaderProperty, UniUnlit は UniVRM (©vrm-c) に梱包されているプログラムです。 -- UniVRM と UniVGO を併用する場合は、UniVgo を取得した際に梱包されていた 重複するファイル(DepthFirstScheduler, ShaderProperty, UniUnlit)を削除する必要があります。 +- DepthFirstScheduler, MToon, ShaderProperty, UniUnlit は UniVRM (©vrm-c) に梱包されているプログラムです。 +- UniVRM と UniVGO を併用する場合は、UniVgo を取得した際に梱包されていた 重複するファイル(DepthFirstScheduler, MToon, ShaderProperty, UniUnlit)を削除する必要があります。 また、それにより UniVgo にてエラーが表示される場合、UniVgo, UniGLTFforUniVgo を `Assets`フォルダーに移動してください。 ### ゲームオブジェクトのタグについて @@ -348,7 +356,7 @@ Unityを開発してくださっている Unity Technologies 様、 この場を借りて御礼申し上げます。 ___ -最終更新日:2020年1月14日 +最終更新日:2020年1月17日 編集者:十六夜おじいちゃん *Copyright (C) 2020 Izayoi Jiichan. All Rights Reserved.* diff --git a/UniVgo/README.md b/UniVgo/README.md index 5b3966e..255554d 100644 --- a/UniVgo/README.md +++ b/UniVgo/README.md @@ -27,7 +27,7 @@ As of the start of 2020, we are developing and confirming in `Unity 2019.3` Wind |package name|owner|Repository|specification version|program version|release date| |:---:|:---:|:---:|:---:|:---:|:---:| |newtonsoft-json-for-unity|jillejr|GitHub|12.0.2|12.0.201|4 Jan, 2020| -|UniVGO|IzayoiJiichan|GitHub| VGO 0.3|0.5.0|14 Jan, 2020| +|UniVGO|IzayoiJiichan|GitHub|VGO 0.4|0.6.0|17 Jan, 2020| ___ ## Install @@ -76,7 +76,7 @@ Write the following in `/Packages/package.json` { "dependencies": { "com.unity.ugui": "1.0.0", - "izayoi.univgo": "https://github.com/izayoijiichan/VGO.git#v0.5.0", + "izayoi.univgo": "https://github.com/izayoijiichan/VGO.git#v0.6.0", "jillejr.newtonsoft.json-for-unity": "12.0.201", "com.unity.modules.ai": "1.0.0", ... @@ -97,8 +97,9 @@ Unzip the file and place it in the `Packages` folder. ``` Packages - izayoi.univgo@0.5.0-preview + izayoi.univgo@0.6.0-preview DepthFirstScheduler + MToon ShaderProperty UniGLTFforUniVgo UniUnlit @@ -123,8 +124,8 @@ Meta information of VGO. |definition name|description|type|fixed value| |:---|:---|:---:|:---:| |Generator Name|The name of the generation tool.|string|UniVGO| -|Generator Version|The generation tool version.|string|0.5.0| -|Spec Version|VGO specification version.|string|0.3| +|Generator Version|The generation tool version.|string|0.6.0| +|Spec Version|VGO specification version.|string|0.4| - It is necessary to give one to Root GameObject. - There are no user configurable items. @@ -178,7 +179,12 @@ The supported shaders are as follows. |shader name|descriptoin| |:---|:---| |Standard|Standard shader| -|UniGLTF/Unlit|Unlit shader| +|Unlit/Color|| +|Unlit/Texture|| +|Unlit/Transparent|| +|Unlit/Transparent Cutout|| +|UniGLTF/Unlit|| +|VRM/MToon|| ___ ## VGO setup @@ -309,16 +315,18 @@ When the package is installed in the project, the script is automatically compil |assemply|description|UniVgo|UniVgo.Editor| |:---|:---|:---:|:---:| |DepthFirstScheduler|Depth first scheduler|*|*| +|MToon|MToon shader utility|*|*| +|MToon.Editor|MToon shader utility|-|*| |ShaderProperty.Runtime|Shader property information|*|*| |UniGLTFforUniVgo|UniGLTF for UniVGO|*|*| -|UniUnlit|Unlit shader utility|-|-| +|UniUnlit|Unlit shader utility|*|*| |UniUnlit.Editor|Unlit shader utility|-|*| |UniVgo|VGO main program|*|*| |UniVgo.Editor|VGO import / export|-|*| - For each of UniVgo, and UniVgo.Editor, * is attached to the dependent DLL. -- DepthFirstScheduler, ShaderProperty, UniUnlit is a program packed in UniVRM (© vrm-c). -- When using UniVRM and UniVGO together, it is necessary to delete the duplicate files (DepthFirstScheduler, ShaderProperty, UniUnlit) that were packed when UniVgo was obtained. +- DepthFirstScheduler, MToon, ShaderProperty, UniUnlit is a program packed in UniVRM (© vrm-c). +- When using UniVRM and UniVGO together, it is necessary to delete the duplicate files (DepthFirstScheduler, MToon, ShaderProperty, UniUnlit) that were packed when UniVgo was obtained. Also, if the error is displayed by UniVgo, please move UniVgo, UniGLTFforUniVgo to the `Assets` folder. ### About GameObject tags @@ -340,14 +348,14 @@ ___ ## Acknowledgment I would like to express my sincere appreciation to -Everyone, including KhronosGroup, who published the specifications about glTF, +Everyone, including KhronosGroup, who published the specifications about glTF, Dear ousttrue for developing and publishing a program about glTF, VRM Consortium, Dwango Co., Ltd., who has published and distributed VRM specifications and related programs, Unity Technologies, who is developing Unity, and other related people. I would like to take this opportunity to thank you. ___ -Last updated: 14 January, 2020 +Last updated: 17 January, 2020 Editor: Izayoi Jiichan *Copyright (C) 2020 Izayoi Jiichan. All Rights Reserved.* diff --git a/UniVgo/Runtime/IO/VgoExporter.cs b/UniVgo/Runtime/IO/VgoExporter.cs index 398452a..0f3bb92 100644 --- a/UniVgo/Runtime/IO/VgoExporter.cs +++ b/UniVgo/Runtime/IO/VgoExporter.cs @@ -21,9 +21,11 @@ protected override IEnumerable ExtensionUsed { get => new string[] { - glTF_KHR_materials_unlit.ExtensionName, glTF_VGO.ExtensionName, glTFNode_VGO.ExtensionName, + glTF_VGO_materials.ExtensionName, + glTF_KHR_materials_unlit.ExtensionName, + glTF_VRMC_materials_mtoon.ExtensionName, }; } @@ -32,9 +34,11 @@ protected override IEnumerable ExtensionsRequired { get => new string[] { - glTF_KHR_materials_unlit.ExtensionName, glTF_VGO.ExtensionName, glTFNode_VGO.ExtensionName, + glTF_VGO_materials.ExtensionName, + glTF_KHR_materials_unlit.ExtensionName, + glTF_VRMC_materials_mtoon.ExtensionName, }; } @@ -54,6 +58,15 @@ public VgoExporter(glTF gltf) : base(gltf) #region Methods + /// + /// + /// + /// + protected override IMaterialExporter CreateMaterialExporter() + { + return new VgoMaterialExporter(); + } + /// /// /// diff --git a/UniVgo/Runtime/IO/VgoImporter.cs b/UniVgo/Runtime/IO/VgoImporter.cs index 584d09b..6b07763 100644 --- a/UniVgo/Runtime/IO/VgoImporter.cs +++ b/UniVgo/Runtime/IO/VgoImporter.cs @@ -17,6 +17,7 @@ public class VgoImporter : ImporterContext /// public VgoImporter() { + SetMaterialImporter(new VgoMaterialImporter(this)); } /// diff --git a/UniVgo/Runtime/IO/VgoMaterialExporter.cs b/UniVgo/Runtime/IO/VgoMaterialExporter.cs new file mode 100644 index 0000000..88a6d0b --- /dev/null +++ b/UniVgo/Runtime/IO/VgoMaterialExporter.cs @@ -0,0 +1,307 @@ +// ---------------------------------------------------------------------- +// @Namespace : UniVgo +// @Class : VgoMaterialExporter +// ---------------------------------------------------------------------- +namespace UniVgo +{ + using MToon; + using UniGLTFforUniVgo; + using UnityEngine; + + /// + /// VGO Material Exporter + /// + public class VgoMaterialExporter : MaterialExporter + { + #region Public Methods + + /// + /// Export the material. + /// + /// + /// + /// + public override glTFMaterial ExportMaterial(Material m, TextureExportManager textureManager) + { + if (m.shader.name == ShaderName.VRM_MToon) + { + return CreateVrmMtoonMaterial(m, textureManager); + } + + return base.ExportMaterial(m, textureManager); + } + + #endregion + + #region Protected Methods + + /// + /// Create a material. + /// + /// + /// + protected override glTFMaterial CreateMaterial(Material m) + { + switch (m.shader.name) + { + case ShaderName.VRM_UnlitTexture: + return CreateVrmUnlitMaterial(m, MToon.RenderMode.Opaque); + + case ShaderName.VRM_UnlitTransparent: + return CreateVrmUnlitMaterial(m, MToon.RenderMode.Transparent); + + case ShaderName.VRM_UnlitCutout: + return CreateVrmUnlitMaterial(m, MToon.RenderMode.Cutout); + + case ShaderName.VRM_UnlitTransparentZWrite: + return CreateVrmUnlitMaterial(m, MToon.RenderMode.TransparentWithZWrite); + + default: + return base.CreateMaterial(m); + } + } + + /// + /// Create a VRM default material. + /// + /// + /// + /// + protected virtual glTFMaterial CreateVrmDefaultMaterial(Material m, MToon.RenderMode renderMode) + { + var material = new glTFMaterial(); + + material.name = m.name; + + // Alpha Mode + switch (renderMode) + { + case MToon.RenderMode.Opaque: + material.alphaMode = glTFBlendMode.OPAQUE.ToString(); + break; + + case MToon.RenderMode.Cutout: + material.alphaMode = glTFBlendMode.MASK.ToString(); + break; + + case MToon.RenderMode.Transparent: + case MToon.RenderMode.TransparentWithZWrite: + material.alphaMode = glTFBlendMode.BLEND.ToString(); + break; + + default: + break; + } + + // Alpha Cutoff + if (renderMode == MToon.RenderMode.Cutout) + { + material.alphaCutoff = m.GetFloat(MToon.Utils.PropCutoff); + } + + return material; + } + + /// + /// Create a VRM Unlit material. + /// + /// + /// + /// + protected virtual glTFMaterial CreateVrmUnlitMaterial(Material m, MToon.RenderMode renderMode) + { + var material = CreateVrmDefaultMaterial(m, renderMode); + + // PBR Metallic Roughness + material.pbrMetallicRoughness = new glTFPbrMetallicRoughness(); + + // extensions + material.extensions = new glTFMaterial_extensions() + { + KHR_materials_unlit = new glTF_KHR_materials_unlit(), + VGO_materials = new glTF_VGO_materials() + { + shaderName = m.shader.name, + } + }; + + return material; + } + + /// + /// Create a VRM MToon material. + /// + /// + /// + /// + protected virtual glTFMaterial CreateVrmMtoonMaterial(Material m, TextureExportManager textureManager) + { + MToonDefinition mtoonDefinition = MToon.Utils.GetMToonParametersFromMaterial(m); + + var mtoon = new glTF_VRMC_materials_mtoon() + { + // Meta + version = mtoonDefinition.Meta.VersionNumber.ToString(), + + // Rendering + renderMode = (MToonRenderMode)mtoonDefinition.Rendering.RenderMode, + cullMode = (MToonCullMode)mtoonDefinition.Rendering.CullMode, + renderQueueOffsetNumber = mtoonDefinition.Rendering.RenderQueueOffsetNumber, + + // Color + litFactor = mtoonDefinition.Color.LitColor.linear.ToArray(), + litMultiplyTexture = -1, + shadeFactor = mtoonDefinition.Color.ShadeColor.linear.ToArray(), + shadeMultiplyTexture = -1, + cutoutThresholdFactor = mtoonDefinition.Color.CutoutThresholdValue, + + // Lighting + shadingShiftFactor = mtoonDefinition.Lighting.LitAndShadeMixing.ShadingShiftValue, + shadingToonyFactor = mtoonDefinition.Lighting.LitAndShadeMixing.ShadingToonyValue, + shadowReceiveMultiplierFactor = mtoonDefinition.Lighting.LitAndShadeMixing.ShadowReceiveMultiplierValue, + shadowReceiveMultiplierMultiplyTexture = -1, + litAndShadeMixingMultiplierFactor = mtoonDefinition.Lighting.LitAndShadeMixing.LitAndShadeMixingMultiplierValue, + litAndShadeMixingMultiplierMultiplyTexture = -1, + lightColorAttenuationFactor = mtoonDefinition.Lighting.LightingInfluence.LightColorAttenuationValue, + giIntensityFactor = mtoonDefinition.Lighting.LightingInfluence.GiIntensityValue, + normalTexture = -1, + normalScaleFactor = mtoonDefinition.Lighting.Normal.NormalScaleValue, + + // Emission + emissionFactor = mtoonDefinition.Emission.EmissionColor.linear.ToArray(), + emissionMultiplyTexture = -1, + + // MatCap + additiveTexture = -1, + + // Rim + rimFactor = mtoonDefinition.Rim.RimColor.linear.ToArray(), + rimMultiplyTexture = -1, + rimLightingMixFactor = mtoonDefinition.Rim.RimLightingMixValue, + rimFresnelPowerFactor = mtoonDefinition.Rim.RimFresnelPowerValue, + rimLiftFactor = mtoonDefinition.Rim.RimLiftValue, + + // Outline + outlineWidthMode = (MToonOutlineWidthMode)mtoonDefinition.Outline.OutlineWidthMode, + outlineWidthFactor = mtoonDefinition.Outline.OutlineWidthValue, + outlineWidthMultiplyTexture = -1, + outlineScaledMaxDistanceFactor = mtoonDefinition.Outline.OutlineScaledMaxDistanceValue, + outlineColorMode = (MToonOutlineColorMode)mtoonDefinition.Outline.OutlineColorMode, + outlineFactor = mtoonDefinition.Outline.OutlineColor.linear.ToArray(), + outlineLightingMixFactor = mtoonDefinition.Outline.OutlineLightingMixValue, + + // TextureOption + mainTextureLeftBottomOriginScale = new float[] + { + mtoonDefinition.TextureOption.MainTextureLeftBottomOriginScale.x, + mtoonDefinition.TextureOption.MainTextureLeftBottomOriginScale.y + }, + mainTextureLeftBottomOriginOffset = new float[] + { + mtoonDefinition.TextureOption.MainTextureLeftBottomOriginOffset.x, + mtoonDefinition.TextureOption.MainTextureLeftBottomOriginOffset.y + }, + uvAnimationMaskTexture = -1, + uvAnimationScrollXSpeedFactor = mtoonDefinition.TextureOption.UvAnimationScrollXSpeedValue, + uvAnimationScrollYSpeedFactor = mtoonDefinition.TextureOption.UvAnimationScrollYSpeedValue, + uvAnimationRotationSpeedFactor = mtoonDefinition.TextureOption.UvAnimationRotationSpeedValue, + }; + + // Textures + mtoon.litMultiplyTexture = textureManager.CopyAndGetIndex(mtoonDefinition.Color.LitMultiplyTexture, RenderTextureReadWrite.sRGB); + mtoon.shadeMultiplyTexture = textureManager.CopyAndGetIndex(mtoonDefinition.Color.ShadeMultiplyTexture, RenderTextureReadWrite.sRGB); + mtoon.shadowReceiveMultiplierMultiplyTexture = textureManager.CopyAndGetIndex(mtoonDefinition.Lighting.LitAndShadeMixing.ShadowReceiveMultiplierMultiplyTexture, RenderTextureReadWrite.sRGB); + mtoon.litAndShadeMixingMultiplierMultiplyTexture = textureManager.CopyAndGetIndex(mtoonDefinition.Lighting.LitAndShadeMixing.LitAndShadeMixingMultiplierMultiplyTexture, RenderTextureReadWrite.sRGB); + mtoon.normalTexture = textureManager.ConvertAndGetIndex(mtoonDefinition.Lighting.Normal.NormalTexture, new NormalConverter()); + mtoon.emissionMultiplyTexture = textureManager.CopyAndGetIndex(mtoonDefinition.Emission.EmissionMultiplyTexture, RenderTextureReadWrite.sRGB); + mtoon.additiveTexture = textureManager.CopyAndGetIndex(mtoonDefinition.MatCap.AdditiveTexture, RenderTextureReadWrite.sRGB); + mtoon.rimMultiplyTexture = textureManager.CopyAndGetIndex(mtoonDefinition.Rim.RimMultiplyTexture, RenderTextureReadWrite.sRGB); + mtoon.outlineWidthMultiplyTexture = textureManager.CopyAndGetIndex(mtoonDefinition.Outline.OutlineWidthMultiplyTexture, RenderTextureReadWrite.sRGB); + mtoon.uvAnimationMaskTexture = textureManager.CopyAndGetIndex(mtoonDefinition.TextureOption.UvAnimationMaskTexture, RenderTextureReadWrite.sRGB); + + var material = CreateVrmDefaultMaterial(m, mtoonDefinition.Rendering.RenderMode); + + // Double Sided + switch (mtoon.cullMode) + { + case MToonCullMode.Off: + material.doubleSided = true; + break; + + case MToonCullMode.Front: + case MToonCullMode.Back: + material.doubleSided = false; + break; + + default: + break; + } + + // PBR Metallic Roughness + { + if (mtoon.litFactor != null) + { + if (material.pbrMetallicRoughness == null) + { + material.pbrMetallicRoughness = new glTFPbrMetallicRoughness(); + } + + material.pbrMetallicRoughness.baseColorFactor = mtoon.litFactor; + } + + if (mtoon.litMultiplyTexture != -1) + { + if (material.pbrMetallicRoughness == null) + { + material.pbrMetallicRoughness = new glTFPbrMetallicRoughness(); + } + + material.pbrMetallicRoughness.baseColorTexture = new glTFMaterialBaseColorTextureInfo() + { + index = mtoon.litMultiplyTexture, + }; + + //material.pbrMetallicRoughness.metallicFactor = 1.0f; + //material.pbrMetallicRoughness.roughnessFactor = 1.0f; + } + } + + // Normal Texture + if (mtoon.normalTexture != -1) + { + material.normalTexture = new glTFMaterialNormalTextureInfo() + { + index = mtoon.normalTexture, + scale = mtoon.normalScaleFactor, + }; + } + + // Emissive + { + material.emissiveFactor = mtoon.emissionFactor; + + if (mtoon.emissionMultiplyTexture != -1) + { + material.emissiveTexture = new glTFMaterialEmissiveTextureInfo() + { + index = mtoon.emissionMultiplyTexture, + }; + } + } + + // Extensions + material.extensions = new glTFMaterial_extensions() + { + VRMC_materials_mtoon = mtoon, + VGO_materials = new glTF_VGO_materials() + { + shaderName = m.shader.name, + } + }; + + return material; + } + + #endregion + } +} diff --git a/UniVgo/Runtime/IO/VgoMaterialExporter.cs.meta b/UniVgo/Runtime/IO/VgoMaterialExporter.cs.meta new file mode 100644 index 0000000..309dd57 --- /dev/null +++ b/UniVgo/Runtime/IO/VgoMaterialExporter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4ce60f7f32cf3084cbf31b634a5de872 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UniVgo/Runtime/IO/VgoMaterialImporter.cs b/UniVgo/Runtime/IO/VgoMaterialImporter.cs new file mode 100644 index 0000000..74ebf12 --- /dev/null +++ b/UniVgo/Runtime/IO/VgoMaterialImporter.cs @@ -0,0 +1,350 @@ +// ---------------------------------------------------------------------- +// @Namespace : UniVgo +// @Class : VgoMaterialImporter +// ---------------------------------------------------------------------- +namespace UniVgo +{ + using MToon; + using UniGLTFforUniVgo; + using UnityEngine; + using UnityEngine.Rendering; + + /// + /// VGO Material Importer + /// + public class VgoMaterialImporter : MaterialImporter + { + #region Constructors + + /// + /// Create a new instance of VgoMaterialImporter with ImporterContext. + /// + /// + public VgoMaterialImporter(ImporterContext context) : base(new VgoShaderStore(context), context) + { + } + + #endregion + + #region Public Methods + + /// + /// Create a material. + /// + /// + /// + /// + /// + public override Material CreateMaterial(int i, glTFMaterial src, bool hasVertexColor) + { + if (src.extensions != null) + { + if (src.extensions.KHR_materials_unlit != null) + { + return CreateUnlitMaterial(i, src, hasVertexColor); + } + if (src.extensions.VRMC_materials_mtoon != null) + { + return CreateMtoonMaterial(i, src); + } + } + + return base.CreateMaterial(i, src, hasVertexColor); + } + + #endregion + + #region Protected Methods + + /// + /// Create a Unlit material. + /// + /// + /// + /// + /// + protected virtual Material CreateUnlitMaterial(int i, glTFMaterial src, bool hasVertexColor) + { + var shader = m_shaderStore.GetShader(src); + + var material = new Material(shader); + + material.name = CreateMaterialName(i, src); + +#if UNITY_EDITOR + material.hideFlags = HideFlags.DontUnloadUnusedAsset; +#endif + // renderMode + switch (src.alphaMode) + { + case MaterialAlphaMode.OPAQUE: + UniGLTF.UniUnlit.Utils.SetRenderMode(material, UniGLTF.UniUnlit.UniUnlitRenderMode.Opaque); + break; + + case MaterialAlphaMode.BLEND: + UniGLTF.UniUnlit.Utils.SetRenderMode(material, UniGLTF.UniUnlit.UniUnlitRenderMode.Transparent); + break; + + case MaterialAlphaMode.MASK: + UniGLTF.UniUnlit.Utils.SetRenderMode(material, UniGLTF.UniUnlit.UniUnlitRenderMode.Cutout); + break; + + default: + UniGLTF.UniUnlit.Utils.SetRenderMode(material, UniGLTF.UniUnlit.UniUnlitRenderMode.Opaque); + break; + } + + // culling + if (src.doubleSided) + { + UniGLTF.UniUnlit.Utils.SetCullMode(material, UniGLTF.UniUnlit.UniUnlitCullMode.Off); + } + else + { + UniGLTF.UniUnlit.Utils.SetCullMode(material, UniGLTF.UniUnlit.UniUnlitCullMode.Back); + } + + // VColor + if (hasVertexColor) + { + UniGLTF.UniUnlit.Utils.SetVColBlendMode(material, UniGLTF.UniUnlit.UniUnlitVertexColorBlendOp.Multiply); + } + else + { + UniGLTF.UniUnlit.Utils.SetVColBlendMode(material, UniGLTF.UniUnlit.UniUnlitVertexColorBlendOp.None); + } + + if (src.pbrMetallicRoughness != null) + { + // color + if (src.pbrMetallicRoughness.baseColorFactor != null) + { + material.color = ArrayConverter.ToColor(src.pbrMetallicRoughness.baseColorFactor, gamma: true); + } + + // texture + if (src.pbrMetallicRoughness.baseColorTexture != null) + { + var texture = Context.GetTexture(src.pbrMetallicRoughness.baseColorTexture.index); + + if (texture != null) + { + material.mainTexture = texture.Texture; + } + } + } + + if (material.shader.name == ShaderName.UniGLTF_UniUnlit) + { + UniGLTF.UniUnlit.Utils.ValidateProperties(material, true); + + return material; + } + + switch (src.alphaMode) + { + case MaterialAlphaMode.BLEND: + material.SetInt(UniGLTF.UniUnlit.Utils.PropNameBlendMode, (int)BlendMode.Fade); + material.SetInt(UniGLTF.UniUnlit.Utils.PropNameSrcBlend, (int)UnityEngine.Rendering.BlendMode.SrcAlpha); + material.SetInt(UniGLTF.UniUnlit.Utils.PropNameDstBlend, (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); + material.SetInt(UniGLTF.UniUnlit.Utils.PropNameZWrite, 0); + material.DisableKeyword(UniGLTF.UniUnlit.Utils.KeywordAlphaTestOn); + material.EnableKeyword(UniGLTF.UniUnlit.Utils.KeywordAlphaBlendOn); + material.renderQueue = (int)RenderQueue.Transparent; + break; + + case MaterialAlphaMode.MASK: + material.SetFloat(UniGLTF.UniUnlit.Utils.PropNameCutoff, src.alphaCutoff); + material.SetInt(UniGLTF.UniUnlit.Utils.PropNameBlendMode, (int)BlendMode.Cutout); + material.SetInt(UniGLTF.UniUnlit.Utils.PropNameSrcBlend, (int)UnityEngine.Rendering.BlendMode.One); + material.SetInt(UniGLTF.UniUnlit.Utils.PropNameDstBlend, (int)UnityEngine.Rendering.BlendMode.Zero); + material.SetInt(UniGLTF.UniUnlit.Utils.PropNameZWrite, 1); + material.EnableKeyword(UniGLTF.UniUnlit.Utils.KeywordAlphaTestOn); + material.DisableKeyword(UniGLTF.UniUnlit.Utils.KeywordAlphaBlendOn); + material.renderQueue = (int)RenderQueue.AlphaTest; + break; + + case MaterialAlphaMode.OPAQUE: + default: + material.SetInt(UniGLTF.UniUnlit.Utils.PropNameBlendMode, (int)BlendMode.Opaque); + material.SetInt(UniGLTF.UniUnlit.Utils.PropNameSrcBlend, (int)UnityEngine.Rendering.BlendMode.One); + material.SetInt(UniGLTF.UniUnlit.Utils.PropNameDstBlend, (int)UnityEngine.Rendering.BlendMode.Zero); + material.SetInt(UniGLTF.UniUnlit.Utils.PropNameZWrite, 1); + material.DisableKeyword(UniGLTF.UniUnlit.Utils.KeywordAlphaTestOn); + material.DisableKeyword(UniGLTF.UniUnlit.Utils.KeywordAlphaBlendOn); + material.renderQueue = -1; + break; + } + + return material; + } + + #endregion + + /// + /// Create a MToon material. + /// + /// + /// + /// + protected virtual Material CreateMtoonMaterial(int i, glTFMaterial src) + { + Shader shader = Shader.Find(MToon.Utils.ShaderName); + + Material material = new Material(shader); + + material.name = CreateMaterialName(i, src); + + MToonDefinition mtoonDefinition = CreateMtoonDefinition(src.extensions.VRMC_materials_mtoon); + + MToon.Utils.SetMToonParametersToMaterial(material, mtoonDefinition); + + return material; + } + + /// + /// Create a MToon definition. + /// + /// + /// + protected virtual MToonDefinition CreateMtoonDefinition(glTF_VRMC_materials_mtoon mtoon) + { + MToonDefinition mtoonDefinition = new MToonDefinition(); + + // Meta + mtoonDefinition.Meta = new MetaDefinition() + { + VersionNumber = MToon.Utils.VersionNumber, + Implementation = MToon.Utils.Implementation, + }; + + // Rendering + mtoonDefinition.Rendering = new RenderingDefinition() + { + RenderMode = (MToon.RenderMode)mtoon.renderMode, + CullMode = (MToon.CullMode)mtoon.cullMode, + RenderQueueOffsetNumber = mtoon.renderQueueOffsetNumber, + }; + + // Color + mtoonDefinition.Color = new ColorDefinition() + { + LitColor = ArrayConverter.ToColor(mtoon.litFactor, gamma: true), + LitMultiplyTexture = GetTexture(MToon.Utils.PropMainTex, mtoon.litMultiplyTexture), + ShadeColor = ArrayConverter.ToColor(mtoon.shadeFactor, gamma: true), + ShadeMultiplyTexture = GetTexture(MToon.Utils.PropShadeTexture, mtoon.shadeMultiplyTexture), + CutoutThresholdValue = mtoon.cutoutThresholdFactor, + }; + + // Lighting + mtoonDefinition.Lighting = new LightingDefinition(); + mtoonDefinition.Lighting.LitAndShadeMixing = new LitAndShadeMixingDefinition() + { + ShadingShiftValue = mtoon.shadingShiftFactor, + ShadingToonyValue = mtoon.shadingToonyFactor, + ShadowReceiveMultiplierValue = mtoon.shadowReceiveMultiplierFactor, + ShadowReceiveMultiplierMultiplyTexture = GetTexture(MToon.Utils.PropReceiveShadowTexture, mtoon.shadowReceiveMultiplierMultiplyTexture), + LitAndShadeMixingMultiplierValue = mtoon.litAndShadeMixingMultiplierFactor, + LitAndShadeMixingMultiplierMultiplyTexture = GetTexture(MToon.Utils.PropShadingGradeTexture, mtoon.litAndShadeMixingMultiplierMultiplyTexture), + }; + mtoonDefinition.Lighting.LightingInfluence = new LightingInfluenceDefinition() + { + LightColorAttenuationValue = mtoon.lightColorAttenuationFactor, + GiIntensityValue = mtoon.giIntensityFactor, + }; + mtoonDefinition.Lighting.Normal = new NormalDefinition() + { + NormalTexture = GetTexture(MToon.Utils.PropBumpMap, mtoon.normalTexture), + NormalScaleValue = mtoon.normalScaleFactor, + }; + + // Emission + mtoonDefinition.Emission = new EmissionDefinition() + { + EmissionColor = ArrayConverter.ToColor(mtoon.emissionFactor, gamma: true), + EmissionMultiplyTexture = GetTexture(MToon.Utils.PropEmissionMap, mtoon.emissionMultiplyTexture), + }; + + // MatCap + mtoonDefinition.MatCap = new MatCapDefinition() + { + AdditiveTexture = GetTexture(MToon.Utils.PropSphereAdd, mtoon.additiveTexture), + }; + + // Rim + mtoonDefinition.Rim = new RimDefinition() + { + RimColor = ArrayConverter.ToColor(mtoon.rimFactor, gamma: true), + RimMultiplyTexture = GetTexture(MToon.Utils.PropRimTexture, mtoon.rimMultiplyTexture), + RimLightingMixValue = mtoon.rimLightingMixFactor, + RimFresnelPowerValue = mtoon.rimFresnelPowerFactor, + RimLiftValue = mtoon.rimLiftFactor, + }; + + // Outline + mtoonDefinition.Outline = new OutlineDefinition() + { + OutlineWidthMode = (MToon.OutlineWidthMode)mtoon.outlineWidthMode, + OutlineWidthValue = mtoon.outlineWidthFactor, + OutlineWidthMultiplyTexture = GetTexture(MToon.Utils.PropOutlineWidthTexture, mtoon.outlineWidthMultiplyTexture), + OutlineScaledMaxDistanceValue = mtoon.outlineScaledMaxDistanceFactor, + OutlineColorMode = (MToon.OutlineColorMode)mtoon.outlineColorMode, + OutlineColor = ArrayConverter.ToColor(mtoon.outlineFactor, gamma: true), + OutlineLightingMixValue = mtoon.outlineLightingMixFactor, + }; + + // Texture Option + mtoonDefinition.TextureOption = new TextureUvCoordsDefinition() + { + MainTextureLeftBottomOriginScale = ArrayConverter.ToVector2(mtoon.mainTextureLeftBottomOriginScale), + MainTextureLeftBottomOriginOffset = ArrayConverter.ToVector2(mtoon.mainTextureLeftBottomOriginOffset), + UvAnimationMaskTexture = GetTexture(MToon.Utils.PropUvAnimMaskTexture, mtoon.uvAnimationMaskTexture), + UvAnimationScrollXSpeedValue = mtoon.uvAnimationScrollXSpeedFactor, + UvAnimationScrollYSpeedValue = mtoon.uvAnimationScrollYSpeedFactor, + UvAnimationRotationSpeedValue = mtoon.uvAnimationRotationSpeedFactor, + }; + + return mtoonDefinition; + } + + /// + /// Create material name. + /// + /// + /// + /// + protected virtual string CreateMaterialName(int i, glTFMaterial src) + { + if ((src == null) || string.IsNullOrEmpty(src.name)) + { + return string.Format("material_{0:00}", i); + } + return src.name; + } + + /// + /// Get the texture. + /// + /// + /// + /// + protected virtual Texture2D GetTexture(string shaderPropertyName, int textureIndex) + { + TextureItem textureItem = Context.GetTexture(textureIndex); + + if (textureItem == null) + { + return null; + } + + Texture2D texture2D = textureItem.ConvertTexture(shaderPropertyName); + + if (texture2D == null) + { + return textureItem.Texture; + } + + return texture2D; + } + } +} diff --git a/UniVgo/Runtime/IO/VgoMaterialImporter.cs.meta b/UniVgo/Runtime/IO/VgoMaterialImporter.cs.meta new file mode 100644 index 0000000..992cf75 --- /dev/null +++ b/UniVgo/Runtime/IO/VgoMaterialImporter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cbb1ddaa52a48214497c911f400385c3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UniVgo/Runtime/IO/VgoShaderStore.cs b/UniVgo/Runtime/IO/VgoShaderStore.cs new file mode 100644 index 0000000..b7919fa --- /dev/null +++ b/UniVgo/Runtime/IO/VgoShaderStore.cs @@ -0,0 +1,192 @@ +// ---------------------------------------------------------------------- +// @Namespace : UniVgo +// @Class : VgoShaderStore +// ---------------------------------------------------------------------- +namespace UniVgo +{ + using UniGLTFforUniVgo; + using UnityEngine; + + /// + /// VGO Shader Store + /// + public class VgoShaderStore : ShaderStore + { + #region Fields + + /// VRM/UnlitTexture + Shader _VrmUnlitTexture; + + /// VRM/UnlitTransparent + Shader _VrmUnlitTransparent; + + /// VRM/UnlitCutout + Shader _VrmUnlitCutout; + + /// VRM/UnlitTransparentZWrite + Shader _VrmUnlitTransparentZWrite; + + /// VRM/MToon + Shader _VrmMtoon; + + #endregion + + #region Properties + + /// VRM/UnlitTexture + protected Shader VrmUnlitTexture + { + get + { + if (_VrmUnlitTexture == null) + { + _VrmUnlitTexture = Shader.Find(ShaderName.VRM_UnlitTexture); + } + return _VrmUnlitTexture; + } + } + + /// VRM/UnlitTransparent + protected Shader VrmUnlitTransparent + { + get + { + if (_VrmUnlitTransparent == null) + { + _VrmUnlitTransparent = Shader.Find(ShaderName.VRM_UnlitTransparent); + } + return _VrmUnlitTransparent; + } + } + + /// VRM/UnlitCutout + protected Shader VrmUnlitCutout + { + get + { + if (_VrmUnlitCutout == null) + { + _VrmUnlitCutout = Shader.Find(ShaderName.VRM_UnlitCutout); + } + return _VrmUnlitCutout; + } + } + + /// VRM/UnlitTransparentZWrite + protected Shader VrmUnlitTransparentZWrite + { + get + { + if (_VrmUnlitTransparentZWrite == null) + { + _VrmUnlitTransparentZWrite = Shader.Find(ShaderName.VRM_UnlitTransparentZWrite); + } + return _VrmUnlitTransparentZWrite; + } + } + + /// VRM/MToon + protected Shader VrmMtoon + { + get + { + if (_VrmMtoon == null) + { + _VrmMtoon = Shader.Find(ShaderName.VRM_MToon); + } + return _VrmMtoon; + } + } + + #endregion + + #region Constructors + + /// + /// Create a new instance of VgoShaderStore. + /// + /// + public VgoShaderStore(ImporterContext _) : base(_) + { + } + + #endregion + + #region Methods + + /// + /// Get a shader. + /// + /// + /// + public override Shader GetShader(glTFMaterial material) + { + if (material == null) + { + return Default; + } + + if (material.extensions == null) + { + return Default; + } + + if ((material.extensions.VGO_materials != null) && + (material.extensions.VGO_materials.shaderName != null)) + { + switch (material.extensions.VGO_materials.shaderName) + { + case ShaderName.UniGLTF_StandardVColor: + return VColor; + + case ShaderName.Unlit_Color: + return UnlitColor; + + case ShaderName.Unlit_Texture: + return UnlitTexture; + + case ShaderName.Unlit_Transparent: + return UnlitTransparent; + + case ShaderName.Unlit_Transparent_Cutout: + return UnlitCutout; + + case ShaderName.UniGLTF_UniUnlit: + return UniUnlit; + + case ShaderName.VRM_UnlitTexture: + return VrmUnlitTexture; + + case ShaderName.VRM_UnlitTransparent: + return VrmUnlitTransparent; + + case ShaderName.VRM_UnlitCutout: + return VrmUnlitCutout; + + case ShaderName.VRM_UnlitTransparentZWrite: + return VrmUnlitTransparentZWrite; + + case ShaderName.VRM_MToon: + return VrmMtoon; + + default: + break; + } + } + + if (material.extensions.KHR_materials_unlit != null) + { + return UniUnlit; + } + + if (material.extensions.VRMC_materials_mtoon != null) + { + return VrmMtoon; + } + + return Default; + } + + #endregion + } +} diff --git a/UniVgo/Runtime/IO/VgoShaderStore.cs.meta b/UniVgo/Runtime/IO/VgoShaderStore.cs.meta new file mode 100644 index 0000000..f668d31 --- /dev/null +++ b/UniVgo/Runtime/IO/VgoShaderStore.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2e37c2993c3758d4c8b187390b250de3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UniVgo/Runtime/UniVgo.asmdef b/UniVgo/Runtime/UniVgo.asmdef index 202c1b4..1e5053b 100644 --- a/UniVgo/Runtime/UniVgo.asmdef +++ b/UniVgo/Runtime/UniVgo.asmdef @@ -2,6 +2,7 @@ "name": "UniVgo", "references": [ "ShaderProperty.Runtime", + "MToon", "UniUnlit", "UniGLTFforUniVgo" ], diff --git a/UniVgo/Runtime/Utils/MaterialAlphaMode.cs b/UniVgo/Runtime/Utils/MaterialAlphaMode.cs new file mode 100644 index 0000000..13f2e3b --- /dev/null +++ b/UniVgo/Runtime/Utils/MaterialAlphaMode.cs @@ -0,0 +1,21 @@ +// ---------------------------------------------------------------------- +// @Namespace : UniVgo +// @Class : MaterialAlphaMode +// ---------------------------------------------------------------------- +namespace UniVgo +{ + /// + /// glTF Material Alpha Mode + /// + public class MaterialAlphaMode + { + /// OPAQUE + public const string OPAQUE = "OPAQUE"; + + /// MASK + public const string MASK = "MASK"; + + /// BLEND + public const string BLEND = "BLEND"; + } +} diff --git a/UniVgo/Runtime/Utils/MaterialAlphaMode.cs.meta b/UniVgo/Runtime/Utils/MaterialAlphaMode.cs.meta new file mode 100644 index 0000000..bf19c7e --- /dev/null +++ b/UniVgo/Runtime/Utils/MaterialAlphaMode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5923329c5323b1047820dd71539f4596 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UniVgo/Runtime/Utils/ShaderName.cs b/UniVgo/Runtime/Utils/ShaderName.cs new file mode 100644 index 0000000..ee53a2e --- /dev/null +++ b/UniVgo/Runtime/Utils/ShaderName.cs @@ -0,0 +1,45 @@ +// ---------------------------------------------------------------------- +// @Namespace : UniVgo +// @Class : ShaderName +// ---------------------------------------------------------------------- +namespace UniVgo +{ + /// + /// + /// + public class ShaderName + { + /// + public const string UniGLTF_StandardVColor = "UniGLTF/StandardVColor"; + + /// + public const string Unlit_Color = "Unlit/Color"; + + /// + public const string Unlit_Texture = "Unlit/Texture"; + + /// + public const string Unlit_Transparent = "Unlit/Transparent"; + + /// + public const string Unlit_Transparent_Cutout = "Unlit/Transparent Cutout"; + + /// + public const string UniGLTF_UniUnlit = "UniGLTF/UniUnlit"; + + /// + public const string VRM_UnlitTexture = "VRM/UnlitTexture"; + + /// + public const string VRM_UnlitTransparent = "VRM/UnlitTransparent"; + + /// + public const string VRM_UnlitCutout = "VRM/UnlitCutout"; + + /// + public const string VRM_UnlitTransparentZWrite = "VRM/UnlitTransparentZWrite"; + + /// + public const string VRM_MToon = "VRM/MToon"; + } +} diff --git a/UniVgo/Runtime/Utils/ShaderName.cs.meta b/UniVgo/Runtime/Utils/ShaderName.cs.meta new file mode 100644 index 0000000..aa15e36 --- /dev/null +++ b/UniVgo/Runtime/Utils/ShaderName.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ab5edba5ea03a6040a7983c0cf70eb65 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UniVgo/Runtime/Vgo.cs b/UniVgo/Runtime/Vgo.cs index 025d68f..ee5758f 100644 --- a/UniVgo/Runtime/Vgo.cs +++ b/UniVgo/Runtime/Vgo.cs @@ -13,6 +13,6 @@ public class Vgo public const string Generator = "UniVGO"; /// Specification Version - public const string SpecVersion = "0.3"; + public const string SpecVersion = "0.4"; } } \ No newline at end of file diff --git a/UniVgo/Runtime/VgoVersion.cs b/UniVgo/Runtime/VgoVersion.cs index 312c614..65ec254 100644 --- a/UniVgo/Runtime/VgoVersion.cs +++ b/UniVgo/Runtime/VgoVersion.cs @@ -13,12 +13,12 @@ public class VgoVersion public const int MAJOR = 0; /// Minor - public const int MINOR = 5; + public const int MINOR = 6; /// Patch public const int PATCH = 0; /// Version - public const string VERSION = "0.5.0"; + public const string VERSION = "0.6.0"; } } diff --git a/package.json b/package.json index 35c8738..3d9ae4f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "izayoi.univgo", "displayName": "UniVGO", "description": "UniVGO is a package that can handle VGO files in Unity.", - "version": "0.5.0-preview", + "version": "0.6.0-preview", "type": "tool", "category": "", "keywords": [