mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-26 12:55:18 -05:00
LINQやめ
This commit is contained in:
@@ -115,8 +115,7 @@ namespace UniGLTF
|
||||
var indicesAccessorIndex = data.ExtendBufferAndGetAccessorIndex(indices.Select(x => (uint)m_vertexIndexMap[x]).ToArray(), glBufferTarget.ELEMENT_ARRAY_BUFFER);
|
||||
var positions = m_positions.ToArray();
|
||||
var positionAccessorIndex = data.ExtendBufferAndGetAccessorIndex(positions, glBufferTarget.ARRAY_BUFFER);
|
||||
data.GLTF.accessors[positionAccessorIndex].min = positions.Aggregate(positions[0], (a, b) => new Vector3(Mathf.Min(a.x, b.x), Math.Min(a.y, b.y), Mathf.Min(a.z, b.z))).ToArray();
|
||||
data.GLTF.accessors[positionAccessorIndex].max = positions.Aggregate(positions[0], (a, b) => new Vector3(Mathf.Max(a.x, b.x), Math.Max(a.y, b.y), Mathf.Max(a.z, b.z))).ToArray();
|
||||
AccessorsBounds.UpdatePositionAccessorsBounds(data.GLTF.accessors[positionAccessorIndex], positions);
|
||||
|
||||
var normals = m_normals.ToArray();
|
||||
var normalAccessorIndex = data.ExtendBufferAndGetAccessorIndex(normals, glBufferTarget.ARRAY_BUFFER);
|
||||
|
||||
@@ -32,8 +32,7 @@ namespace UniGLTF
|
||||
var materials = unityMesh.Materials;
|
||||
var positions = mesh.vertices.Select(axisInverter.InvertVector3).ToArray();
|
||||
var positionAccessorIndex = data.ExtendBufferAndGetAccessorIndex(positions, glBufferTarget.ARRAY_BUFFER);
|
||||
data.GLTF.accessors[positionAccessorIndex].min = positions.Aggregate(positions[0], (a, b) => new Vector3(Mathf.Min(a.x, b.x), Math.Min(a.y, b.y), Mathf.Min(a.z, b.z))).ToArray();
|
||||
data.GLTF.accessors[positionAccessorIndex].max = positions.Aggregate(positions[0], (a, b) => new Vector3(Mathf.Max(a.x, b.x), Math.Max(a.y, b.y), Mathf.Max(a.z, b.z))).ToArray();
|
||||
AccessorsBounds.UpdatePositionAccessorsBounds(data.GLTF.accessors[positionAccessorIndex], positions);
|
||||
|
||||
var normalAccessorIndex = data.ExtendBufferAndGetAccessorIndex(mesh.normals.Select(y => axisInverter.InvertVector3(y.normalized)).ToArray(), glBufferTarget.ARRAY_BUFFER);
|
||||
|
||||
|
||||
37
Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/PositionMinMax.cs
Normal file
37
Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/PositionMinMax.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
/// <summary>
|
||||
/// https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#accessors-bounds
|
||||
///
|
||||
/// Animation input and vertex position attribute accessors MUST have accessor.min and accessor.max defined. For all other accessors, these properties are optional.
|
||||
/// </summary>
|
||||
public static class AccessorsBounds
|
||||
{
|
||||
public static void UpdatePositionAccessorsBounds(glTFAccessor accessor, Vector3[] positions)
|
||||
{
|
||||
if (positions.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var minX = positions[0].x;
|
||||
var minY = positions[0].y;
|
||||
var minZ = positions[0].z;
|
||||
var maxX = positions[0].x;
|
||||
var maxY = positions[0].y;
|
||||
var maxZ = positions[0].z;
|
||||
foreach (var position in positions)
|
||||
{
|
||||
minX = Mathf.Min(minX, position.x);
|
||||
minY = Mathf.Min(minY, position.y);
|
||||
minZ = Mathf.Min(minZ, position.z);
|
||||
maxX = Mathf.Max(maxX, position.x);
|
||||
maxY = Mathf.Max(maxY, position.y);
|
||||
maxZ = Mathf.Max(maxZ, position.z);
|
||||
}
|
||||
accessor.min = new float[] { minX, minY, minZ };
|
||||
accessor.max = new float[] { maxX, maxY, maxZ };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ebb201c801060d4a9865057558d1fbd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user