效果展示

1.首先先下载一个模型剖切插件Cross-Section插件 没有的下方链接自取

插件下载链接

2.下载之后导入到项目  导入之后的样子如下图

因项目需求需要剖切模型,要使用滑动条进行剖切,插件中有很多demo,其中就有使用滑动条的,可是只能进行单独一个面的剖切,换面操作模型会恢复原状,需求是可以同时操作三个面剖切,模型不恢复原状

插件demo     视频链接一      视频链接二

最后只能在插件里面修改

修改了CappedSectionBox这个脚本

修改结果如下 代码很长就折叠了

//The purpose of this script is to manipulate the scale and position of the capped section box gizmo object
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; namespace WorldSpaceTransitions
{
public class CappedSectionBox : MonoBehaviour, ISizedSection
{ //public LayerMask layer = 13;
//[Space(10)]
public Collider xAxis;
public Collider xAxisNeg;
[Space(10)]
public Collider yAxis;
public Collider yAxisNeg;
[Space(10)]
public Collider zAxis;
public Collider zAxisNeg; private enum GizmoAxis { X, Y, Z, Xneg, Yneg, Zneg, XYRotate, XZRotate, YZRotate, none };
private GizmoAxis selectedAxis; private RaycastHit hit;
private Ray ray, ray1;
private Plane dragplane;
private float rayDistance, newRotY, rayDistancePrev, distance;
private Vector3 lookCamera, startDrag, startPos, startDragRot, lookHitPoint, startScale;
private bool dragging; #region 自己加的改动 改成滑动条剖切
/// <summary>
/// 发射射线的物体 世界坐标的x轴 y轴 z轴 方向 各放一个位置作为起点
/// </summary>
public GameObject rayobj_X, rayobj_Y, rayobj_Z;
public Slider sliderX,sliderY,sliderZ; // Use this for initialization
void Start()
{ //滑动条的数值如果不是很准确 就把 maxValue minValue调试到合适的值就可以了
sliderX.maxValue = xAxis.transform.position.x;
sliderX.minValue = -(xAxis.transform.position.x);
sliderX.value = sliderX.maxValue;// + this.transform.position.x; sliderY.maxValue = yAxis.transform.position.y;
sliderY.minValue = -(yAxis.transform.position.y)/2;
sliderY.value = sliderY.maxValue;// + this.transform.position.y; //不准确自己手动调吧 其他轴不准确的也自己调一下就行了
sliderZ.maxValue = zAxis.transform.position.z;
sliderZ.minValue = -zAxis.transform.position.z;
sliderZ.value = sliderZ.maxValue; }
public void 滑动条按下(int aa)
{
if (aa==0)
{
dragplane = new Plane();
RaycastHit hit;
if (Physics.Raycast(rayobj_X.transform.position ,xAxis .transform.position , out hit, 1000f))
{
selectedAxis = GizmoAxis.X;
dragplane.SetNormalAndPosition(transform.right, transform.position);
}
distance = hit.distance;
startDrag = new Vector3(xAxis.transform.position.x, xAxis.transform.position.y, distance);
startPos = transform.position;
startScale = transform.localScale;
dragging = true;
}
else if (aa==1)
{ dragplane = new Plane();
RaycastHit hit;
if (Physics.Raycast(rayobj_Y.transform.position, yAxis.transform.position, out hit, 1000f))
{
selectedAxis = GizmoAxis.Y;
dragplane.SetNormalAndPosition(transform.up, transform.position);
} distance = hit.distance;
startDrag = new Vector3(yAxis.transform.position.x, yAxis.transform.position.y, distance);
startPos = transform.position;
startScale = transform.localScale;
dragging = true; }
else if (aa==2)
{
dragplane = new Plane();
RaycastHit hit;
if (Physics.Raycast(rayobj_Z.transform.position, zAxis.transform.position, out hit, 1000f))
{
selectedAxis = GizmoAxis.Z;
dragplane.SetNormalAndPosition(transform.forward, transform.position);
}
Debug.DrawLine(rayobj_Z.transform.position, zAxis.transform.position, Color.red,10f);
distance = hit.distance;
startDrag = new Vector3(zAxis.transform.position.x, zAxis.transform.position.y, zAxis.transform.position.z);
startPos = transform.position;
startScale = transform.localScale;
dragging = true;
} }
public void 滑动条拖动(int aa)
{
if (aa == 0)
{
if (dragging)
{
float lsx = startScale.x;
float lsy = startScale.y;
float lsz = startScale.z;
Vector3 onDrag = new Vector3(sliderX.value, xAxis.transform.position.y, distance);
Vector3 translation = onDrag - startDrag;
Vector3 projectedTranslation = Vector3.zero; projectedTranslation = Vector3.Project(translation, transform.right);
transform.position = startPos + 0.5f * (projectedTranslation.normalized * translation.magnitude);
lsx += translation.magnitude * Mathf.Sign(Vector3.Dot(projectedTranslation, transform.right));
transform.localScale = new Vector3(Mathf.Clamp(lsx, 0.01f, Mathf.Infinity), Mathf.Clamp(lsy, 0.01f, Mathf.Infinity), Mathf.Clamp(lsz, 0.01f, Mathf.Infinity));
}
}
else if (aa==1)
{
if (dragging)
{
float lsx = startScale.x;
float lsy = startScale.y;
float lsz = startScale.z;
Vector3 onDrag = new Vector3(yAxis.transform.position.x , sliderY.value, distance);
Vector3 translation = onDrag - startDrag;
Vector3 projectedTranslation = Vector3.zero; projectedTranslation = Vector3.Project(translation, transform.up);
transform.position = startPos + 0.5f * (projectedTranslation.normalized * translation.magnitude);
lsy += translation.magnitude * Mathf.Sign(Vector3.Dot(projectedTranslation, transform.up));
transform.localScale = new Vector3(Mathf.Clamp(lsx, 0.01f, Mathf.Infinity), Mathf.Clamp(lsy, 0.01f, Mathf.Infinity), Mathf.Clamp(lsz, 0.01f, Mathf.Infinity));
}
}
else if (aa==2)
{
if (dragging)
{
float lsx = startScale.x;
float lsy = startScale.y;
float lsz = startScale.z;
Vector3 onDrag = new Vector3(zAxis.transform.position.x, zAxis.transform.position.y, (distance+sliderZ.value));
Vector3 translation = onDrag - startDrag;
Vector3 projectedTranslation = Vector3.zero; projectedTranslation = Vector3.Project(translation, transform.forward);
transform.position = startPos + 0.5f * (projectedTranslation.normalized * translation.magnitude);
lsz += translation.magnitude * Mathf.Sign(Vector3.Dot(projectedTranslation, transform.forward));
transform.localScale = new Vector3(Mathf.Clamp(lsx, 0.01f, Mathf.Infinity), Mathf.Clamp(lsy, 0.01f, Mathf.Infinity), Mathf.Clamp(lsz, 0.01f, Mathf.Infinity));
}
}
}
public void 滑动条停止()
{
dragging = false;
} #endregion
// Update is called once per frame
void Update()
{ //if (Input.GetMouseButtonDown(0))
//{ // ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// dragplane = new Plane(); // RaycastHit hit;
// if (xAxis.Raycast(ray, out hit, 1000f))
// {
// selectedAxis = GizmoAxis.X;
// dragplane.SetNormalAndPosition(transform.up, transform.position);
// }
// else if (xAxisNeg.Raycast(ray, out hit, 1000f))
// {
// selectedAxis = GizmoAxis.Xneg;
// dragplane.SetNormalAndPosition(-transform.up, transform.position);
// }
// else if (yAxis.Raycast(ray, out hit, 1000f))
// {
// selectedAxis = GizmoAxis.Y;
// dragplane.SetNormalAndPosition(transform.forward, transform.position);
// }
// else if (yAxisNeg.Raycast(ray, out hit, 1000f))
// {
// selectedAxis = GizmoAxis.Yneg;
// dragplane.SetNormalAndPosition(-transform.forward, transform.position);
// }
// else if (zAxis.Raycast(ray, out hit, 1000f))
// {
// selectedAxis = GizmoAxis.Z;
// dragplane.SetNormalAndPosition(transform.up, transform.position);
// }
// else if (zAxisNeg.Raycast(ray, out hit, 1000f))
// {
// selectedAxis = GizmoAxis.Zneg;
// dragplane.SetNormalAndPosition(-transform.up, transform.position);
// }
// else
// {
// //Debug.Log(hit.collider.name);
// return;
// }
// distance = hit.distance;
// startDrag = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance));
// startPos = transform.position;
// startScale = transform.localScale;
// dragging = true;
//} //if (dragging)
//{
// ray = Camera.main.ScreenPointToRay(Input.mousePosition); // Vector3 onDrag = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance));
// Vector3 translation = onDrag - startDrag;
// Vector3 projectedTranslation = Vector3.zero; // if (dragging)
// {
// float lsx = startScale.x;
// float lsy = startScale.y;
// float lsz = startScale.z; // switch (selectedAxis)
// {
// case GizmoAxis.X:
// {
// projectedTranslation = Vector3.Project(translation, transform.right);
// transform.position = startPos + 0.5f * (projectedTranslation.normalized * translation.magnitude);
// lsx += translation.magnitude * Mathf.Sign(Vector3.Dot(projectedTranslation, transform.right));
// break;
// }
// case GizmoAxis.Xneg:
// {
// projectedTranslation = Vector3.Project(translation, -transform.right);
// transform.position = startPos + 0.5f * (projectedTranslation.normalized * translation.magnitude);
// lsx += translation.magnitude * Mathf.Sign(Vector3.Dot(projectedTranslation, -transform.right));
// break;
// }
// case GizmoAxis.Y:
// {
// projectedTranslation = Vector3.Project(translation, transform.up);
// transform.position = startPos + 0.5f * (projectedTranslation.normalized * translation.magnitude);
// lsy += translation.magnitude * Mathf.Sign(Vector3.Dot(projectedTranslation, transform.up));
// break;
// }
// case GizmoAxis.Yneg:
// {
// projectedTranslation = Vector3.Project(translation, -transform.up);
// transform.position = startPos + 0.5f * (projectedTranslation.normalized * translation.magnitude);
// lsy += translation.magnitude * Mathf.Sign(Vector3.Dot(projectedTranslation, -transform.up));
// break;
// }
// case GizmoAxis.Z:
// {
// projectedTranslation = Vector3.Project(translation, transform.forward);
// transform.position = startPos + 0.5f * (projectedTranslation.normalized * translation.magnitude);
// lsz += translation.magnitude * Mathf.Sign(Vector3.Dot(projectedTranslation, transform.forward));
// break;
// }
// case GizmoAxis.Zneg:
// {
// projectedTranslation = Vector3.Project(translation, -transform.forward);
// transform.position = startPos + 0.5f * (projectedTranslation.normalized * translation.magnitude);
// lsz += translation.magnitude * Mathf.Sign(Vector3.Dot(projectedTranslation, -transform.forward));
// break;
// } // } // transform.localScale = new Vector3(Mathf.Clamp(lsx, 0.01f, Mathf.Infinity), Mathf.Clamp(lsy, 0.01f, Mathf.Infinity), Mathf.Clamp(lsz, 0.01f, Mathf.Infinity)); // //foreach (UVScaler uvs in gameObject.GetComponentsInChildren<UVScaler>()) uvs.SetUV();
// } // if (Input.GetMouseButtonUp(0))
// {
// dragging = false;
// }
//}
} public void HideCage(bool val)
{
foreach (PlaneHover ph in gameObject.GetComponentsInChildren<PlaneHover>()) ph.GetComponent<Renderer>().enabled = val;
}
public void HideCaps(bool val)
{
foreach (Transform quad in gameObject.transform) if (quad.name.Contains("hatch")) quad.GetComponent<Renderer>().enabled = val;
} public void Size(Bounds b, GameObject g, BoundsOrientation orientation)
{
//Debug.Log(b.ToString());
float scale = 1f; Vector3 clearance = 0.01f * Vector3.one; transform.localScale = Vector3.one; transform.localScale = scale * b.size + clearance; transform.position = b.center;
}
}
}

