|
edit: update to reflect changes made after comments So I'm trying to build a mesh with code and generate triangles. I've successfully made tris manually, but I'm hoping to utilize this Triangulator script to generate tris for more complex concave/convex shapes. http://www.unifycommunity.com/wiki/index.php?title=Triangulator Here's the triangulator code in C# -- I'm very unfamiliar with C# so this is pretty confusing to me. Here's a thread that has helped me so far http://forum.unity3d.com/threads/27346-JavaScript.Array-gt-C-.List-and-constructor?highlight=constructor+triangulator So I use that code:
But that doesn't seem to do much. I assume the .cs script ran through Triangulate with my Vector2 array, but how do I retrieve the results in this .js script? Any help is greatly appreciated :)
(comments are locked)
|
|
Probably you are trying to attach the Script to a GameObject and therefore made it a MonoBehaviour. I don't know this script, but I guess it's only a Helper class meaning that it doesn't need to be attached to a GameObject and also shouldn't extend MonoBehaviour. I think you're right -- I dug myself my own little hole by trying to solve it without properly knowing how. So I'm back using the 3 line snippet found in that thread. No errors or warnings, but no tris either. So how do I get the triangulated array of int from the .cs file? I try stuff like newTriangles = temp.Triangulate(); with no success.
Nov 12 '10 at 08:48 AM
JTown 1
If you're using c# do this: int[] tris = temp.Triangulate(); In js do that: var tris = temp.Triangulate();
Nov 12 '10 at 09:03 AM
StephanK
I'm an idiot -- dumb typos in creating my Vector2 array. It works now. Thanks!
Nov 12 '10 at 09:13 AM
JTown 1
(comments are locked)
|

The Triangulator class in http://www.unifycommunity.com/wiki/index.php?title=Triangulator doesn't extend MonoBehaviour. Does yours differs from it?
I forgot I did modify line 4 to "public class Triangulator : MonoBehaviour" because it was giving me an error -- should I remove that and find a solution to my original error?
Yes, you can't do that -- as the error says, you can't instantiate MonoBehavior classes. They are instantiated by Unity itself.
So now I get the warning "The class defined in the script is not derived from MonoBehaviour or ScriptableObject!" in monobehavior.cpp and still no tris.
I'm thinking I'm still failing to actually receive the tris back in the js file..
Hmmm, I can't help much. But you should update the question with the new info and perhaps a more detailed stack trace information.