Mesh简化为Cube mesh
- 🍳食用
- 🥙子物体独立生成CubeMesh
- 🥪合并成一个CubeMesh
- 🌭Demo
🍳食用
下载并导入插件👈即可在代码中调用。
🥙子物体独立生成CubeMesh
gameObject.ToCubeMesh_Invidual();
🥪合并成一个CubeMesh
gameObject.ToCubeMesh();
🌭Demo
using EasyRoads3Dv3;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace ZYF
{
public class ToCubeMeshDemo : MonoBehaviour
{
[SerializeField]
private Material cubeMat;
[SerializeField,Header("独立模式")]
private bool invidualModel = true;
private void Start()
{
GameObject res = new GameObject("cube mesh");
if (invidualModel ==false)
{
var result = gameObject.ToCubeMesh();
var go= DisplayMesh(mesh: result, gameObject);
go.transform.SetParent(res.transform);
}
else
{
var results = gameObject.ToCubeMesh_Invidual();
foreach (var c in results)
{
var rgo= DisplayMesh(c.cubeMesh, c.meshGo);
rgo.transform.SetParent(res.transform);
}
}
}
private GameObject DisplayMesh(Mesh mesh, GameObject go)
{
var cube = new GameObject(go.name);
var mf = cube.AddComponent<MeshFilter>();
var mr = cube.AddComponent<MeshRenderer>();
mf.mesh = mesh;
mr.material = cubeMat;
cube.transform.position = go.transform.position;
cube.transform.rotation = go.transform.rotation;
cube.transform.localScale = go.transform.lossyScale;
return cube;
}
}
}