private static UBoneWeight[] FromSimplifyBoneWeights(BoneWeight[] boneWeights) { if (boneWeights == null) { return(null); } var newBoneWeights = new UBoneWeight[boneWeights.Length]; for (int i = 0; i < boneWeights.Length; i++) { var boneWeight = boneWeights[i]; newBoneWeights[i] = new UBoneWeight() { boneIndex0 = boneWeight.boneIndex0, boneIndex1 = boneWeight.boneIndex1, boneIndex2 = boneWeight.boneIndex2, boneIndex3 = boneWeight.boneIndex3, weight0 = boneWeight.boneWeight0, weight1 = boneWeight.boneWeight1, weight2 = boneWeight.boneWeight2, weight3 = boneWeight.boneWeight3 }; } return(newBoneWeights); }
private static void AddToList(ref List <BoneWeight> list, UBoneWeight[] arr, int previousVertexCount, int currentVertexCount, int totalVertexCount) { if (arr == null || arr.Length == 0) { if (list != null) { for (int i = 0; i < currentVertexCount; i++) { list.Add(new BoneWeight()); } } return; } if (list == null) { list = new List <BoneWeight>(totalVertexCount); for (int i = 0; i < previousVertexCount; i++) { list.Add(new BoneWeight()); } } for (int i = 0; i < arr.Length; i++) { UBoneWeight boneWeight = arr[i]; list.Add(new BoneWeight( boneWeight.boneIndex0, boneWeight.boneIndex1, boneWeight.boneIndex2, boneWeight.boneIndex3, boneWeight.weight0, boneWeight.weight1, boneWeight.weight2, boneWeight.weight3)); } }
static object PerformMemberwiseClone(ref object o) { var ins = new UnityEngine.BoneWeight(); ins = (UnityEngine.BoneWeight)o; return(ins); }
static void WriteBackInstance(CSHotFix.Runtime.Enviorment.AppDomain __domain, StackObject *ptr_of_this_method, IList <object> __mStack, ref UnityEngine.BoneWeight instance_of_this_method) { ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method); switch (ptr_of_this_method->ObjectType) { case ObjectTypes.Object: { __mStack[ptr_of_this_method->Value] = instance_of_this_method; } break; case ObjectTypes.FieldReference: { var ___obj = __mStack[ptr_of_this_method->Value]; if (___obj is ILTypeInstance) { ((ILTypeInstance)___obj)[ptr_of_this_method->ValueLow] = instance_of_this_method; } else { var t = __domain.GetType(___obj.GetType()) as CLRType; t.SetFieldValue(ptr_of_this_method->ValueLow, ref ___obj, instance_of_this_method); } } break; case ObjectTypes.StaticFieldReference: { var t = __domain.GetType(ptr_of_this_method->Value); if (t is ILType) { ((ILType)t).StaticInstance[ptr_of_this_method->ValueLow] = instance_of_this_method; } else { ((CLRType)t).SetStaticFieldValue(ptr_of_this_method->ValueLow, instance_of_this_method); } } break; case ObjectTypes.ArrayReference: { var instance_of_arrayReference = __mStack[ptr_of_this_method->Value] as UnityEngine.BoneWeight[]; instance_of_arrayReference[ptr_of_this_method->ValueLow] = instance_of_this_method; } break; } }
static StackObject *op_Inequality_19(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 2); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); UnityEngine.BoneWeight rhs = (UnityEngine.BoneWeight) typeof(UnityEngine.BoneWeight).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 2); UnityEngine.BoneWeight lhs = (UnityEngine.BoneWeight) typeof(UnityEngine.BoneWeight).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); var result_of_this_method = lhs != rhs; __ret->ObjectType = ObjectTypes.Integer; __ret->Value = result_of_this_method ? 1 : 0; return(__ret + 1); }
private static void TransformVertices(UVector3[] vertices, UBoneWeight[] boneWeights, UMatrix[] oldBindposes, UMatrix[] newBindposes) { // TODO: Is this method doing what it is supposed to?? It has not been properly tested // First invert the old bindposes for (int i = 0; i < oldBindposes.Length; i++) { oldBindposes[i] = oldBindposes[i].inverse; } // The transform the vertices for (int i = 0; i < vertices.Length; i++) { UVector3 vertex = vertices[i]; UBoneWeight boneWeight = boneWeights[i]; if (boneWeight.weight0 > 0f) { int boneIndex = boneWeight.boneIndex0; float weight = boneWeight.weight0; vertex = ScaleMatrix(ref newBindposes[boneIndex], weight) * (ScaleMatrix(ref oldBindposes[boneIndex], weight) * vertex); } if (boneWeight.weight1 > 0f) { int boneIndex = boneWeight.boneIndex1; float weight = boneWeight.weight1; vertex = ScaleMatrix(ref newBindposes[boneIndex], weight) * (ScaleMatrix(ref oldBindposes[boneIndex], weight) * vertex); } if (boneWeight.weight2 > 0f) { int boneIndex = boneWeight.boneIndex2; float weight = boneWeight.weight2; vertex = ScaleMatrix(ref newBindposes[boneIndex], weight) * (ScaleMatrix(ref oldBindposes[boneIndex], weight) * vertex); } if (boneWeight.weight3 > 0f) { int boneIndex = boneWeight.boneIndex3; float weight = boneWeight.weight3; vertex = ScaleMatrix(ref newBindposes[boneIndex], weight) * (ScaleMatrix(ref oldBindposes[boneIndex], weight) * vertex); } vertices[i] = vertex; } }
static StackObject *GetHashCode_16(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 1); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method); UnityEngine.BoneWeight instance_of_this_method = (UnityEngine.BoneWeight) typeof(UnityEngine.BoneWeight).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); var result_of_this_method = instance_of_this_method.GetHashCode(); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); WriteBackInstance(__domain, ptr_of_this_method, __mStack, ref instance_of_this_method); __intp.Free(ptr_of_this_method); __ret->ObjectType = ObjectTypes.Integer; __ret->Value = result_of_this_method; return(__ret + 1); }
static StackObject *set_boneIndex3_15(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 2); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.Int32 @value = ptr_of_this_method->Value; ptr_of_this_method = ILIntepreter.Minus(__esp, 2); ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method); UnityEngine.BoneWeight instance_of_this_method = (UnityEngine.BoneWeight) typeof(UnityEngine.BoneWeight).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); instance_of_this_method.boneIndex3 = value; ptr_of_this_method = ILIntepreter.Minus(__esp, 2); WriteBackInstance(__domain, ptr_of_this_method, __mStack, ref instance_of_this_method); __intp.Free(ptr_of_this_method); return(__ret); }
/// <summary> /// https://github.com/vrm-c/UniVRM/issues/800 /// /// SubMesh 単位に分割する。 /// SubMesh を Gltf の Primitive に対応させる。 /// </summary> /// <param name="mesh"></param> /// <param name="materials"></param> /// <param name="storage"></param> /// <param name="gltfMesh"></param> /// <param name="option"></param> static IEnumerable <glTFPrimitives> ExportMeshDivided(this VrmLib.Mesh mesh, List <object> materials, Vrm10Storage storage, ExportArgs option) { var bufferIndex = 0; var usedIndices = new List <int>(); var meshIndices = SpanLike.CopyFrom(mesh.IndexBuffer.GetAsIntArray()); var positions = mesh.VertexBuffer.Positions.GetSpan <UnityEngine.Vector3>().ToArray(); var normals = mesh.VertexBuffer.Normals.GetSpan <UnityEngine.Vector3>().ToArray(); var uv = mesh.VertexBuffer.TexCoords.GetSpan <UnityEngine.Vector2>().ToArray(); var hasSkin = mesh.VertexBuffer.Weights != null; var weights = mesh.VertexBuffer.Weights?.GetSpan <UnityEngine.Vector4>().ToArray(); var joints = mesh.VertexBuffer.Joints?.GetSpan <SkinJoints>().ToArray(); Func <int, int> getJointIndex = default; if (hasSkin) { getJointIndex = i => { return(i); }; } foreach (var submesh in mesh.Submeshes) { var indices = meshIndices.Slice(submesh.Offset, submesh.DrawCount).ToArray(); var hash = new HashSet <int>(indices); // mesh // index の順に attributes を蓄える var buffer = new MeshExportUtil.VertexBuffer(indices.Length, getJointIndex); usedIndices.Clear(); for (int k = 0; k < positions.Length; ++k) { if (hash.Contains(k)) { // indices から参照される頂点だけを蓄える usedIndices.Add(k); buffer.Push(k, positions[k], normals[k], uv[k]); if (getJointIndex != null) { var j = joints[k]; var w = weights[k]; var boneWeight = new UnityEngine.BoneWeight { boneIndex0 = j.Joint0, boneIndex1 = j.Joint1, boneIndex2 = j.Joint2, boneIndex3 = j.Joint3, weight0 = w.x, weight1 = w.y, weight2 = w.z, weight3 = w.w, }; buffer.Push(boneWeight); } } } var materialIndex = submesh.Material; var gltfPrimitive = buffer.ToGltfPrimitive(storage.Gltf, bufferIndex, materialIndex, indices); // blendShape for (int j = 0; j < mesh.MorphTargets.Count; ++j) { var blendShape = new MeshExportUtil.BlendShapeBuffer(indices.Length); // index の順に attributes を蓄える var morph = mesh.MorphTargets[j]; var blendShapePositions = morph.VertexBuffer.Positions.GetSpan <UnityEngine.Vector3>(); SpanLike <UnityEngine.Vector3>?blendShapeNormals = default; if (morph.VertexBuffer.Normals != null) { blendShapeNormals = morph.VertexBuffer.Normals.GetSpan <UnityEngine.Vector3>(); } foreach (var k in usedIndices) { blendShape.Push( blendShapePositions[k], blendShapeNormals.HasValue ? blendShapeNormals.Value[k] : UnityEngine.Vector3.zero ); } gltfPrimitive.targets.Add(blendShape.ToGltf(storage.Gltf, bufferIndex, !option.removeMorphNormal)); } yield return(gltfPrimitive); } }