karl- / pb_Stl

STL import/export for Unity, supporting both ASCII and Binary.
MIT License
179 stars 43 forks source link

Hi! please, how can I import via script in runtime? #5

Closed ZoomDomain closed 6 years ago

ZoomDomain commented 6 years ago

How can I import an STL to a GO in runtime via script? which functions? maybe add the infos to the readme file? THANKS!

karl- commented 6 years ago

Check out pb_Stl_Importer.cs. The Import function returns an array of meshes. Usually it will just be a single mesh, but if the vertex count is greater than the max allowed it will be split into multiple meshes.

Ex:

Mesh[] result =  pb_Stl_Importer.Import("/dir/MyModel.stl");

foreach(Mesh m in result)
{
    GameObject go = new GameObject();
    go.AddComponent<MeshRenderer>().sharedMaterial = material;
    go.AddComponent<MeshFilter>().sharedMesh = m;
}
ZoomDomain commented 6 years ago

Brilliant Thanks! Import namespace parabox.STL too :D