You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

33 lines
889 B

using System;
using System.Runtime.InteropServices;
using UnityEngine;
public static class QExtensions
{
public static TStruct[] ToStructArray<TStruct>(this IntPtr ptr, int count)
{
if (ptr == IntPtr.Zero)
return null;
TStruct[] result = new TStruct[count];
int size = Marshal.SizeOf<TStruct>();
IntPtr current = ptr;
for (int i = 0; i < count; ++i)
{
result[i] = Marshal.PtrToStructure<TStruct>(current);
current = new IntPtr(current.ToInt64() + size);
}
return result;
}
public static Vector3 ToVector3(this QVec3 vec)
{
return new Vector3(vec.x, vec.y, vec.z);
}
public static Vector3 ToVector3(this QTriVertex triVertex)
{
byte[] v = triVertex.v;
return new Vector3(v[0] / 255f, v[1] / 255f, v[2] / 255f);
}
}