Unity实现在3D模型上涂鸦
来源:互联网 发布:abb仿真软件track 编辑:程序博客网 时间:2024/06/10 11:59
http://docs.unity3d.com/ScriptReference/GL.html
using System.Collections.Generic;using UnityEngine;using UnityEngine.EventSystems;public class DrawOnModel : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler{ public Color color = Color.red; public float thickness = 0.02f; private List<Vector3> points = new List<Vector3>(); private List<Vector3> normals = new List<Vector3>(); private List<int> splits = new List<int>();//分割索引 static Material lineMaterial; static void CreateLineMaterial() { if (!lineMaterial) { // Unity has a built-in shader that is useful for drawing // simple colored things. var shader = Shader.Find("Hidden/Internal-Colored"); lineMaterial = new Material(shader); lineMaterial.hideFlags = HideFlags.HideAndDontSave; // Turn on alpha blending lineMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); lineMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); // Turn backface culling off lineMaterial.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off); // Turn off depth writes lineMaterial.SetInt("_ZWrite", 0); } } public void OnRenderObject() { CreateLineMaterial(); lineMaterial.SetPass(0); GL.PushMatrix(); GL.MultMatrix(transform.localToWorldMatrix); GL.Begin(GL.LINES); int index = 0; for(int i=1; i<points.Count; i++) { if (index < splits.Count && i == splits[index]) { index++; continue; } GL.Color(color); var from = points[i-1] + normals[i-1] * thickness; GL.Vertex3(from.x, from.y, from.z); var worldNormal = transform.TransformDirection(normals[i]); var to = points[i] + worldNormal * thickness; GL.Vertex3(to.x, to.y, to.z); } GL.End(); GL.PopMatrix(); } public void OnBeginDrag(PointerEventData eventData) { } public void OnDrag(PointerEventData eventData) { if (!eventData.pointerCurrentRaycast.isValid) { SplitPoints(); return; } var localPosition = transform.InverseTransformPoint(eventData.pointerCurrentRaycast.worldPosition); points.Add(localPosition); var localNormal = transform.InverseTransformDirection(eventData.pointerCurrentRaycast.worldNormal); normals.Add(localNormal); } public void OnEndDrag(PointerEventData eventData) { SplitPoints(); } void SplitPoints() { if (splits.Count == 0 && points.Count != 0 || splits[splits.Count - 1] != points.Count) splits.Add(points.Count); }}
2 0
- Unity实现在3D模型上涂鸦
- Unity实现在白板上绘画涂鸦
- Unity之在UI界面上显示3D模型
- Unity中在界面上显示3D模型的方法
- unity学习日记:怎样在UI界面上渲染3D模型
- android 实现在照片上涂鸦
- unity在模型上绘画
- Unity 判断是否点击在3D物体上
- unity实现3D物体上的事件监听处理
- [unity-17] Unity如何在UI层显示3D模型
- 在canvas上实现3D效果
- 【Unity3D】【NGUI】如何在UI上显示3D模型
- Unity3D NGUI如何在UI上显示3D模型
- Unity3D NGUI如何在UI上显示3D模型
- unity在模型上绘制贴图
- unity 3d 在限定区域内 实现文字拖动翻页
- unity3d鼠标滑动UIImage从而实现3D模型在UIImage上的左右旋转(RawImage映射)
- 3d max 模型贴图导入unity
- js中几种实用的跨域方法原理详解
- zookeeper命令行(zkCli.sh&zkServer.sh)使用及四字命令
- 视图
- 爱的贝塞尔曲线讲解
- shell
- Unity实现在3D模型上涂鸦
- 快捷安装Redis数据库和Redis Desktop Manage可视化界面工具
- SqlYog注册码
- NLP笔记(一)
- 墓碑上的字符
- kubernetes1.5新特性:新版本kubeadm
- MySQL/ 索引
- vue.js配合$.post从后台获取数据简单demo
- arcgis for javascript 隐藏或显示底图