scripts
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Parabox.STL
|
||||
{
|
||||
// Token: 0x02000004 RID: 4
|
||||
public static class pb_Stl_Exporter
|
||||
{
|
||||
// Token: 0x06000007 RID: 7 RVA: 0x00002638 File Offset: 0x00000838
|
||||
public static bool Export(string path, GameObject[] gameObjects, FileType type)
|
||||
{
|
||||
Mesh[] array = pb_Stl_Exporter.CreateWorldSpaceMeshesWithTransforms(gameObjects.Select((GameObject x) => x.transform).ToArray<Transform>());
|
||||
bool flag = false;
|
||||
if (array != null && array.Length != 0 && !string.IsNullOrEmpty(path))
|
||||
{
|
||||
flag = pb_Stl.WriteFile(path, array, type, true);
|
||||
}
|
||||
int num = 0;
|
||||
while (array != null && num < array.Length)
|
||||
{
|
||||
global::UnityEngine.Object.DestroyImmediate(array[num]);
|
||||
num++;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
// Token: 0x06000008 RID: 8 RVA: 0x000026AC File Offset: 0x000008AC
|
||||
private static Mesh[] CreateWorldSpaceMeshesWithTransforms(IList<Transform> transforms)
|
||||
{
|
||||
if (transforms == null || transforms.Count < 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Vector3 vector = Vector3.zero;
|
||||
for (int i = 0; i < transforms.Count; i++)
|
||||
{
|
||||
vector += transforms[i].position;
|
||||
}
|
||||
Vector3 vector2 = vector / (float)transforms.Count;
|
||||
GameObject gameObject = new GameObject();
|
||||
gameObject.name = "ROOT";
|
||||
gameObject.transform.position = vector2;
|
||||
foreach (Transform transform in transforms)
|
||||
{
|
||||
GameObject gameObject2 = (GameObject)global::UnityEngine.Object.Instantiate(transform.gameObject);
|
||||
gameObject2.transform.SetParent(transform.parent, false);
|
||||
gameObject2.transform.SetParent(gameObject.transform, true);
|
||||
}
|
||||
gameObject.transform.position = Vector3.zero;
|
||||
List<MeshFilter> list = (from x in gameObject.GetComponentsInChildren<MeshFilter>()
|
||||
where x.sharedMesh != null
|
||||
select x).ToList<MeshFilter>();
|
||||
int count = list.Count;
|
||||
Mesh[] array = new Mesh[count];
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
Transform transform2 = list[j].transform;
|
||||
Vector3[] vertices = list[j].sharedMesh.vertices;
|
||||
Vector3[] normals = list[j].sharedMesh.normals;
|
||||
for (int k = 0; k < vertices.Length; k++)
|
||||
{
|
||||
vertices[k] = transform2.TransformPoint(vertices[k]);
|
||||
normals[k] = transform2.TransformDirection(normals[k]);
|
||||
}
|
||||
array[j] = new Mesh
|
||||
{
|
||||
name = list[j].name,
|
||||
vertices = vertices,
|
||||
normals = normals,
|
||||
triangles = list[j].sharedMesh.triangles
|
||||
};
|
||||
}
|
||||
global::UnityEngine.Object.DestroyImmediate(gameObject);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user