CappedSectionBox

修改完之后就是效果展示的样子了

项目Hierarchy截图  用的就是插件里面带的demo

最后再把插件修改过后的资源包发一下吧,以免其他小伙伴出错

修改之后的插件资源包下载

亲测2021.3.4可以打包

之后又更改了既可以滑动条模型剖切,也可以鼠标点击模型进行剖切

只改了一个脚本如下 复制替换即可 

//The purpose of this script is to manipulate the scale and position of the capped section box gizmo object
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI; namespace WorldSpaceTransitions
{
public class CappedSectionBox : MonoBehaviour, ISizedSection
{ //public LayerMask layer = 13;
//[Space(10)]
public Collider xAxis;
public Collider xAxisNeg;
[Space(10)]
public Collider yAxis;
public Collider yAxisNeg;
[Space(10)]
public Collider zAxis;
public Collider zAxisNeg; private enum GizmoAxis { X, Y, Z, Xneg, Yneg, Zneg, XYRotate, XZRotate, YZRotate, none };
private GizmoAxis selectedAxis; private RaycastHit hit;
private Ray ray, ray1;
private Plane dragplane;
private float rayDistance, newRotY, rayDistancePrev, distance;
private Vector3 lookCamera, startDrag, startPos, startDragRot, lookHitPoint, startScale;
private bool dragging;
private bool dragging_; #region 自己加的改动 改成滑动条剖切
/// <summary>
/// 发射射线的物体
/// </summary>
//public GameObject rayobj_X, rayobj_Y, rayobj_Z;
public Slider sliderX, sliderY, sliderZ; private float floatminX, floatminY, floatminZ, floatmaxX, floatmaxY, floatmaxZ;
private float flokmax, flokmay, flokmaz;
private float blx, bly, blz; // Use this for initialization
void Start()
{ //GetSliderData();
}
public void GetSliderData()
{
floatminX = xAxisNeg.transform.position.x;
floatminY = yAxisNeg.transform.position.y;
floatminZ = zAxisNeg.transform.position.z; floatmaxX = xAxis.transform.position.x;
floatmaxY = yAxis.transform.position.y;
floatmaxZ = zAxis.transform.position.z; sliderX.maxValue = floatmaxX;
sliderX.minValue = floatminX;
sliderX.value = floatmaxX;// + this.transform.position.x; sliderY.maxValue = floatmaxY;
sliderY.minValue = floatminY;
sliderY.value = floatmaxY;// + this.transform.position.y; sliderZ.maxValue = floatmaxZ;
sliderZ.minValue = floatminZ;
sliderZ.value = floatmaxZ; flokmax = transform.localScale.x;
flokmay = transform.localScale.y;
flokmaz = transform.localScale.z; blx = GetSpecific_value(floatmaxX, floatminX, flokmax);
bly = GetSpecific_value(floatmaxY, floatminY, flokmay);
blz = GetSpecific_value(floatmaxZ, floatminZ, flokmaz); }
public void 滑动条按下(int aa)
{
if (aa == 0)
{
dragplane = new Plane();
RaycastHit hit;
if (xAxis.Raycast(ray, out hit, 1000f))
{
selectedAxis = GizmoAxis.X;
dragplane.SetNormalAndPosition(transform.right, transform.position);
}
distance = hit.distance;
startDrag = new Vector3(xAxis.transform.position.x, xAxis.transform.position.y, distance);
startPos = transform.position;
startScale = transform.localScale;
}
else if (aa == 1)
{ dragplane = new Plane();
RaycastHit hit;
//if (Physics.Raycast(rayobj_Y.transform.position, yAxis.transform.position, out hit, 1000f))
if (yAxis.Raycast(ray, out hit, 1000f))
{
selectedAxis = GizmoAxis.Y;
dragplane.SetNormalAndPosition(transform.up, transform.position);
}
distance = hit.distance;
startDrag = new Vector3(yAxis.transform.position.x, yAxis.transform.position.y, distance);
startPos = transform.position;
startScale = transform.localScale;
}
else if (aa == 2)
{
dragplane = new Plane();
RaycastHit hit;
if (zAxis.Raycast(ray, out hit, 1000f))
{
selectedAxis = GizmoAxis.Z;
dragplane.SetNormalAndPosition(transform.forward, transform.position);
}
//Debug.DrawLine(rayobj_Z.transform.position, zAxis.transform.position, Color.red, 10f);
distance = hit.distance;
startDrag = new Vector3(zAxis.transform.position.x, zAxis.transform.position.y, zAxis.transform.position.z);
startPos = transform.position;
startScale = transform.localScale;
}
滑动条拖动(aa); }
public void 滑动条拖动(int aa)
{
if (aa == 0)
{
float lsx = startScale.x;
float lsy = startScale.y;
float lsz = startScale.z;
Vector3 onDrag = new Vector3(sliderX.value, xAxis.transform.position.y, distance);
Vector3 translation = onDrag - startDrag;
Vector3 projectedTranslation = Vector3.zero; projectedTranslation = Vector3.Project(translation, transform.right);
transform.position = startPos + 0.5f * (projectedTranslation.normalized * translation.magnitude);
lsx += translation.magnitude * Mathf.Sign(Vector3.Dot(projectedTranslation, transform.right));
transform.localScale = new Vector3(Mathf.Clamp(lsx, 0.01f, Mathf.Infinity), Mathf.Clamp(lsy, 0.01f, Mathf.Infinity), Mathf.Clamp(lsz, 0.01f, Mathf.Infinity));
}
else if (aa == 1)
{
float lsx = startScale.x;
float lsy = startScale.y;
float lsz = startScale.z;
Vector3 onDrag = new Vector3(yAxis.transform.position.x, sliderY.value, distance);
Vector3 translation = onDrag - startDrag;
Vector3 projectedTranslation = Vector3.zero; projectedTranslation = Vector3.Project(translation, transform.up);
transform.position = startPos + 0.5f * (projectedTranslation.normalized * translation.magnitude);
lsy += translation.magnitude * Mathf.Sign(Vector3.Dot(projectedTranslation, transform.up));
transform.localScale = new Vector3(Mathf.Clamp(lsx, 0.01f, Mathf.Infinity), Mathf.Clamp(lsy, 0.01f, Mathf.Infinity), Mathf.Clamp(lsz, 0.01f, Mathf.Infinity));
}
else if (aa == 2)
{
float lsx = startScale.x;
float lsy = startScale.y;
float lsz = startScale.z;
Vector3 onDrag = new Vector3(zAxis.transform.position.x, zAxis.transform.position.y, (sliderZ.value-distance));
Vector3 translation = onDrag - startDrag;
Vector3 projectedTranslation = Vector3.zero; projectedTranslation = Vector3.Project(translation, transform.forward);
transform.position = startPos + 0.5f * (projectedTranslation.normalized * translation.magnitude);
lsz += translation.magnitude * Mathf.Sign(Vector3.Dot(projectedTranslation, transform.forward));
transform.localScale = new Vector3(Mathf.Clamp(lsx, 0.01f, Mathf.Infinity), Mathf.Clamp(lsy, 0.01f, Mathf.Infinity), Mathf.Clamp(lsz, 0.01f, Mathf.Infinity));
}
}
#endregion
// Update is called once per frame
void Update()
{ if (Input.GetMouseButtonDown(0) && EventSystem.current.IsPointerOverGameObject() == false)
{ ray = Camera.main.ScreenPointToRay(Input.mousePosition);
dragplane = new Plane(); RaycastHit hit;
if (xAxis.Raycast(ray, out hit, 1000f))
{
selectedAxis = GizmoAxis.X;
dragplane.SetNormalAndPosition(transform.up, transform.position);
}
else if (xAxisNeg.Raycast(ray, out hit, 1000f))
{
selectedAxis = GizmoAxis.Xneg;
dragplane.SetNormalAndPosition(-transform.up, transform.position);
}
else if (yAxis.Raycast(ray, out hit, 1000f))
{
selectedAxis = GizmoAxis.Y;
dragplane.SetNormalAndPosition(transform.forward, transform.position);
}
else if (yAxisNeg.Raycast(ray, out hit, 1000f))
{
selectedAxis = GizmoAxis.Yneg;
dragplane.SetNormalAndPosition(-transform.forward, transform.position);
}
else if (zAxis.Raycast(ray, out hit, 1000f))
{
selectedAxis = GizmoAxis.Z;
dragplane.SetNormalAndPosition(transform.up, transform.position);
}
else if (zAxisNeg.Raycast(ray, out hit, 1000f))
{
selectedAxis = GizmoAxis.Zneg;
dragplane.SetNormalAndPosition(-transform.up, transform.position);
}
else
{
//Debug.Log(hit.collider.name);
return;
}
distance = hit.distance;
startDrag = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance));
startPos = transform.position;
startScale = transform.localScale; dragging_ = true;
} if (dragging_)
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition); Vector3 onDrag = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance));
Vector3 translation = onDrag - startDrag;
Vector3 projectedTranslation = Vector3.zero; float lsx = startScale.x;
float lsy = startScale.y;
float lsz = startScale.z; switch (selectedAxis)
{
case GizmoAxis.X:
{
projectedTranslation = Vector3.Project(translation, transform.right);
transform.position = startPos + 0.5f * (projectedTranslation.normalized * translation.magnitude);
lsx += translation.magnitude * Mathf.Sign(Vector3.Dot(projectedTranslation, transform.right));
break;
}
//case GizmoAxis.Xneg:
// {
// projectedTranslation = Vector3.Project(translation, -transform.right);
// transform.position = startPos + 0.5f * (projectedTranslation.normalized * translation.magnitude);
// lsx += translation.magnitude * Mathf.Sign(Vector3.Dot(projectedTranslation, -transform.right));
// break;
// }
case GizmoAxis.Y:
{
projectedTranslation = Vector3.Project(translation, transform.up);
transform.position = startPos + 0.5f * (projectedTranslation.normalized * translation.magnitude);
lsy += translation.magnitude * Mathf.Sign(Vector3.Dot(projectedTranslation, transform.up));
break;
}
//case GizmoAxis.Yneg:
// {
// projectedTranslation = Vector3.Project(translation, -transform.up);
// transform.position = startPos + 0.5f * (projectedTranslation.normalized * translation.magnitude);
// lsy += translation.magnitude * Mathf.Sign(Vector3.Dot(projectedTranslation, -transform.up));
// break;
// }
case GizmoAxis.Z:
{
projectedTranslation = Vector3.Project(translation, transform.forward);
transform.position = startPos + 0.5f * (projectedTranslation.normalized * translation.magnitude);
lsz += translation.magnitude * Mathf.Sign(Vector3.Dot(projectedTranslation, transform.forward));
break;
}
//case GizmoAxis.Zneg:
// {
// projectedTranslation = Vector3.Project(translation, -transform.forward);
// transform.position = startPos + 0.5f * (projectedTranslation.normalized * translation.magnitude);
// lsz += translation.magnitude * Mathf.Sign(Vector3.Dot(projectedTranslation, -transform.forward));
// break;
// } } transform.localScale = new Vector3(Mathf.Clamp(lsx, 0.01f, Mathf.Infinity), Mathf.Clamp(lsy, 0.01f, Mathf.Infinity), Mathf.Clamp(lsz, 0.01f, Mathf.Infinity)); //比例值根据公式计算所得 lsx (框)的区间 是0-lsx 滑动条上面也有一个值的区间 min-max
//公式: (0*x)+y= 滑动条最小值 min
// (lsx*x)+y=滑动条最大值 max
//最后求出 x值 y值 带进去即可 因为模型大小都不一样,比例值也不一致,需要自行计算
sliderX.value = lsx * blx + floatminX;
sliderY.value = lsy * bly + floatminY;
sliderZ.value = lsz * blz + floatminZ; if (Input.GetMouseButtonUp(0))
{
dragging_ = false;
}
}
}
public float GetSpecific_value(float MAX, float MIN, float LXYZ)
{
float AA = (MAX - MIN) / LXYZ;
return AA;
} public void HideCage(bool val)
{
foreach (PlaneHover ph in gameObject.GetComponentsInChildren<PlaneHover>()) ph.GetComponent<Renderer>().enabled = val;
}
public void HideCaps(bool val)
{
foreach (Transform quad in gameObject.transform) if (quad.name.Contains("hatch")) quad.GetComponent<Renderer>().enabled = val;
} public void Size(Bounds b, GameObject g, BoundsOrientation orientation)
{
//Debug.Log(b.ToString());
float scale = 1f; Vector3 clearance = 0.01f * Vector3.one; transform.localScale = Vector3.one; transform.localScale = scale * b.size + clearance; transform.position = b.center;
}
}
}

