Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by JTown 1 · Nov 12, 2010 at 08:09 AM · javascriptmeshtriangles

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

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Rodrigo Moraes · Nov 12, 2010 at 08:20 AM 0
Share

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

avatar image JTown 1 · Nov 12, 2010 at 08:23 AM 0
Share

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?

avatar image Rodrigo Moraes · Nov 12, 2010 at 08:26 AM 0
Share

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

avatar image JTown 1 · Nov 12, 2010 at 08:27 AM 0
Share

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

avatar image Rodrigo Moraes · Nov 12, 2010 at 08:37 AM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JTown 1 · Nov 12, 2010 at 08:48 AM 0
Share

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.

avatar image StephanK · Nov 12, 2010 at 09:03 AM 0
Share

If you're using c# do this: int[] tris = temp.Triangulate();

In js do that: var tris = temp.Triangulate();

avatar image JTown 1 · Nov 12, 2010 at 09:13 AM 0
Share

I'm an idiot -- dumb typos in creating my Vector2 array. It works now. Thanks!

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges