模型拆解 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

相关推荐
多恩Stone4 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
多恩Stone5 天前
【3D-AICG 系列-15】Trellis 2 的 O-voxel Shape: Flexible Dual Grid 代码与论文对应
人工智能·python·算法·3d·aigc
在下胡三汉5 天前
为什么“资产土地”标准化主资产的 glTF、glb格式模型,为什么非常流行
3d
2401_863801465 天前
3DTiles(.b3dm,i3dm,cmpt) 数据转换fbx转obj转max转su,cesium格式模型转换
3d
3Dmax效果图渲染研习社5 天前
2026年3ds Max云渲染平台哪个好?
3d
思茂信息5 天前
基于CST 3D Combined功能的以太网口RE仿真
开发语言·javascript·单片机·嵌入式硬件·matlab·3d
CG_MAGIC5 天前
Maya 角色绑定:控制器搭建与 IK/FK 切换
3d·贴图·maya·渲云渲染
PHOSKEY5 天前
光子精密3D工业相机陶瓷基片平面度检测!赋能电子制造质控升级
平面·3d·3d工业相机
twe77582585 天前
用3D动画揭示技术路线的多样性
科技·3d·制造·动画