修改之后的脚本

再加一个自动设置剖切的脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using WorldSpaceTransitions; public class AutoSheScript : MonoBehaviour
{
public GameObject pouqieObj;
public SectionSetup sectionSetup_;
public CappedSectionBox cappedSectionBox_; // Start is called before the first frame update
void Start()
{
//模型标签"PouQie"
pouqieObj = GameObject.FindGameObjectWithTag("PouQie");
}
//执行剖切 剖切框就会自动设置好
public void Perform_Cutting()
{ sectionSetup_.model = pouqieObj;
sectionSetup_.RecalculateBounds();
sectionSetup_.CheckShaders();
sectionSetup_.CreateSectionMaterials();
cappedSectionBox_.GetSliderData(); }
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown (KeyCode.Space))
{
Perform_Cutting();
}
}
}

自动设置剖切

修改之后的效果

没有积分的可以评论区联系我,看到会回复的

如果喜欢请给我点个赞吧,谢谢

搜索

复制

Unity模型剖切的更多相关文章

  1. xBIM WeXplorer xViewer的导航,相机、剖切、隐藏 等操作

    目录 基础 xBIM WeXplorer 简要介绍 xBIM WeXplorer xViewer 基本应用 xBIM WeXplorer xViewer 浏览器检查 xBIM WeXplorer xV ...

  2. SkylineGlobe 7.0.1 & 7.0.2版本Web开发 如何实现对三维模型和地形的剖切展示

    现在很多三维项目中,不仅仅要用到三维地形,正射影像和矢量数据,还会融合到各种三维模型,包括传统的3DMax手工建模,BIM,倾斜摄影自动建模,激光点云模型,三维地质体模型等等. 三维平台首先要做的是把 ...

  3. xBIM 基础12 WeXplorer xViewer的导航、相机、剖切、隐藏等操作

    系列目录    [已更新最新开发文章,点击查看详细]  本篇将学习xViewer的导航,剪切和隐藏.这应该足以使用户能够通过所有缩放,平移,轨道运行和隐藏可能的障碍物来检查建筑物内部.点击这里可以看到 ...

  4. 【VR视频播放】解决Unity模型贴图反转的问题

    使用UV贴图网模型上贴的时候, 会出现图片反过来的情况. 根本原因是因为, 一般系统的屏幕坐标系(例如Android)是左上角为原点(0,0), 但是Unity的贴图是以左下角为原点(0,0) 方法有 ...

  5. Unity模型导入的若干问题

    原地址:http://tieba.baidu.com/p/2807225555 我觉得有三点感觉在导出时比较重要的1.单位的设置3dsmax系统单位设置就设成厘米显示单位公制也设成厘米这样在max里的 ...

  6. unity模型任意无限切割插件

    概述 3d模型的任意切割一直是游戏开发里的一个很大的问题,模型切割的关键点就只有生成横切面的新顶点以及切口纹理的缝合,理论上解决了这两点,就近乎可以做到以假乱真的程度了.本篇文章就这两点进行描述 详细 ...

  7. unity 模型层次细节

    http://blog.csdn.net/qq_25210959/article/details/51734517 层次细节(LOD),它是根据物体在游戏画面中所占视图的百分比来调用不同复杂度的模型的 ...

  8. unity模型法线反转问题

    fbx模型导入unity正常 但只要绑了骨骼,在3dmax中正常,进入unity就法线反转 原因是3dmax中模型用到复制和镜像的导出需要多一步处理 1重置变换 2反转法线 按顺序进行这两个,在绑定模 ...

  9. Unity 模型导入导出

    从3DMAX导出,参考: http://tieba.baidu.com/p/2807225555 -> 使用3dmax 2013,会自带导出 fbx 的功能 -> 从 3dmax 导出 - ...

  10. Unity模型导入导出

    从3DMAX导出,参考: http://tieba.baidu.com/p/2807225555 -> 使用3dmax 2013,会自带导出 fbx 的功能 -> 从 3dmax 导出 - ...

