remove unused Format/NodeCollider

This commit is contained in:
ousttrue 2021-04-30 13:21:36 +09:00
parent 693eb982fa
commit f5a1c1e537
11 changed files with 77 additions and 513 deletions

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 57de298702679f949a2f2658ad186d4a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,172 +0,0 @@
// This file is generated from JsonSchema. Don't modify this source code.
using UniJSON;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace UniGLTF.Extensions.VRMC_node_collider {
public static class GltfDeserializer
{
public static bool TryGet(UniGLTF.glTFExtension src, out VRMC_node_collider extension)
{
if(src is UniGLTF.glTFExtensionImport extensions)
{
foreach(var kv in extensions.ObjectItems())
{
if(kv.Key.GetUtf8String() == VRMC_node_collider.ExtensionNameUtf8)
{
extension = Deserialize(kv.Value);
return true;
}
}
}
extension = default;
return false;
}
public static VRMC_node_collider Deserialize(JsonNode parsed)
{
var value = new VRMC_node_collider();
foreach(var kv in parsed.ObjectItems())
{
var key = kv.Key.GetString();
if(key=="extensions"){
value.Extensions = new glTFExtensionImport(kv.Value);
continue;
}
if(key=="extras"){
value.Extras = new glTFExtensionImport(kv.Value);
continue;
}
if(key=="shapes"){
value.Shapes = Deserialize_Shapes(kv.Value);
continue;
}
}
return value;
}
public static List<ColliderShape> Deserialize_Shapes(JsonNode parsed)
{
var value = new List<ColliderShape>();
foreach(var x in parsed.ArrayItems())
{
value.Add(Deserialize_Shapes_ITEM(x));
}
return value;
}
public static ColliderShape Deserialize_Shapes_ITEM(JsonNode parsed)
{
var value = new ColliderShape();
foreach(var kv in parsed.ObjectItems())
{
var key = kv.Key.GetString();
if(key=="extensions"){
value.Extensions = new glTFExtensionImport(kv.Value);
continue;
}
if(key=="extras"){
value.Extras = new glTFExtensionImport(kv.Value);
continue;
}
if(key=="sphere"){
value.Sphere = Deserialize_Sphere(kv.Value);
continue;
}
if(key=="capsule"){
value.Capsule = Deserialize_Capsule(kv.Value);
continue;
}
}
return value;
}
public static ColliderShapeSphere Deserialize_Sphere(JsonNode parsed)
{
var value = new ColliderShapeSphere();
foreach(var kv in parsed.ObjectItems())
{
var key = kv.Key.GetString();
if(key=="offset"){
value.Offset = Deserialize_Offset(kv.Value);
continue;
}
if(key=="radius"){
value.Radius = kv.Value.GetSingle();
continue;
}
}
return value;
}
public static float[] Deserialize_Offset(JsonNode parsed)
{
var value = new float[parsed.GetArrayCount()];
int i=0;
foreach(var x in parsed.ArrayItems())
{
value[i++] = x.GetSingle();
}
return value;
}
public static ColliderShapeCapsule Deserialize_Capsule(JsonNode parsed)
{
var value = new ColliderShapeCapsule();
foreach(var kv in parsed.ObjectItems())
{
var key = kv.Key.GetString();
if(key=="offset"){
value.Offset = Deserialize_Offset(kv.Value);
continue;
}
if(key=="radius"){
value.Radius = kv.Value.GetSingle();
continue;
}
if(key=="tail"){
value.Tail = Deserialize_Tail(kv.Value);
continue;
}
}
return value;
}
public static float[] Deserialize_Tail(JsonNode parsed)
{
var value = new float[parsed.GetArrayCount()];
int i=0;
foreach(var x in parsed.ArrayItems())
{
value[i++] = x.GetSingle();
}
return value;
}
} // GltfDeserializer
} // UniGLTF

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 162032f06e7a71549bb767d4aad3d221
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,57 +0,0 @@
// This file is generated from JsonSchema. Don't modify this source code.
using System;
using System.Collections.Generic;
using UniGLTF;
using UniJSON;
namespace UniGLTF.Extensions.VRMC_node_collider
{
public class ColliderShapeSphere
{
// The sphere center. vector3
public float[] Offset;
// The sphere radius
public float? Radius;
}
public class ColliderShapeCapsule
{
// The capsule head. vector3
public float[] Offset;
// The capsule radius
public float? Radius;
// The capsule tail. vector3
public float[] Tail;
}
public class ColliderShape
{
// Dictionary object with extension-specific objects.
public glTFExtension Extensions;
// Application-specific data.
public glTFExtension Extras;
public ColliderShapeSphere Sphere;
public ColliderShapeCapsule Capsule;
}
public class VRMC_node_collider
{
public const string ExtensionName = "VRMC_node_collider";
public static readonly Utf8String ExtensionNameUtf8 = Utf8String.From(ExtensionName);
// Dictionary object with extension-specific objects.
public glTFExtension Extensions;
// Application-specific data.
public glTFExtension Extras;
public List<ColliderShape> Shapes;
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: b1f73d7cedc49cb4d9513f7a0a9ae9b6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,160 +0,0 @@
// This file is generated from JsonSchema. Don't modify this source code.
using System;
using System.Collections.Generic;
using System.Linq;
using UniJSON;
namespace UniGLTF.Extensions.VRMC_node_collider {
static public class GltfSerializer
{
public static void SerializeTo(ref UniGLTF.glTFExtension dst, VRMC_node_collider extension)
{
if (dst is glTFExtensionImport)
{
throw new NotImplementedException();
}
if (!(dst is glTFExtensionExport extensions))
{
extensions = new glTFExtensionExport();
dst = extensions;
}
var f = new JsonFormatter();
Serialize(f, extension);
extensions.Add(VRMC_node_collider.ExtensionName, f.GetStoreBytes());
}
public static void Serialize(JsonFormatter f, VRMC_node_collider value)
{
f.BeginMap();
if(value.Extensions!=null){
f.Key("extensions");
value.Extensions.Serialize(f);
}
if(value.Extras!=null){
f.Key("extras");
value.Extras.Serialize(f);
}
if(value.Shapes!=null&&value.Shapes.Count()>=0){
f.Key("shapes");
Serialize_Shapes(f, value.Shapes);
}
f.EndMap();
}
public static void Serialize_Shapes(JsonFormatter f, List<ColliderShape> value)
{
f.BeginList();
foreach(var item in value)
{
Serialize_Shapes_ITEM(f, item);
}
f.EndList();
}
public static void Serialize_Shapes_ITEM(JsonFormatter f, ColliderShape value)
{
f.BeginMap();
if(value.Extensions!=null){
f.Key("extensions");
value.Extensions.Serialize(f);
}
if(value.Extras!=null){
f.Key("extras");
value.Extras.Serialize(f);
}
if(value.Sphere!=null){
f.Key("sphere");
Serialize_Sphere(f, value.Sphere);
}
if(value.Capsule!=null){
f.Key("capsule");
Serialize_Capsule(f, value.Capsule);
}
f.EndMap();
}
public static void Serialize_Sphere(JsonFormatter f, ColliderShapeSphere value)
{
f.BeginMap();
if(value.Offset!=null&&value.Offset.Count()>=3){
f.Key("offset");
Serialize_Offset(f, value.Offset);
}
if(value.Radius.HasValue){
f.Key("radius");
f.Value(value.Radius.GetValueOrDefault());
}
f.EndMap();
}
public static void Serialize_Offset(JsonFormatter f, float[] value)
{
f.BeginList();
foreach(var item in value)
{
f.Value(item);
}
f.EndList();
}
public static void Serialize_Capsule(JsonFormatter f, ColliderShapeCapsule value)
{
f.BeginMap();
if(value.Offset!=null&&value.Offset.Count()>=3){
f.Key("offset");
Serialize_Offset(f, value.Offset);
}
if(value.Radius.HasValue){
f.Key("radius");
f.Value(value.Radius.GetValueOrDefault());
}
if(value.Tail!=null&&value.Tail.Count()>=3){
f.Key("tail");
Serialize_Tail(f, value.Tail);
}
f.EndMap();
}
public static void Serialize_Tail(JsonFormatter f, float[] value)
{
f.BeginList();
foreach(var item in value)
{
f.Value(item);
}
f.EndList();
}
} // class
} // namespace

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 8eb6c9672b71ea147867c73cb8d58a35
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -24,7 +24,6 @@ namespace UniVRM10
Storage.Gltf.extensionsUsed.Add(UniGLTF.Extensions.VRMC_vrm.VRMC_vrm.ExtensionName);
Storage.Gltf.extensionsUsed.Add(UniGLTF.Extensions.VRMC_materials_mtoon.VRMC_materials_mtoon.ExtensionName);
Storage.Gltf.extensionsUsed.Add(UniGLTF.Extensions.VRMC_springBone.VRMC_springBone.ExtensionName);
Storage.Gltf.extensionsUsed.Add(UniGLTF.Extensions.VRMC_node_collider.VRMC_node_collider.ExtensionName);
Storage.Gltf.extensionsUsed.Add(UniGLTF.Extensions.VRMC_node_constraint.VRMC_node_constraint.ExtensionName);
Storage.Gltf.buffers.Add(new glTFBuffer
{
@ -264,14 +263,14 @@ namespace UniVRM10
return (vrm, vrmSpringBone, thumbnailTextureIndex);
}
UniGLTF.Extensions.VRMC_node_collider.ColliderShape ExportShape(VRM10SpringBoneCollider z)
UniGLTF.Extensions.VRMC_springBone.ColliderShape ExportShape(VRM10SpringBoneCollider z)
{
var shape = new UniGLTF.Extensions.VRMC_node_collider.ColliderShape();
var shape = new UniGLTF.Extensions.VRMC_springBone.ColliderShape();
switch (z.ColliderType)
{
case VRM10SpringBoneColliderTypes.Sphere:
{
shape.Sphere = new UniGLTF.Extensions.VRMC_node_collider.ColliderShapeSphere
shape.Sphere = new UniGLTF.Extensions.VRMC_springBone.ColliderShapeSphere
{
Radius = z.Radius,
Offset = ReverseX(z.Offset),
@ -281,7 +280,7 @@ namespace UniVRM10
case VRM10SpringBoneColliderTypes.Capsule:
{
shape.Capsule = new UniGLTF.Extensions.VRMC_node_collider.ColliderShapeCapsule
shape.Capsule = new UniGLTF.Extensions.VRMC_springBone.ColliderShapeCapsule
{
Radius = z.Radius,
Offset = new float[] { z.Offset.x, z.Offset.y, z.Offset.z },
@ -311,6 +310,7 @@ namespace UniVRM10
{
var springBone = new UniGLTF.Extensions.VRMC_springBone.VRMC_springBone
{
ColliderGroups = new List<UniGLTF.Extensions.VRMC_springBone.ColliderGroup>(),
Springs = new List<UniGLTF.Extensions.VRMC_springBone.Spring>(),
};
@ -338,14 +338,14 @@ namespace UniVRM10
colliders.Add(nodeIndex);
var gltfNode = Storage.Gltf.nodes[nodeIndex];
// VRMC_node_collider
var collider = new UniGLTF.Extensions.VRMC_node_collider.VRMC_node_collider
{
Shapes = y.Colliders.Select(ExportShape).ToList(),
};
// // VRMC_node_collider
// var collider = new UniGLTF.Extensions.VRMC_node_collider.VRMC_node_collider
// {
// Shapes = y.Colliders.Select(ExportShape).ToList(),
// };
// serialize
UniGLTF.Extensions.VRMC_node_collider.GltfSerializer.SerializeTo(ref gltfNode.extensions, collider);
// // serialize
// UniGLTF.Extensions.VRMC_node_collider.GltfSerializer.SerializeTo(ref gltfNode.extensions, collider);
}
spring.ColliderGroups = colliders.ToArray();
}

View File

@ -396,51 +396,51 @@ namespace UniVRM10
}
}
// collider
springBone.ColliderGroups.AddRange(gltfSpring.ColliderGroups.Select(colliderNode =>
{
if (UniGLTF.Extensions.VRMC_node_collider.GltfDeserializer.TryGet(Parser.GLTF.nodes[colliderNode].extensions,
out UniGLTF.Extensions.VRMC_node_collider.VRMC_node_collider extension))
{
var node = Nodes[colliderNode];
var colliderGroup = node.gameObject.GetComponent<VRM10SpringBoneColliderGroup>();
if (colliderGroup == null)
{
colliderGroup = node.gameObject.AddComponent<VRM10SpringBoneColliderGroup>();
colliderGroup.Colliders.AddRange(extension.Shapes.Select(x =>
{
if (x.Sphere != null)
{
return new VRM10SpringBoneCollider
{
ColliderType = VRM10SpringBoneColliderTypes.Sphere,
Offset = Vector3InvertX(x.Sphere.Offset),
Radius = x.Sphere.Radius.Value,
};
}
else if (x.Capsule != null)
{
return new VRM10SpringBoneCollider
{
ColliderType = VRM10SpringBoneColliderTypes.Capsule,
Offset = Vector3InvertX(x.Capsule.Offset),
Radius = x.Capsule.Radius.Value,
Tail = Vector3InvertX(x.Capsule.Tail),
};
}
else
{
throw new NotImplementedException();
}
}));
}
return colliderGroup;
}
else
{
return null;
}
}).Where(x => x != null));
// // collider
// springBone.ColliderGroups.AddRange(gltfSpring.ColliderGroups.Select(colliderNode =>
// {
// if (UniGLTF.Extensions.VRMC_node_collider.GltfDeserializer.TryGet(Parser.GLTF.nodes[colliderNode].extensions,
// out UniGLTF.Extensions.VRMC_node_collider.VRMC_node_collider extension))
// {
// var node = Nodes[colliderNode];
// var colliderGroup = node.gameObject.GetComponent<VRM10SpringBoneColliderGroup>();
// if (colliderGroup == null)
// {
// colliderGroup = node.gameObject.AddComponent<VRM10SpringBoneColliderGroup>();
// colliderGroup.Colliders.AddRange(extension.Shapes.Select(x =>
// {
// if (x.Sphere != null)
// {
// return new VRM10SpringBoneCollider
// {
// ColliderType = VRM10SpringBoneColliderTypes.Sphere,
// Offset = Vector3InvertX(x.Sphere.Offset),
// Radius = x.Sphere.Radius.Value,
// };
// }
// else if (x.Capsule != null)
// {
// return new VRM10SpringBoneCollider
// {
// ColliderType = VRM10SpringBoneColliderTypes.Capsule,
// Offset = Vector3InvertX(x.Capsule.Offset),
// Radius = x.Capsule.Radius.Value,
// Tail = Vector3InvertX(x.Capsule.Tail),
// };
// }
// else
// {
// throw new NotImplementedException();
// }
// }));
// }
// return colliderGroup;
// }
// else
// {
// return null;
// }
// }).Where(x => x != null));
}
}
}

View File

@ -23,16 +23,22 @@ namespace UniVRM10
{
var colliderNodes = new List<int>();
var springBone = new UniGLTF.Extensions.VRMC_springBone.VRMC_springBone
{
ColliderGroups = new List<UniGLTF.Extensions.VRMC_springBone.ColliderGroup>(),
Springs = new List<UniGLTF.Extensions.VRMC_springBone.Spring>(),
};
foreach (var x in sa["colliderGroups"].ArrayItems())
{
var node = x["node"].GetInt32();
colliderNodes.Add(node);
var gltfNode = gltf.nodes[node];
var collider = new UniGLTF.Extensions.VRMC_node_collider.VRMC_node_collider()
var colliderGroup = new UniGLTF.Extensions.VRMC_springBone.ColliderGroup()
{
Shapes = new List<UniGLTF.Extensions.VRMC_node_collider.ColliderShape>(),
Colliders = new List<UniGLTF.Extensions.VRMC_springBone.Collider>(),
};
springBone.ColliderGroups.Add(colliderGroup);
// {
// "node": 14,
@ -65,31 +71,20 @@ namespace UniVRM10
// },
foreach (var y in x["colliders"].ArrayItems())
{
collider.Shapes.Add(new UniGLTF.Extensions.VRMC_node_collider.ColliderShape
colliderGroup.Colliders.Add(new UniGLTF.Extensions.VRMC_springBone.Collider
{
Sphere = new UniGLTF.Extensions.VRMC_node_collider.ColliderShapeSphere
Shape = new UniGLTF.Extensions.VRMC_springBone.ColliderShape
{
Offset = MigrateVector3.Migrate(y["offset"]),
Radius = y["radius"].GetSingle()
Sphere = new UniGLTF.Extensions.VRMC_springBone.ColliderShapeSphere
{
Offset = MigrateVector3.Migrate(y["offset"]),
Radius = y["radius"].GetSingle()
}
}
});
}
if (!(gltfNode.extensions is UniGLTF.glTFExtensionExport extensions))
{
extensions = new UniGLTF.glTFExtensionExport();
gltfNode.extensions = extensions;
}
var f = new JsonFormatter();
UniGLTF.Extensions.VRMC_node_collider.GltfSerializer.Serialize(f, collider);
extensions.Add(UniGLTF.Extensions.VRMC_node_collider.VRMC_node_collider.ExtensionName, f.GetStoreBytes());
}
var springBone = new UniGLTF.Extensions.VRMC_springBone.VRMC_springBone
{
Springs = new List<UniGLTF.Extensions.VRMC_springBone.Spring>(),
};
foreach (var x in sa["boneGroups"].ArrayItems())
{
// {
@ -123,7 +118,7 @@ namespace UniVRM10
var spring = new UniGLTF.Extensions.VRMC_springBone.Spring
{
Name = comment,
ColliderGroups = x["colliderGroups"].ArrayItems().Select(z => colliderNodes[z.GetInt32()]).ToArray(),
ColliderGroups = x["colliderGroups"].ArrayItems().Select(z => z.GetInt32()).ToArray(),
Joints = new List<UniGLTF.Extensions.VRMC_springBone.SpringBoneJoint>(),
};

View File

@ -245,11 +245,10 @@ namespace UniVRM10
Assert.True(UniGLTF.Extensions.VRMC_springBone.GltfDeserializer.TryGet(parser1.GLTF.extensions, out UniGLTF.Extensions.VRMC_springBone.VRMC_springBone springBone));
var spring = springBone.Springs[0];
var colliderNodeIndex = spring.ColliderGroups[0];
Assert.True(UniGLTF.Extensions.VRMC_node_collider.GltfDeserializer.TryGet(parser1.GLTF.nodes[colliderNodeIndex].extensions, out UniGLTF.Extensions.VRMC_node_collider.VRMC_node_collider colliderGroup));
// x軸だけが反転する
Assert.AreEqual(-VALUE.x, colliderGroup.Shapes[0].Sphere.Offset[0]);
Assert.AreEqual(VALUE.y, colliderGroup.Shapes[0].Sphere.Offset[1]);
Assert.AreEqual(VALUE.z, colliderGroup.Shapes[0].Sphere.Offset[2]);
Assert.AreEqual(-VALUE.x, springBone.ColliderGroups[0].Colliders[0].Shape.Sphere.Offset[0]);
Assert.AreEqual(VALUE.y, springBone.ColliderGroups[0].Colliders[0].Shape.Sphere.Offset[1]);
Assert.AreEqual(VALUE.z, springBone.ColliderGroups[0].Colliders[0].Shape.Sphere.Offset[2]);
}
}
}