- Home /
Help me use Triangulator.cs (from wiki) with javascript
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:
var triangulator : Triangulator = GetComponent("Triangulator");
temp = new Triangulator(newVertices2D.ToBuiltin(Vector2));
temp.Triangulate();
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 :)
The Triangulator class in http://www.unifycommunity.com/wiki/index.php?title=Triangulator doesn't extend $$anonymous$$onoBehaviour. Does yours differs from it?
I forgot I did modify line 4 to "public class Triangulator : $$anonymous$$onoBehaviour" 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 $$anonymous$$onoBehavior classes. They are instantiated by Unity itself.
So now I get the warning "The class defined in the script is not derived from $$anonymous$$onoBehaviour 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.
Answer by StephanK · Nov 12, 2010 at 08:40 AM
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.
If you're using c# do this: int[] tris = temp.Triangulate();
In js do that: var tris = temp.Triangulate();
I'm an idiot -- dumb typos in creating my Vector2 array. It works now. Thanks!
Your answer
Follow this Question
Related Questions
How to find triangles using variables 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Getting Triangles from Mesh 2 Answers
Scripting Meshes Subdivision(Javascript) 0 Answers