随机推荐

  1. webpack打包后发现有一部分代码还携带注释,如何解决?/webpack打包删除注释以及console.log--快快点进来看一看吧~~

    1.自己配置了一个webpack,打包后发现里边部分代码还存在注释,顿感不妙 废话不多说 解决如下: npm install terser-webpack-plugin --save-dev 然后在w ...

  2. 【随笔记】T507 ADC SGM58031 16BIT 4Channel 调试记录

    文章介绍 本文主要描述在 T507 Android 10 Linux 4.9 平台下,调试 SGM58031 芯片的记录,实现单芯片实时采集外部四通道的电压数值. 芯片介绍 SGM58031 是一款低 ...

  3. 12月20日内容总结——ajax补充知识点、多对多外键的三种创建方式、django内置序列化组件、批量操作数据、分页器推导思路与自定义分页器的使用、form组件

    目录 一.ajax补充说明 二.多对多三种创建方式 三.django内置序列化组件(drf前身) 四.批量操作数据 五.分页器思路 六.自定义分页器的使用 七.form组件 forms组件介绍 For ...

  4. IoT 边缘集群基于 Kubernetes Events 的告警通知实现(二):进一步配置

    上一篇文章 IoT 边缘集群基于 Kubernetes Events 的告警通知实现 目标 告警恢复通知 - 经过评估无法实现 原因: 告警和恢复是单独完全不相关的事件, 告警是 Warning 级别 ...

  5. 固定SRAM地址变量

    IAR: __no_init uint8_t _downflag @0x2001FF00;

  6. Windows QT程序配置删除网卡IP

    1.Windows下可在CMD控制终端使用Dos命令对指定网卡进行IP配置,需要使用管理员权限打开CMD终端 往网卡添加IP主要有以下两种方法: 方法1: netsh interface ip add ...

  7. 2013-12-2 ISBN号码

    问题描述 试题编号: 201312-2 试题名称: ISBN号码 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 每一本正式出版的图书都有一个ISBN号码与之对应,ISBN码包 ...

  8. 代码随想录算法训练营day16 | leetcode ● 104.二叉树的最大深度 559.n叉树的最大深度 ● 111.二叉树的最小深度 ● 222.完全二叉树的节点个数

    基础知识 二叉树的多种遍历方式,每种遍历方式各有其特点 LeetCode 104.二叉树的最大深度 分析1.0 往下遍历深度++,往上回溯深度-- class Solution { int deep ...

  9. .Net 6 miniAPI

    启动:1.双击 WebApplication1.exe文件   2.dotnet WebApplication1.dll --urls "http://localhost:5403;http ...

  10. 基于C++的OpenGL 09 之材质

    1. 引言 本文基于C++语言,描述OpenGL的材质 前置知识可参考: 基于C++的OpenGL 08 之基础光照 - 当时明月在曾照彩云归 - 博客园 (cnblogs.com) 笔者这里不过多描 ...