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?
    }
}

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

相关推荐
今夕资源网8 小时前
牛童三国单机游戏Unity源码 免费开源
游戏·unity·单机游戏·游戏源码·unity源码·unity游戏
future_studio13 小时前
聊聊 Unity(小白专享、C# 小程序 之 图片播放器)
unity·小程序·c#
ellis19701 天前
toLua[七] Examples 06_LuaCoroutine2分析
unity
L X..1 天前
Unity 光照贴图异常修复笔记
unity·c#·游戏引擎
Xeon_CC1 天前
打开多个Unity编辑器时使用Visual Studio调试,弹出选择Unity实例窗口,但是没有实例
unity·编辑器·visual studio·调试·unity 调试
小L~~~2 天前
2025吉比特-游戏引擎开发-一面复盘
数据结构·算法·游戏引擎
云卓SKYDROID2 天前
无人机中继器模式技术对比
人工智能·游戏引擎·php·无人机·cocos2d·高科技·云卓科技
future_studio3 天前
聊聊 Unity(小白专享、熟悉基础编程 ... ...)
unity·游戏引擎
ellis19703 天前
toLua[六] Examples 05_LuaCoroutine分析
unity
程序员正茂3 天前
Unity3d中Tab控件的实现
ui·unity·tab·控件