From finite elements to Unity - Unity grid programming


Preface

Last time we talked about how to export abaqus grid data and analyze the exported content. This time we will talk about grid programming in Unity to prepare for the reproduction of finite element grids in Unity.


1. What is grid programming?

Grid programming is a means of visualizing 3D models in Unity. The key properties of the model grid (vertices, patches, normals, etc.) are defined through Unity's built-in classes, properties, methods, etc., so as to display the needs in Unity. Model effect (equivalent to customizing the grid to meet display, interaction, rendering, etc. needs).

2. Grid and related classes (components) in Unity

1. Grid

The model mesh is mainly composed of vertices and triangular faces. Therefore, to determine the shape of the model mesh, we must first determine which vertices the mesh consists of and what are the spatial positions of these vertices, that is, the mesh vertex positions . Vertex positions are described by coordinates in a Cartesian coordinate system.
In addition, it is also necessary to determine which triangular patches are in the model and which vertices each triangular patch is composed of in which order, that is, the patch construction sequence . In Unity, the left-hand rule is used to determine the front and back of the triangular patch based on the ordering of the three vertices of the triangular patch. As shown in the figure below, the triangular patch is composed of three vertices with vertex numbers 43, 56, and 29. If the vertex order (patch construction sequence) is defined as 43, 29, and 56, then the side facing outward from the screen is the front. Can be rendered with its back side culled.
Insert image description here

2.Mesh Filter and Mesh Renderer in Unity

2.1.Mesh Filter

Mesh Filter is used to define meshes or obtain meshes from resources, and the mesh attributes in Mesh Filter are used to define and save mesh-related attributes, including Vertices of the Vector3[] type used to save mesh vertex coordinates, Triangles of type int[] that holds the construction sequence of mesh triangle patches.

2.2.Mesh Renderer (Mesh Renderer)

Mesh Renderer is used for rendering mesh models. It can define textures, materials and other information, and then elaborate and use the cloud image distribution to reproduce the finite element analysis results in Unity.

3. Grid programming examples

Here we use a simple cube model with a side length of 1m to explain how to use the mesh attribute of the Mesh Renderer in Unity to define and visualize a cube mesh accordingly.
step1. Create an empty object, customize and mount a script named TestMesh
step2. Open the TestMesh script and dynamically add a Mesh Filter component

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class TestMesh : MonoBehavior
{
   
    
    
	private MeshFilter mf;
	private void Start()
	{
   
    
    
		mf = this.AddComponent<MeshFilter>();//动态添加Mesh Filter组件
	}
}

step3. Define the mesh vertex position

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class TestMesh : MonoBehaviour
{
   
    
    
    private MeshFilter mf;
    private void Start()
    {
   
    
    
        //动态添加Mesh Filter组件
        mf = this.AddComponent

Guess you like

Origin blog.csdn.net/flatrrow/article/details/132655620