1
This commit is contained in:
@@ -5,41 +5,41 @@ using UnityEngine;
|
||||
/// <summary>
|
||||
/// 计算位置到边上最近的点
|
||||
/// </summary>
|
||||
public class AlgorithmSidePoint : ModuleAlgorithm<DataIntersect> {
|
||||
//public class AlgorithmSidePoint : ModuleAlgorithm<DataIntersect> {
|
||||
|
||||
protected override void Awake() => ModuleCore.AlgorithmSidePoint = this;
|
||||
// protected override void Awake() => ModuleCore.AlgorithmSidePoint = this;
|
||||
|
||||
public override void Compute(DataIntersect data) {
|
||||
Vector3 position = data.position - data.side.plate.designPosition;
|
||||
for (int i = 0; i < data.side.lines.Length; i++) {
|
||||
DataLine line = data.side.lines[i];
|
||||
if (!Compute(line, position, out Vector3 intersectPoint)) { continue; }
|
||||
data.isIntersect = true;
|
||||
data.intersectPoint = intersectPoint + data.side.plate.designPosition;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// public override void Compute(DataIntersect data) {
|
||||
// Vector3 position = data.position - data.side.plate.designPosition;
|
||||
// for (int i = 0; i < data.side.lines.Length; i++) {
|
||||
// DataLine line = data.side.lines[i];
|
||||
// if (!Compute(line, position, out Vector3 intersectPoint)) { continue; }
|
||||
// data.isIntersect = true;
|
||||
// data.intersectPoint = intersectPoint + data.side.plate.designPosition;
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
/// <summary> 查询匹配的边 </summary>
|
||||
private bool Compute(DataLine line, Vector3 position, out Vector3 intersectPoint) {
|
||||
return ProjectDistance(line.a, line.b, position, out intersectPoint);
|
||||
}
|
||||
// /// <summary> 查询匹配的边 </summary>
|
||||
// private bool Compute(DataLine line, Vector3 position, out Vector3 intersectPoint) {
|
||||
// return ProjectDistance(line.a, line.b, position, out intersectPoint);
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 向量投影法
|
||||
/// 计算点c到线段ab最近的点
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
/// <param name="b"></param>
|
||||
/// <param name="c"></param>
|
||||
/// <returns>如果不在线段上返回 false</returns>
|
||||
public static bool ProjectDistance(Vector3 a, Vector3 b, Vector3 c, out Vector3 intersectPoint) {
|
||||
Vector3 ab = b - a;
|
||||
Vector3 ac = c - a;
|
||||
Vector3 p = Vector3.Project(ac, ab.normalized);
|
||||
intersectPoint = p + a;
|
||||
if (ab.normalized != p.normalized) { return false; }
|
||||
if (ab.magnitude < p.magnitude) { return false; }
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// /// <summary>
|
||||
// /// 向量投影法
|
||||
// /// 计算点c到线段ab最近的点
|
||||
// /// </summary>
|
||||
// /// <param name="a"></param>
|
||||
// /// <param name="b"></param>
|
||||
// /// <param name="c"></param>
|
||||
// /// <returns>如果不在线段上返回 false</returns>
|
||||
// public static bool ProjectDistance(Vector3 a, Vector3 b, Vector3 c, out Vector3 intersectPoint) {
|
||||
// Vector3 ab = b - a;
|
||||
// Vector3 ac = c - a;
|
||||
// Vector3 p = Vector3.Project(ac, ab.normalized);
|
||||
// intersectPoint = p + a;
|
||||
// if (ab.normalized != p.normalized) { return false; }
|
||||
// if (ab.magnitude < p.magnitude) { return false; }
|
||||
// return true;
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -6,18 +6,18 @@ using UnityEngine;
|
||||
/// 散列点生成简单多边形算法
|
||||
/// </summary>
|
||||
public class AlgorithmSimplePolygon : ModuleAlgorithm<DataPlate> {
|
||||
private UnitAlgorithm<DataPlate> AlgorithmSideSubdivision = new UnitAlgorithmBezier();
|
||||
private UnitAlgorithm<DataPlate> AlgorithmTriangle = new UnitAlgorithmEarCutting();
|
||||
private UnitAlgorithm<DataPlate> AlgorithmMergeTriangle = new UnitAlgorithmMergeTriangle();
|
||||
private UnitAlgorithm<DataPlateDesign> AlgorithmSideSubdivision = new UnitAlgorithmJobsSideSubdivision();
|
||||
private UnitAlgorithm<DataPlateDesign> AlgorithmTriangle = new UnitAlgorithmEarCutting();
|
||||
private UnitAlgorithm<DataPlateDesign> AlgorithmMergeTriangle = new UnitAlgorithmMergeTriangle();
|
||||
|
||||
protected override void Awake() => ModuleCore.AlgorithmSimplePolygon = this;
|
||||
|
||||
public override void Compute(DataPlate data) {
|
||||
public override void Compute(DataPlate plate) {
|
||||
//遍历计算边(DataSide)上的细分点(positions)和线(lines)
|
||||
AlgorithmSideSubdivision.Compute(data);
|
||||
AlgorithmSideSubdivision.Compute(plate.dataDesign);
|
||||
//计算三角面
|
||||
AlgorithmTriangle.Compute(data);
|
||||
AlgorithmTriangle.Compute(plate.dataDesign);
|
||||
//三角面列表转换网格
|
||||
AlgorithmMergeTriangle.Compute(data);
|
||||
AlgorithmMergeTriangle.Compute(plate.dataDesign);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 缝合边算法模块
|
||||
/// </summary>
|
||||
public class AlgorithmSuture : ModuleAlgorithm<DataSuture> {
|
||||
/// <summary> 设计的缝合线 </summary>
|
||||
public UnitAlgorithm<DataSutureSide> SutureDesign = new UnitAlgorithmSutureDesign();
|
||||
/// <summary> 烘焙的缝合线 </summary>
|
||||
public UnitAlgorithm<DataSutureSide> SutureBaking = new UnitAlgorithmSutureBaking();
|
||||
|
||||
protected override void Awake() => ModuleCore.AlgorithmSuture = this;
|
||||
|
||||
public override void Compute(DataSuture suture) {
|
||||
//缝合边长
|
||||
float aLength = suture.a.plateSide.dataDesign.length;
|
||||
float bLength = suture.b.plateSide.dataDesign.length;
|
||||
suture.length = aLength < bLength ? aLength : bLength;
|
||||
//设计缝合顶点
|
||||
SutureDesign.Compute(suture.a);
|
||||
SutureDesign.Compute(suture.b);
|
||||
//烘焙缝合顶点
|
||||
SutureBaking.Compute(suture.a);
|
||||
SutureBaking.Compute(suture.b);
|
||||
//缝合锚点
|
||||
suture.points = new List<DataSuturePoint>();
|
||||
suture.points.AddRange(Compute(suture.a, suture.b));
|
||||
suture.points.AddRange(Compute(suture.b, suture.a));
|
||||
}
|
||||
private List<DataSuturePoint> Compute(DataSutureSide a, DataSutureSide b) {
|
||||
DataSutureSideVertex[] vertexs = a.dataBaking.vertexs;
|
||||
DataSutureSideVertex[] allVertexs = b.dataBaking.allVertexs;
|
||||
List<DataSuturePoint> suturePoints = new List<DataSuturePoint>();
|
||||
for (int i = 0; i < vertexs.Length; i++) {
|
||||
DataSutureSideVertex vertex = vertexs[i];
|
||||
for (int j = 0; j < allVertexs.Length; j++) {
|
||||
DataSutureSideVertex anchor = allVertexs[j];
|
||||
if (anchor.MaxDistance < vertex.origin) { continue; }
|
||||
DataSuturePoint suturePoint = new DataSuturePoint();
|
||||
suturePoint.distance = vertex.origin - anchor.origin;
|
||||
suturePoint.vertex = vertex.a;
|
||||
suturePoint.aAnchor = anchor.a;
|
||||
suturePoint.bAnchor = anchor.b;
|
||||
suturePoints.Add(suturePoint);
|
||||
}
|
||||
}
|
||||
return suturePoints;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc0a831375a5abe418c790ae74a19376
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -6,62 +6,62 @@ using UnityEngine;
|
||||
/// <summary>
|
||||
/// 缝合边算法模块
|
||||
/// </summary>
|
||||
public class AlgorithmSutureSide : ModuleAlgorithm<DataSutureSide> {
|
||||
public class VertexPosition : IComparable<VertexPosition> {
|
||||
public Vector3 designPosition;
|
||||
public Vector3 bakingPosition;
|
||||
public float distance;
|
||||
public int CompareTo(VertexPosition other) {
|
||||
return other.distance >= distance ? 1 : -1;
|
||||
}
|
||||
}
|
||||
//public class AlgorithmSutureSide : ModuleAlgorithm<DataSutureSide> {
|
||||
// public class VertexPosition : IComparable<VertexPosition> {
|
||||
// public Vector3 designPosition;
|
||||
// public Vector3 bakingPosition;
|
||||
// public float distance;
|
||||
// public int CompareTo(VertexPosition other) {
|
||||
// return other.distance >= distance ? 1 : -1;
|
||||
// }
|
||||
// }
|
||||
|
||||
protected override void Awake() => ModuleCore.AlgorithmSutureSide = this;
|
||||
// protected override void Awake() => ModuleCore.AlgorithmSutureSide = this;
|
||||
|
||||
public override void Compute(DataSutureSide data) {
|
||||
//List<VertexPosition> vertexPositions = VertexPositions(data);
|
||||
data.designPositions = VertexToDesignPositions(data).ToArray();
|
||||
data.bakingPositions = VertexToBakingPositions(data).ToArray();
|
||||
}
|
||||
// public override void Compute(DataSutureSide data) {
|
||||
// //List<VertexPosition> vertexPositions = VertexPositions(data);
|
||||
// data.designPositions = VertexToDesignPositions(data).ToArray();
|
||||
// data.bakingPositions = VertexToBakingPositions(data).ToArray();
|
||||
// }
|
||||
|
||||
private List<VertexPosition> VertexPositions(DataSutureSide sutureSide) {
|
||||
List<VertexPosition> vertexPositions = new List<VertexPosition>();
|
||||
for (int i = 0; i < sutureSide.Vertices.Length; i++) {
|
||||
Vector3 design = sutureSide.Vertices[i].design;
|
||||
Quaternion quaternion = Quaternion.Euler(sutureSide.PlateBakingEulerAngles);
|
||||
Vector3 baking = quaternion * sutureSide.Vertices[i].design;
|
||||
VertexPosition vertexPosition = new VertexPosition();
|
||||
vertexPosition.designPosition = design + sutureSide.PlateDesignPosition;
|
||||
vertexPosition.bakingPosition = baking + sutureSide.PlateBakingPosition;
|
||||
vertexPosition.distance = Vector3.Distance(design, sutureSide.side.aPoint.position);
|
||||
vertexPositions.Add(vertexPosition);
|
||||
}
|
||||
//按距离从小到大排序
|
||||
vertexPositions.Sort();
|
||||
//是否颠倒
|
||||
if (sutureSide.isReversal) { vertexPositions.Reverse(); }
|
||||
return vertexPositions;
|
||||
}
|
||||
private List<Vector3> VertexToDesignPositions(DataSutureSide data) {
|
||||
//转换列表
|
||||
List<Vector3> positions = new List<Vector3>();
|
||||
for (int i = 0; i < data.Vertices.Length; i++) {
|
||||
Vector3 position = data.Vertices[i].design + data.PlateDesignPosition;
|
||||
positions.Add(position);
|
||||
}
|
||||
if (data.isReversal) { positions.Reverse(); }
|
||||
return positions;
|
||||
}
|
||||
private List<Vector3> VertexToBakingPositions(DataSutureSide data) {
|
||||
//转换列表
|
||||
List<Vector3> positions = new List<Vector3>();
|
||||
for (int i = 0; i < data.Vertices.Length; i++) {
|
||||
Quaternion quaternion = Quaternion.Euler(data.PlateBakingEulerAngles);
|
||||
Vector3 baking = quaternion * data.Vertices[i].design;
|
||||
Vector3 position = baking + data.PlateBakingPosition;
|
||||
positions.Add(position);
|
||||
}
|
||||
if (data.isReversal) { positions.Reverse(); }
|
||||
return positions;
|
||||
}
|
||||
}
|
||||
// private List<VertexPosition> VertexPositions(DataSutureSide sutureSide) {
|
||||
// List<VertexPosition> vertexPositions = new List<VertexPosition>();
|
||||
// for (int i = 0; i < sutureSide.Vertices.Length; i++) {
|
||||
// Vector3 design = sutureSide.Vertices[i].design;
|
||||
// Quaternion quaternion = Quaternion.Euler(sutureSide.PlateBakingEulerAngles);
|
||||
// Vector3 baking = quaternion * sutureSide.Vertices[i].design;
|
||||
// VertexPosition vertexPosition = new VertexPosition();
|
||||
// vertexPosition.designPosition = design + sutureSide.PlateDesignPosition;
|
||||
// vertexPosition.bakingPosition = baking + sutureSide.PlateBakingPosition;
|
||||
// vertexPosition.distance = Vector3.Distance(design, sutureSide.side.aPoint.position);
|
||||
// vertexPositions.Add(vertexPosition);
|
||||
// }
|
||||
// //按距离从小到大排序
|
||||
// vertexPositions.Sort();
|
||||
// //是否颠倒
|
||||
// if (sutureSide.isReversal) { vertexPositions.Reverse(); }
|
||||
// return vertexPositions;
|
||||
// }
|
||||
// private List<Vector3> VertexToDesignPositions(DataSutureSide data) {
|
||||
// //转换列表
|
||||
// List<Vector3> positions = new List<Vector3>();
|
||||
// for (int i = 0; i < data.Vertices.Length; i++) {
|
||||
// Vector3 position = data.Vertices[i].design + data.PlateDesignPosition;
|
||||
// positions.Add(position);
|
||||
// }
|
||||
// if (data.isReversal) { positions.Reverse(); }
|
||||
// return positions;
|
||||
// }
|
||||
// private List<Vector3> VertexToBakingPositions(DataSutureSide data) {
|
||||
// //转换列表
|
||||
// List<Vector3> positions = new List<Vector3>();
|
||||
// for (int i = 0; i < data.Vertices.Length; i++) {
|
||||
// Quaternion quaternion = Quaternion.Euler(data.PlateBakingEulerAngles);
|
||||
// Vector3 baking = quaternion * data.Vertices[i].design;
|
||||
// Vector3 position = baking + data.PlateBakingPosition;
|
||||
// positions.Add(position);
|
||||
// }
|
||||
// if (data.isReversal) { positions.Reverse(); }
|
||||
// return positions;
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ResetBakingPolygon : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f24a4f73b9925a9478f58b089059ef1e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user