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

相关推荐
梦想的理由1 小时前
3D人体建模的前沿探索(二):深入解析SMPL-IK与多视角人体网格重建
3d
道可云5 小时前
道可云人工智能&元宇宙每日资讯|2024国际虚拟现实创新大会将在青岛举办
大数据·人工智能·3d·机器人·ar·vr
Sitarrrr8 小时前
【Unity】ScriptableObject的应用和3D物体跟随鼠标移动:鼠标放置物体在场景中
3d·unity
starsongda1 天前
VR科技展厅重塑科技展示新风貌,引领未来展示潮流
科技·3d·vr
兔老大的胡萝卜1 天前
threejs 数字孪生,制作3d炫酷网页
前端·3d
CV-X.WANG1 天前
【详细 工程向】基于Smart3D的五镜头相机三维重建
数码相机·3d
JoeyKo1 天前
国内版Sketchfab平台 - CG美术之家(3D编辑发布篇)
3d·3d建模·3dsmax·3d渲染·模型·3d模型·cg模型
mirrornan1 天前
3D互动+AR试戴,重塑线上珠宝营销新体验!
3d·ar
DisonTangor2 天前
腾讯混元3D-1.0:文本到三维和图像到三维生成的统一框架
人工智能·3d·aigc
坠金3 天前
【3D】基础概念
3d