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 saiato · Sep 03, 2013 at 10:22 PM · classestrianglesvertice manipulation

Drawing a series of triangles using scripts

I am new to Unity and attempting to translate one of my games to Unity. A major component of the game is drawing a tree of triangles, which wasn't that difficult in the original language (Processing), but I am having a lot of trouble understanding how to do this in Unity. The original algorithm works like so:

  • Create a Layer object (stores transforms)

  • Inside the layer object, create a Tree object (stores array of branches)

  • Inside the Tree object, create an array of Branch objects (triangles) using the previous branch's vertices to determine where the new one will be drawn

So far, the best equivalent I've been able to come up with is using prefabs in place of the Layer, Tree, and Branch classes (making the branches children of Tree, and Tree a child of Layer), and creating a mesh for each branch by manipulating the MeshFilter component for each Branch prefab. Everything is instantiated using scripts. I am a bit worried that this mesh method may be too expensive, and also not be able to render things like stroke as I was able to when in a 2D system. Even if this is the correct approach, I'm not 100% sure how to implement it in Unity.

What is the correct way to build something like this? I feel a bit lost coming from an OOP language to Unity's stage-like environment.

Comment
Add comment
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

1 Reply

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

Answer by scipiothegreat · Sep 03, 2013 at 11:14 PM

You can still have the classes you want in unity. The scripts that show up in the inspector are just derived from the MonoBehaviour class. You can define your own classes like normal and then have a MonoBehaviour manipulate them.

Using Instantiate can be very expensive, So it would probably be best to have a Pool of branch meshes that just recycled and regenerated when it passes the camera.

Meshes can be built by using an array of Vector3s for each vertex. Triangles are made using an array of ints, each value is used to index the vertex array. The triangle array must be exactly three times longer than the vertex array.

Comment
Add comment · Show 2 · 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 Eric5h5 · Sep 03, 2013 at 11:23 PM 0
Share

The triangle array only needs to be a multiple of 3. It doesn't need to be 3 times longer than the vertex array; actually that's not something that would happen. A mesh consisting of one triangle would have 3 entries in the vertex array and 3 entries in the triangle array.

avatar image saiato · Sep 04, 2013 at 12:09 AM 0
Share

Hmm that makes sense! Is it possible to store these pools of branch meshes as arrays for other game objects to access? Say, I have a tree game object with a couple branches as children, can it access them as an array?

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

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to inherit from two classes? 2 Answers

Tetris Unity game structure C# 3 Answers

I have objects that have the same set of variables, but different desired behaviors. How can I do this without repeating variable declarations across all behaviors? 1 Answer

Deleting square in Mesh really slow. Need help optimizing code. 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