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

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

相关推荐
暴走约伯2 天前
【VFX工具链源码拆解 09】终极工业化闭环:基于 ID 规则驱动的全自动场景建档、骨骼挂载与男转女场景迁移
unity·c#·游戏引擎·材质
寂寞的船3 天前
【Unity知识速递】第13期 Unity 内存泄漏排查实战:从 Memory Profiler 到 Lua 引用泄漏的生产级全链路诊断
unity·junit·c#·游戏引擎·lua
寂寞的船3 天前
【Unity Bug挑战】第12期 Awaitable 二次 await 死锁之谜 —— 为什么同一个异步操作等两次就卡死?
unity·c#·游戏引擎·bug
探求虚无5 天前
用 AI 在 Unity 里做一款 RTS:最难的不是生成代码,而是证明它真的能玩
人工智能·unity·游戏引擎
17岁的勇气6 天前
Unity Shader unity文档学习笔记(二十二):shader变体
笔记·学习·unity
寂寞的船7 天前
【Unity知识速递】第10期 Unity GC 零分配实战:从 UnityEngine.Pool 到手动 GC 控制的全链路优化
jvm·unity·c#·游戏引擎·lucene
Martina_03217 天前
AI生成3D场景的霓虹灯一开就糊成光团?用6步检查Emissive、Bloom与曝光
人工智能·3d·ai·自然语言处理·游戏引擎·材质·贴图
寂寞的船9 天前
【Unity知识速递】第8期 IL2CPP 托管堆内存碎片与原生堆交互机制深度解析
unity·游戏引擎·交互
寂寞的船9 天前
【Unity知识速递】第5期 Unity 6.2 深度解析:AI Assistant 登场,World Space UI 与 Sentis 全面升级
人工智能·ui·unity
寂寞的船9 天前
【Unity知识速递】第4期 MCP for Unity:用 AI 自然语言控制编辑器
人工智能·unity·编辑器