模型拆解 3d标注

using System.Collections;

using System.Collections.Generic;

using Unity.VisualScripting;

using UnityEngine;

using UnityEngine.UI;

using Lovatto.OrbitCamera;

using DG;

using DG.Tweening;

using System.IO;

using UnityEngine.Experimental.GlobalIllumination;

public class main : MonoBehaviour

{

// Start is called before the first frame update

public Text txt1;

public Text txt2;

bool SplitModelBoo = false;

public Animation _Animation;

public AnimationClip[] clips;

public bl_CameraOrbit _bl_CameraOrbit;

bool AutoRoa = true;

public GameObject Leftui;

bool OpenLeftUiBoo = true;

SerializeField

Camera UI_Camera;//UI相机

SerializeField

Canvas ui_Canvas;

System.Serializable

public struct PointInfo

{

public GameObject Point3d;

public string Title;

public string Info;

}

public PointInfo[] _PointInfo = new PointInfo[3];

public RectTransform Circle;

public GameObject Tripmc;

public Text Titletxt;

public Text Infotxt;

public int ShowinfoI;

bool Showinfoboo = false;

public RectTransform Line;

public GameObject[] Uiall;

int UiallIndex = 0;

public GameObject RightModel;

void Start()

{

ShowRightModel(false);

HideInfo();

HideUiall();

}

// Update is called once per frame

void Update()

{

if (Showinfoboo) {

Vector2 mouseDown = Camera.main.WorldToScreenPoint(_PointInfo[ShowinfoI].Point3d.transform.position);

Vector2 mouseUGUIPos = new Vector2();

bool isRect = RectTransformUtility.ScreenPointToLocalPointInRectangle(ui_Canvas.transform as RectTransform, mouseDown, UI_Camera, out mouseUGUIPos);

if (isRect)

{

Circle.anchoredPosition = mouseUGUIPos;

}

//Line.anchoredPosition = mouseUGUIPos;

CreateLine(Line.gameObject, mouseUGUIPos, Tripmc.GetComponent<RectTransform>().anchoredPosition3D);

}

}

public void SplitModel(bool boo)

{if (SplitModelBoo == boo) return;

SplitModelBoo=boo;

if (boo)

{

_Animation.clip = clips[0];

AnimationState state = _Animation["Take 001"];

state.speed = 1;

_Animation.Play();

txt1.text = "组合模型";

}

else

{

_Animation.clip = clips[0];

AnimationState state = _Animation["Take 001"];

state.speed = -1;

_Animation.Play();

txt1.text = "拆分模型";

HideInfo();

}

}

public void SplitModelLoop()

{

SplitModel(!SplitModelBoo);

}

public void SetAutoRoa()

{

if (AutoRoa)

{

_bl_CameraOrbit.AutoRotate = true;

txt2.text = "手动旋转";

}

else

{

_bl_CameraOrbit.AutoRotate = false;

txt2.text = "自动旋转";

}

AutoRoa = !AutoRoa;

}

//public void OpenLeftUiLoop()

//{

// OpenLeftUi(!OpenLeftUiBoo);

//}

public void ShowRightModel(bool boo) {

RightModel.gameObject.SetActive(boo);

if (boo)

{

_bl_CameraOrbit.gameObject.GetComponent<Camera>().orthographic = true;

}

else {

_bl_CameraOrbit.gameObject.GetComponent<Camera>().orthographic = false;

}

}

public void HideUiall()

{

for (int i = 0; i<Uiall.Length; i++) {

Uiall[i].gameObject.SetActive(false);

}

ShowRightModel(false);

}

public void OpenUiall(int j)

{

if (j == 0)

{

ShowRightModel(false);

}

else {

ShowRightModel(true);

}

UiallIndex = j;

for (int i = 0; i < Uiall.Length; i++) {

Uiall[i].gameObject.SetActive(i==j?true:false);

}

SplitModel(false);

}

public void Showinfo(int i) {

Showinfoboo = true;

Circle.gameObject.SetActive(true);

Tripmc.gameObject.SetActive(true);

Line.gameObject.SetActive(true);

Titletxt.text = _PointInfo[i].Title;

Infotxt.text = _PointInfo[i].Info;

ShowinfoI = i;

HideUiall();

}

public void HideInfo() {

Showinfoboo = false;

Circle.gameObject.SetActive(false);

Tripmc.gameObject.SetActive(false);

Line.gameObject.SetActive(false);

}

void CreateLine(GameObject line, Vector2 startPosition, Vector2 endPosition)

{

var heading = endPosition - startPosition;

var distance = heading.magnitude;

var direction = heading / distance;

RectTransform rtLine = line.GetComponent<RectTransform>();

对齐左下角

//rtLine.anchorMin = Vector2.zero;

//rtLine.anchorMax = Vector2.zero;

//计算线条位置

// Vector2 centerPos = new Vector2(startPosition.x + endPosition.x, startPosition.y + endPosition.y) / 2;

rtLine.anchoredPosition = startPosition;

//计算线条角度

float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;

line.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

rtLine.sizeDelta = new Vector2(distance, 5.0f);

}

}

https://download.csdn.net/download/design888/89892924

相关推荐
书到用时方恨少!18 分钟前
基于 Three.js 的 3D 地球可视化项目
开发语言·javascript·3d
出门吃三碗饭12 小时前
3DGS场景优化 8*A100GPU实战
3d
做cv的小昊14 小时前
结合代码读3DGS论文(10)——ICLR 2025 3DGS加速&压缩新工作Sort-Free 3DGS论文及代码解读
论文阅读·人工智能·游戏·计算机视觉·3d·图形渲染·3dgs
图扑软件17 小时前
图扑 HT 帧动画 | 3D 动态渲染设计与实现
前端·javascript·3d·动画·数字孪生
新启航光学频率梳18 小时前
精密陶瓷轴承套孔深光学3D轮廓测量-激光频率梳3D轮廓技术
科技·3d·制造
weixin_505154461 天前
博维数孪,重塑3D作业指导新时代
人工智能·物联网·3d·智慧城市·数据安全·数字孪生
3DVisionary1 天前
从微观损伤到宏观断裂:DIC非接触测量在复合材料可靠性验证中的前沿实践
人工智能·数码相机·算法·机器学习·3d·复合材料·dic技术
Godspeed Zhao2 天前
3D打印的造物革命5
3d
CG_MAGIC2 天前
SketchUp室内布局:户型建模与家具组件高效摆放
3d·贴图·建模教程·渲云渲染
love530love2 天前
ComfyUI-3D-Pack:Windows 下手动编译 mesh_inpaint_processor C++ 加速模块
c++·人工智能·windows·python·3d·hunyuan3d·comfyui-3d-pack