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 runningwild · Aug 12, 2012 at 06:05 PM · gameobjectmeshcolorlighttriangles

Getting triangles of a single gameobject (one prefab instance, not all)

Hi! Finally I've found a question that does not seem to be covered yet here! :)

Here it is: I want to do a custom lighting by changing colors of faces that point to my light source. This is going to be some sort of "prebaked" lighting but without the overhead of additional textures and without some limitations of lightmapping.

In order to do this I determine the gameobjects close to the lightsource. Out of those objects I want to get the faces that point toward the lightsource.

My problem is that I can get the mesh, vertices, normals, etc. but only for all instances of the prefab (as it is shared). There does not seem to be a way to get for example only the triangles of a given (single) game object. Whenever I call gameObject.GetComponent().mesh.vertices I get the entire list of vertices (probably of all existing instances of my static prefab).

What I am looking for would be some sort of: gameobject.GetMeYourTriangleIndicesButNotThoseOfYourSiblingInstances().

After hours of research I start running out of ideas. Any help on this would be highly welcome!!!

Comment
Add comment · Show 2
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 Loius · Aug 12, 2012 at 07:21 PM 0
Share

So if you have two cubes (eight vertices each), your .vertices call is getting 16 vertices back?

avatar image runningwild · Aug 13, 2012 at 07:36 AM 0
Share

right! when static flag is set. (see my comment to scroodge's answer)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ScroodgeM · Aug 12, 2012 at 10:22 PM

as i understood you correct, you need

http://docs.unity3d.com/Documentation/ScriptReference/Mesh-subMeshCount.html

http://docs.unity3d.com/Documentation/ScriptReference/Mesh.GetTriangles.html

note, that submeshes are separated only in triangles, vertices are shared for all submeshes. so vertex used in one submesh can be used in another.

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 runningwild · Aug 13, 2012 at 07:34 AM 0
Share

These submeshes are also shared unfortunately. I don't get them for a single instance.

The problem seems to be the 'static' flag. I wrote a simple script and attached it to one of my cubes:

$$anonymous$$esh mesh = gameObject.GetComponent().mesh; Vector3[] vertices = mesh.vertices; Debug.Log("v="+vertices.Length+", smc="+mesh.sub$$anonymous$$eshCount);

When I run it with static flag set on my cube, then I get this : v=6169 ('=vertice count'), smc=576 ('=submesh count')

Without static flag: v=24 ('vertice count'), smc=5 ('=submesh count')

=> without static flag I can access the triangles of a single object => with static flag this information is no longer available. I can only get triangles for... I don't know... the result of unitys internal merging process (problably all static objects)

As I am developing for mobile plattforms I really want to use the static flag in order to avoid thousands of draw calls on static objects.

avatar image ScroodgeM · Aug 13, 2012 at 07:07 PM 0
Share

i missed that you are talking about statics...

if you mark object as 'static' it means that you want not to move, rotate, change, scale, change material etc. this checkbox lets unity to combine all static objects to decrease drawcalls.

this is internal mechanism and AFAI$$anonymous$$ unity doesn't store information for reverting this action. so, in your static mode you are not able to get object back.

as a solution, you can make a custom mesh-combinator which will store information for recombine, or just stores (but not draws) original information and just recombines it on original changes.

it's a lot of examples with mesh-combiners in unity free access.

avatar image runningwild · Aug 14, 2012 at 07:29 AM 0
Share

i believe unity should behave differently on this one. an internal optimization should not alter the result of unity's interface methods. this can lead a developer on the wrong path.

furtunately, in my case I can live without statics. The performance seems to be good enough!

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

9 People are following this question.

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

Related Questions

Does anybody know why this happens to the mesh's color? 1 Answer

Change Color of model from Down to up! 1 Answer

Render voxels with RGB data passed to them 1 Answer

How to have different materials on one GameObject? 1 Answer

Raycast - Add tris (script inside) 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