• 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 Griffo · Nov 30, 2016 at 07:05 AM · boundsvolumevolumetric

Divide volume depending on chosen amount.

Hi, I'm a bit stuck and could do with some help please, I've put together a script to find the bounds of a prefab that helps me place light probes but what I'd like to do is if I ask for 2, 3 or 4 light probe volumes I'd like to divide the bounds up like in the pictures below, any ideas on how to efficiently do this, thanks.

 function findBounds ()
 {
     ClearBounds();
     probePositions.Clear();
 
     var allChildren = transform.root.gameObject.GetComponentsInChildren(Transform);
 
     for ( var child : Transform in allChildren)
     {
         if(child.gameObject.GetComponent.<Renderer>() != null)
             meshRenererArray.Add(child.gameObject.GetComponent.<Renderer>());
     }
      for (var i: int = 0; i < meshRenererArray.Count; i++)
      {
          boundsArray.Add(meshRenererArray[i].bounds);
          _center += meshRenererArray[i].bounds.center;
      }
  //center is average center of children
      _center /= transform.root.childCount;
      totalBound = new Bounds(_center, Vector3.zero); 
 
      for (var ii: int = 0; ii < boundsArray.Count; ii++)
      {
          b = new Bounds(boundsArray[ii].center, boundsArray[ii].size);
          totalBound.Encapsulate(boundsArray[ii]);  
     }
     transform.position = totalBound.center;
 
     for ( var area: LightProbeArea in LightProbeVolumes)
     {
         area.ProbeVolume.extents = totalBound.size;
         area.ProbeVolume.center = totalBound.center;
     }
 }

alt text

cubes-00.jpg (24.7 kB)
Comment
Add comment · Show 1
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 Griffo · Nov 30, 2016 at 02:54 PM 0
Share

O$$anonymous$$ think I was just being idle, added this ..

     var outerBounds : float = (totalBound.center.x - (totalBound.size.x/2));
     var _newCenters : float = (totalBound.extents.x / LightProbeVolumes.Length);
     var newPosX : float = (outerBounds + _newCenters);
 
     totalBound.size.x /= LightProbeVolumes.Length;
 
     var newCenter : float = (totalBound.center.x - (totalBound.size.x/2));
 
     for ( var area: LightProbeArea in LightProbeVolumes)
     {
         area.ProbeVolume.extents = totalBound.size;
 
         area.ProbeVolume.center.x = (outerBounds + _newCenters);
         area.ProbeVolume.center.y = totalBound.center.y;
         area.ProbeVolume.center.z = totalBound.center.z;
         _newCenters += area.ProbeVolume.extents.x;
     }

And it divides it up into strips, might change it again so it does squares to.

alt text

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

55 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 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 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 avatar image

Related Questions

tex3d lookup yields black mesh - why?? 1 Answer

Is there a functionality for finding how much two objects intersect each other 2 Answers

Get closest point on 2D perimeter using Bounds 2 Answers

AudioSource.ignoreListenerVolume warning 1 Answer

scale animation result? 1 Answer


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