示例#1
0
        static void ReverseVector3Array(glTF gltf, int accessorIndex, HashSet <int> used)
        {
            if (accessorIndex == -1)
            {
                return;
            }

            if (!used.Add(accessorIndex))
            {
                return;
            }

            var accessor        = gltf.accessors[accessorIndex];
            var bufferViewIndex = -1;

            if (accessor.bufferView != -1)
            {
                bufferViewIndex = accessor.bufferView;
            }
            else if (accessor.sparse?.values != null && accessor.sparse.values.bufferView != -1)
            {
                bufferViewIndex = accessor.sparse.values.bufferView;
            }

            if (bufferViewIndex != -1)
            {
                var buffer = gltf.GetViewBytes(bufferViewIndex);
                var span   = VrmLib.SpanLike.Wrap <UnityEngine.Vector3>(buffer);
                for (int i = 0; i < span.Length; ++i)
                {
                    span[i] = span[i].RotateY180();
                }
            }
        }
示例#2
0
 public ArraySegment <byte> GetImageBytes(glTFImage image)
 {
     if (string.IsNullOrEmpty(image.uri))
     {
         return(GLTF.GetViewBytes(IO, image.bufferView));
     }
     else
     {
         return(IO.Get(image.uri));
     }
 }
示例#3
0
        static void ReverseVector3Array(glTF gltf, int accessorIndex, HashSet <int> used)
        {
            if (!used.Add(accessorIndex))
            {
                return;
            }

            var accessor = gltf.accessors[accessorIndex];
            var buffer   = gltf.GetViewBytes(accessor.bufferView);
            var span     = VrmLib.SpanLike.Wrap <UnityEngine.Vector3>(buffer);

            for (int i = 0; i < span.Length; ++i)
            {
                span[i] = span[i].RotateY180();
            }
        }
示例#4
0
        /// <summary>
        /// シーンをY軸で180度回転する
        /// </summary>
        /// <param name="gltf"></param>
        public static void Rotate(glTF gltf)
        {
            foreach (var node in gltf.nodes)
            {
                Rotate(node);
            }

            // mesh の回転のみでよい
            var used = new HashSet <int>();

            foreach (var mesh in gltf.meshes)
            {
                foreach (var prim in mesh.primitives)
                {
                    ReverseVector3Array(gltf, prim.attributes.POSITION, used);
                    ReverseVector3Array(gltf, prim.attributes.NORMAL, used);
                    foreach (var target in prim.targets)
                    {
                        ReverseVector3Array(gltf, target.POSITION, used);
                        ReverseVector3Array(gltf, target.NORMAL, used);
                    }
                }
            }

            foreach (var skin in gltf.skins)
            {
                if (used.Add(skin.inverseBindMatrices))
                {
                    var accessor = gltf.accessors[skin.inverseBindMatrices];
                    var buffer   = gltf.GetViewBytes(accessor.bufferView);
                    var span     = VrmLib.SpanLike.Wrap <UnityEngine.Matrix4x4>(buffer);
                    for (int i = 0; i < span.Length; ++i)
                    {
                        span[i] = span[i].RotateY180();
                    }
                }
            }
        }