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

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

相关推荐
丁小未19 小时前
基于MVVM框架的XUUI 扩展的UI管理系统教程
unity·mvvm·ui框架·xuui·ui管理器
丁小未1 天前
基于MVVM框架的XUUI HelloWorld 新手教程
unity·性能优化·c#·游戏引擎
丁小未2 天前
基于MVVM框架的XUUI MoreComplex案例
unity·c#
EQ-雪梨蛋花汤2 天前
【Unity笔记】VR 一体机画面锯齿、模型边缘闪烁、接缝抖动排查:MSAA、Mipmap、Render Scale、Z-Fighting 全流程记录
笔记·unity·vr
松树戈2 天前
【Godot4精进之路】03~Godot编辑器常用界面介绍
编辑器·游戏引擎·godot
YigAin2 天前
Unity Spine 资源出现白边的解决办法
unity·游戏引擎·spine
郝学胜-神的一滴3 天前
中级OpenGL教程 013:渲染器类架构设计与逐帧渲染流程详解
开发语言·c++·unity·游戏引擎·图形渲染·opengl·unreal
_helen_5203 天前
unreal engine 虚拟现实 + airsim
游戏引擎·vr·虚幻
真鬼1234 天前
【Unity WebGL】内嵌网页与双向通信
unity·游戏引擎·webgl
zyh______5 天前
C#语法糖(按照实用性排序)
unity·c#