Skip to main content
added 1 character in body
Source Link
Philipp
  • 123.2k
  • 28
  • 264
  • 345

As a Unity programmer, you usually do not work with polygons directly.

The usual way to create and animate 3d objects in Unity is not to do that with code. You usually do that by creating them in a 3d modeling program like Maya or Blender. These programs also allow you to define animations for the model. When you import the model into Unity, you can also import its animations. You ancan then trigger these animations through the Unity Animation System. This approach is both more design-friendly (3d modeling programs offer you WYSIWYG editing instead of just typing numbers and hoping they look good) and more performance-friendly (the deformation logic can be processed on the GPU).

But if you really want to create and manipulate 3d geometry in code (there are some edge-cases where this is indeed useful, like procedural generation for example), check out the class Mesh. It represents the geometry used by a MeshFilter component.

You can either create an entirely new mesh:

    Mesh mesh = new Mesh();
    GetComponent<MeshFilter>().mesh = mesh;

Or you can obtain the reference to an existing mesh

    Mesh mesh =  GetComponent<MeshFilter>().mesh;

You can then manipulate that mesh:

    mesh.vertices = /* Vector3[] of polygon corners */;
    mesh.uv = /* Vector2[] of the UV texture coordinates for the polygon corners */;
    mesh.triangles = /* int[] of indexes in the vertices array. Every 3 entries define one polygon */

When you are finished manipulating the mesh, you might need to update a couple precomputed values. Depending on what you changed and what kind of material you use, not all three of these might be necessary:

    mesh.RecalculateBounds(); /* important for culling calculation */
    mesh.RecalculateNormals(); /* required by some shaders */
    mesh.RecalculateTangents(); /* required by some shaders */

As a Unity programmer, you usually do not work with polygons directly.

The usual way to create and animate 3d objects in Unity is not to do that with code. You usually do that by creating them in a 3d modeling program like Maya or Blender. These programs also allow you to define animations for the model. When you import the model into Unity, you can also import its animations. You an then trigger these animations through the Unity Animation System. This approach is both more design-friendly (3d modeling programs offer you WYSIWYG editing instead of just typing numbers and hoping they look good) and more performance-friendly (the deformation logic can be processed on the GPU).

But if you really want to create and manipulate 3d geometry in code (there are some edge-cases where this is indeed useful, like procedural generation for example), check out the class Mesh. It represents the geometry used by a MeshFilter component.

You can either create an entirely new mesh:

    Mesh mesh = new Mesh();
    GetComponent<MeshFilter>().mesh = mesh;

Or you can obtain the reference to an existing mesh

    Mesh mesh =  GetComponent<MeshFilter>().mesh;

You can then manipulate that mesh:

    mesh.vertices = /* Vector3[] of polygon corners */;
    mesh.uv = /* Vector2[] of the UV texture coordinates for the polygon corners */;
    mesh.triangles = /* int[] of indexes in the vertices array. Every 3 entries define one polygon */

When you are finished manipulating the mesh, you might need to update a couple precomputed values. Depending on what you changed and what kind of material you use, not all three of these might be necessary:

    mesh.RecalculateBounds(); /* important for culling calculation */
    mesh.RecalculateNormals(); /* required by some shaders */
    mesh.RecalculateTangents(); /* required by some shaders */

As a Unity programmer, you usually do not work with polygons directly.

The usual way to create and animate 3d objects in Unity is not to do that with code. You usually do that by creating them in a 3d modeling program like Maya or Blender. These programs also allow you to define animations for the model. When you import the model into Unity, you can also import its animations. You can then trigger these animations through the Unity Animation System. This approach is both more design-friendly (3d modeling programs offer you WYSIWYG editing instead of just typing numbers and hoping they look good) and more performance-friendly (the deformation logic can be processed on the GPU).

But if you really want to create and manipulate 3d geometry in code (there are some edge-cases where this is indeed useful, like procedural generation for example), check out the class Mesh. It represents the geometry used by a MeshFilter component.

You can either create an entirely new mesh:

    Mesh mesh = new Mesh();
    GetComponent<MeshFilter>().mesh = mesh;

Or you can obtain the reference to an existing mesh

    Mesh mesh =  GetComponent<MeshFilter>().mesh;

You can then manipulate that mesh:

    mesh.vertices = /* Vector3[] of polygon corners */;
    mesh.uv = /* Vector2[] of the UV texture coordinates for the polygon corners */;
    mesh.triangles = /* int[] of indexes in the vertices array. Every 3 entries define one polygon */

When you are finished manipulating the mesh, you might need to update a couple precomputed values. Depending on what you changed and what kind of material you use, not all three of these might be necessary:

    mesh.RecalculateBounds(); /* important for culling calculation */
    mesh.RecalculateNormals(); /* required by some shaders */
    mesh.RecalculateTangents(); /* required by some shaders */
added 92 characters in body
Source Link
Philipp
  • 123.2k
  • 28
  • 264
  • 345

As a Unity programmer, you usually do not work with polygons directly.

The usual way to create and animate 3d objects in Unity is not to do that with code. You usually do that by creating them in a 3d modeling program like Maya or Blender. These programs also allow you to define animations for the model. When you import the model into Unity, which you can also import its animations. You an then trigger these animations through the Unity Animation System. As a programmer you usually do not work with polygons directly. This approach is both more design-friendly (3d modeling programs offer you WYSIWYG editing instead of just typing numbers and hoping they look good) and more performance-friendly (the deformation logic can be processed on the GPU).

