Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Dionysos1111 · Jan 31, 2017 at 04:56 PM · meshrenderervolumestatic batching

mesh volume static batching

I use a script to calculate the volume of a mesh renderer which works fine but i when set static batching on in the editor the volume returns zero.

I already tried "isstatic" in the start function and then the volume is calculated correctly but that won't enable the actual static batching, it doesn't batch anything that way.

this is the code i use to calculate the volume:

         public float SignedVolumeOfTriangle(Vector3 p1, Vector3 p2, Vector3 p3)
         {
             float v321 = p3.x * p2.y * p1.z;
             float v231 = p2.x * p3.y * p1.z;
             float v312 = p3.x * p1.y * p2.z;
             float v132 = p1.x * p3.y * p2.z;
             float v213 = p2.x * p1.y * p3.z;
             float v123 = p1.x * p2.y * p3.z;
             return (1.0f / 6.0f) * (-v321 + v231 + v312 - v132 - v213 + v123);
         }
         public float VolumeOfMesh(Mesh mesh)
         {
             float volume = 0;
             Vector3[] vertices = mesh.vertices;
             int[] triangles = mesh.triangles;
             for (int i = 0; i < mesh.triangles.Length; i += 3)
      {
                 Vector3 p1 = vertices[triangles[i + 0]];
                 Vector3 p2 = vertices[triangles[i + 1]];
                 Vector3 p3 = vertices[triangles[i + 2]];
                 volume += SignedVolumeOfTriangle(p1, p2, p3);
             }
             volume *= this.gameObject.transform.localScale.x * this.gameObject.transform.localScale.y * this.gameObject.transform.localScale.z;
             gameObject.isStatic = true;
             return Mathf.Abs(volume);


Is there a way i can calculate the volume of the mesh AND use static batching this way? And why does it return zero if i set the object to static?

Comment
Add comment · Show 9
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 elenzil · Jan 31, 2017 at 06:24 PM 0
Share

i don't know the answer to your questions, but one $$anonymous$$or comment - i think you're calculating the surface area of the mesh/triangles here, not the volume.

avatar image Dionysos1111 elenzil · Jan 31, 2017 at 06:32 PM 0
Share

It's definitely the volume because when i place a cube and calculate the x*y*z i get the exact same outcome.

i think at least lol.

avatar image elenzil Dionysos1111 · Jan 31, 2017 at 06:38 PM 0
Share

hm. i'd be surprised. the volume of a triangle is zero. perhaps this is the volume of the tetrahedron joining the origin (0, 0, 0) to the triangle ?

Show more comments
avatar image Glurth · Jan 31, 2017 at 06:47 PM 0
Share

Not familiar with batching, but this seems odd: How are you getting the $$anonymous$$esh? (Thinking maybe the batching stuff sets it to an empty mesh, so it wont be drawn by the renderer, just by the batch. If so, perhaps caching it during Start(), before the batching stuff get's its mitts on it, will help?)

Not sure how often you call this, but worth noting: If the mesh verticies are not changing, just the transform, you can compute a scaleOne, or "Unit" volume, one time, during startup, and only multiply by the transform's scale each cycle. $$anonymous$$ight also help work around the batching issue.

(by the way, how does a triangle have volume with no thickness? I just can't wrap my head around what that volume of triangle function is doing!)

avatar image Dionysos1111 Glurth · Jan 31, 2017 at 07:00 PM 0
Share

i call this function quite alot, most of the times on the start function to calculate literally every mesh volume in the scene.

the verticies are not changing and the transform is also not changing during the calculation(start function).

How can i compute a scaleOne or Unit volume then? i am not familiar with it.

i don't know how the formula actually works, i just know that it works because i calculated a square x*y*z and that return the exact same volume of the other script

avatar image Glurth Dionysos1111 · Jan 31, 2017 at 07:41 PM 0
Share

You DO compute the Unit volume. Then you multiply it by the scale. It's just the volume before you scale it. But if this is being done in start only, I think you can safely ignore my comments.

Still don't know where you get the mesh passed into this function. I'd bet that's where the issue lies.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

6 People are following this question.

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

Related Questions

Mask a MeshRenderer 0 Answers

Why are static objects that are batched simply not showing up on some Android devices? 1 Answer

Baking Static Batches at Editor Time 0 Answers

Static batching and windzones - does wind count as moving the object? 0 Answers

Sound volume based on rigidbody velocity before collision. 3 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