U3D Outsourcing team-technology sharing u3d to get the size of the object

Source: Internet
Author: User

Take the x direction of size as an example

1:gameobject.renderer.bounds.size.x;//The result of this value really reflects the size of the model that has meshrenderer this component. No need to multiply localscale.x.

2:gameobject.getcomponent<meshfilter> (). mesh.bounds.size.x;//gets the mesh of the original model through Meshfilter, which returns the size of the original mesh.

To get the size of the model you also need to multiply the model's localscale.x.

That is:gameobject.getcomponent<meshfilter> (). mesh.bounds.size.x*gameobject.transform.localscale.x;

3: Add collider to the object, then use XXX.collider.bounds.size;

This does not necessarily respond well to the size of the object, and the bounds obtains the outer rectangle of the object. And this outsourced rectangle has the same x, Y, z and world coordinates. Therefore, if the object has a rotation, the size obtained cannot reflect the true size of the object, just the size of its outsourced rectangle ...

such as: Get the size of the terrain

Terrainwidth = terrain.collider.bounds.size.x;

Terrainlength = terrain.collider.bounds.size.z;

Terrainheight = Terrain.collider.bounds.size.y;

4: Code to achieve the size of complex objects (such as the root node does not have Meshfilter,meshrenderer components, objects are composed of many complex irregular small mesh sub-objects) such as: Camera aperture size

When the projection type is perspective, the Fieldofview property represents the degree of the aperture, in the range [1,179]

When the projection type is orthgraphic, the Orthographicsize property is the aperture size in orthogonal mode

U3D Outsourcing team-technology sharing u3d to get the size of the object

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.