But if you really want to create and manipulate 3d geometry in code (there are some edge-cases where this is indeed useful, like procedural generation for example), check out the class Mesh. It represents the geometry used by a MeshFilter component.

You can either create an entirely new mesh:

    Mesh mesh = new Mesh();
    GetComponent<MeshFilter>().mesh = mesh;

Or you can obtain the reference to an existing mesh

    Mesh mesh =  GetComponent<MeshFilter>().mesh;

You can then manipulate that mesh:

    mesh.vertices = /* Vector3[] of polygon corners */;
    mesh.uv = /* Vector2[] of the UV texture coordinates for the polygon corners */;
    mesh.triangles = /* int[] of indexes in the vertices array. Every 3 entries define one polygon */

When you are finished manipulating the mesh, you might need to update a couple precomputed values. Depending on what you changed and what kind of material you use, not all three of these might be necessary:

    mesh.RecalculateBounds(); /* important for culling calculation */
    mesh.RecalculateNormals(); /* required by some shaders */
    mesh.RecalculateTangents(); /* required by some shaders */

The usual way to create and animate 3d objects in Unity is not to do that with code. You do that by creating them in a 3d modeling program like Maya or Blender. These programs also allow you to define animations for the model, which you can then trigger through the Unity Animation System. As a programmer you usually do not work with polygons directly. This approach is both more design-friendly (3d modeling programs offer you WYSIWYG editing instead of just typing numbers and hoping they look good) and more performance-friendly (the deformation logic can be processed on the GPU).

But if you really want to create and manipulate 3d geometry in code (there are some edge-cases where this is indeed useful), check out the class Mesh. It represents the geometry used by a MeshFilter component.

You can either create an entirely new mesh:

    Mesh mesh = new Mesh();
    GetComponent<MeshFilter>().mesh = mesh;

Or you can obtain the reference to an existing mesh

    Mesh mesh =  GetComponent<MeshFilter>().mesh;

You can then manipulate that mesh:

    mesh.vertices = /* Vector3[] of polygon corners */;
    mesh.uv = /* Vector2[] of the UV texture coordinates for the polygon corners */;
    mesh.triangles = /* int[] of indexes in the vertices array. Every 3 entries define one polygon */

When you are finished manipulating the mesh, you might need to update a couple precomputed values. Depending on what you changed and what kind of material you use, not all three of these might be necessary:

    mesh.RecalculateBounds(); /* important for culling calculation */
    mesh.RecalculateNormals(); /* required by some shaders */
    mesh.RecalculateTangents(); /* required by some shaders */

As a Unity programmer, you usually do not work with polygons directly.

The usual way to create and animate 3d objects in Unity is not to do that with code. You usually do that by creating them in a 3d modeling program like Maya or Blender. These programs also allow you to define animations for the model. When you import the model into Unity, you can also import its animations. You an then trigger these animations through the Unity Animation System. This approach is both more design-friendly (3d modeling programs offer you WYSIWYG editing instead of just typing numbers and hoping they look good) and more performance-friendly (the deformation logic can be processed on the GPU).

But if you really want to create and manipulate 3d geometry in code (there are some edge-cases where this is indeed useful, like procedural generation for example), check out the class Mesh. It represents the geometry used by a MeshFilter component.

You can either create an entirely new mesh:

    Mesh mesh = new Mesh();
    GetComponent<MeshFilter>().mesh = mesh;

Or you can obtain the reference to an existing mesh

    Mesh mesh =  GetComponent<MeshFilter>().mesh;

You can then manipulate that mesh:

    mesh.vertices = /* Vector3[] of polygon corners */;
    mesh.uv = /* Vector2[] of the UV texture coordinates for the polygon corners */;
    mesh.triangles = /* int[] of indexes in the vertices array. Every 3 entries define one polygon */

When you are finished manipulating the mesh, you might need to update a couple precomputed values. Depending on what you changed and what kind of material you use, not all three of these might be necessary:

    mesh.RecalculateBounds(); /* important for culling calculation */
    mesh.RecalculateNormals(); /* required by some shaders */
    mesh.RecalculateTangents(); /* required by some shaders */
Source Link
Philipp
  • 123.2k
  • 28
  • 264
  • 345

The usual way to create and animate 3d objects in Unity is not to do that with code. You do that by creating them in a 3d modeling program like Maya or Blender. These programs also allow you to define animations for the model, which you can then trigger through the Unity Animation System. As a programmer you usually do not work with polygons directly. This approach is both more design-friendly (3d modeling programs offer you WYSIWYG editing instead of just typing numbers and hoping they look good) and more performance-friendly (the deformation logic can be processed on the GPU).

But if you really want to create and manipulate 3d geometry in code (there are some edge-cases where this is indeed useful), check out the class Mesh. It represents the geometry used by a MeshFilter component.

You can either create an entirely new mesh:

    Mesh mesh = new Mesh();
    GetComponent<MeshFilter>().mesh = mesh;

Or you can obtain the reference to an existing mesh

    Mesh mesh =  GetComponent<MeshFilter>().mesh;

You can then manipulate that mesh:

    mesh.vertices = /* Vector3[] of polygon corners */;
    mesh.uv = /* Vector2[] of the UV texture coordinates for the polygon corners */;
    mesh.triangles = /* int[] of indexes in the vertices array. Every 3 entries define one polygon */

When you are finished manipulating the mesh, you might need to update a couple precomputed values. Depending on what you changed and what kind of material you use, not all three of these might be necessary:

    mesh.RecalculateBounds(); /* important for culling calculation */
    mesh.RecalculateNormals(); /* required by some shaders */
    mesh.RecalculateTangents(); /* required by some shaders */