public void LoadPC2(string filename) { MegaPointCache am = (MegaPointCache)target; oldverts = am.Verts; mods = am.gameObject.GetComponent <MegaModifiers>(); if (mods == null) { Debug.LogWarning("You need to add a Mega Modify Object component first!"); return; } lastpath = filename; // Clear what we have Verts.Clear(); FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, System.IO.FileShare.Read); long len = fs.Length; BinaryReader br = new BinaryReader(fs); string sig = MegaParse.ReadStr(br); if (sig != "POINTCACHE2") { EditorUtility.DisplayDialog("PC2 Importer", "The selected file does not appear to be a valid PC2 File", "Ok"); br.Close(); return; } int fileVersion = br.ReadInt32(); if (fileVersion != 1) { br.Close(); return; } int numPoints = br.ReadInt32(); br.ReadSingle(); br.ReadSingle(); int numSamples = br.ReadInt32(); long csamples = (len - 24) / (numPoints * 12); numSamples = (int)csamples; am.Verts = new MegaPCVert[numPoints]; for (int i = 0; i < am.Verts.Length; i++) { am.Verts[i] = new MegaPCVert(); am.Verts[i].points = new Vector3[numSamples]; } for (int i = 0; i < numSamples; i++) { for (int v = 0; v < numPoints; v++) { am.Verts[v].points[i] = MegaParse.ReadP3(br); } } BuildData(mods, am, filename); br.Close(); }
public void LoadPC2(string filename) { MegaPointCache am = (MegaPointCache)target; mods = am.gameObject.GetComponent <MegaModifiers>(); if (mods == null) { Debug.LogWarning("You need to add a Mega Modify Object component first!"); return; } lastpath = filename; // Clear what we have Verts.Clear(); FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, System.IO.FileShare.Read); BinaryReader br = new BinaryReader(fs); string sig = MegaParse.ReadStr(br); if (sig != "POINTCACHE2") { br.Close(); return; } int fileVersion = br.ReadInt32(); if (fileVersion != 1) { br.Close(); return; } int numPoints = br.ReadInt32(); br.ReadSingle(); br.ReadSingle(); int numSamples = br.ReadInt32(); am.Verts = new MegaPCVert[numPoints]; for (int i = 0; i < am.Verts.Length; i++) { am.Verts[i] = new MegaPCVert(); am.Verts[i].points = new Vector3[numSamples]; } for (int i = 0; i < numSamples; i++) { for (int v = 0; v < numPoints; v++) { am.Verts[v].points[i] = MegaParse.ReadP3(br); } } BuildData(mods, am, filename); br.Close(); }