x


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 :)

more ▼

asked Nov 12 '10 at 08:09 AM

JTown 1 gravatar image

JTown 1
38 2 2 9

The Triangulator class in http://www.unifycommunity.com/wiki/index.php?title=Triangulator doesn't extend MonoBehaviour. Does yours differs from it?

Nov 12 '10 at 08:20 AM Rodrigo Moraes

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?

Nov 12 '10 at 08:23 AM JTown 1

Yes, you can't do that -- as the error says, you can't instantiate MonoBehavior classes. They are instantiated by Unity itself.

Nov 12 '10 at 08:26 AM Rodrigo Moraes

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..

Nov 12 '10 at 08:27 AM JTown 1

Hmmm, I can't help much. But you should update the question with the new info and perhaps a more detailed stack trace information.

Nov 12 '10 at 08:37 AM Rodrigo Moraes
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Nov 12 '10 at 08:40 AM

StephanK gravatar image

StephanK
6k 39 53 93

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)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5070
x3456
x1357
x61

asked: Nov 12 '10 at 08:09 AM

Seen: 1971 times

Last Updated: Nov 12 '10 at 08:57 AM