Unity曲线插件Dreamteck Splines生成曲线Mesh

一、需求

脱离编辑器,运行时添加点,动态生成管道、线缆等曲线Mesh。

二、Dreamteck Splines简单运用

这方面资料不多,只有官方文档全英参考,而且又介绍得不详细。

2个重要组件介绍:

SplineComputer:

最重要的样条曲线数据组件,Edit中提供了鼠标直接在编辑器场景中添加、删除、移动、旋转、缩放、法向、镜像、基准形状的功能,供在场景中编辑使用。

下方close是首尾闭合本曲线。

reverse是顺序反转,也就是第一个点变最后一个点。

右边加号和剪刀分别是Merge和Split,也就是将两个曲线物体混合成一个,或者将一个曲线物体分割成两个。

TubeGenerator:

Common中的Size是管道粗细,Faces中的Double------sided可以创建双面Mesh,Shape中的Sides是管道的原型截面多少条边,根据自己性能设置。

三、上代码,动态添加点,生成曲线mesh

cs 复制代码
using System;
using System.Collections;
using System.Collections.Generic;
using Dreamteck.Splines;
using UniRx;
using UnityEngine;

public class DynamicSpline : MonoBehaviour
{
    private SplineComputer _splineComputer;
    private TubeGenerator _tubeGenerator;
    private Material _material;
    
    void Start()
    {
        Vector3[] v3 = new Vector3[3] { new Vector3(1.509808f, -2.273857f, 22.09592f), new Vector3(1.509808f, 3.6f, 34.1f),new Vector3(1.509808f,-2.273857f,54.5f) };
        for (int i = 0; i < v3.Length; i++)
        {
            v3[i].x += transform.position.x;
            v3[i].z += transform.position.z;
            v3[i].y += transform.position.y;
        }
        _material = Resources.Load<Material>("Material/TubeMaterial");
        
        
        _splineComputer = gameObject.AddComponent<SplineComputer>();
        for (int i = 0; i < 3; i++)
        {
            SplinePoint point = new SplinePoint(v3[i]);
            _splineComputer.SetPoint(i, point);
        }
        _tubeGenerator = gameObject.AddComponent<TubeGenerator>();
        _tubeGenerator.spline = _splineComputer;
        
        //how to set the material?
    }
}

但是需要自己弥补一下材质问题,手动设置可以,但是插件应该可以有方法能够设置,暂时没发现。

相关推荐
冰凌糕20 小时前
Unity3D Shader 法线与基础光照
unity
新手unity自用笔记1 天前
unity网络基础_1
网络·unity·游戏引擎
谢斯1 天前
[vscode] 使用unity打开vscode的取消.csproj的显示
ide·vscode·unity
魔术师Dix1 天前
StartGame:Unity TDD 外部工程指南
学习·游戏·unity·c#·测试驱动开发
hsw8157739432 天前
第10章 软件架构的演化和维护 — 系统架构设计师
unity·系统架构·游戏引擎
tealcwu2 天前
【尝鲜】Unity 6.7alpha版本测试
unity·游戏引擎
懒狗跑ai的程序员Brain3 天前
如何利用粒子系统在unity制作一个烟花(粒子系统学习向)
学习·unity·游戏引擎