public void Execute(List <string> param, ObjModel model) { var vertices = param.ConvertAll <ObjVertex>( (str) => { var vertex = ObjVertex.Parse(model.CurrentMesh, str); for (int i = 0; i < vertex.attrIndex.Length; i++) { vertex.attrIndex[i] -= 1; } return(vertex); } ); if (vertices.Count > 0) { if (model.CurrentMesh.vertexVaiidFlag == 0) { model.CurrentMesh.vertexVaiidFlag = vertices[0] != null ? vertices[0].GetValidFlag() : 0; } if (model.CurrentMesh.vertexVaiidFlag == 0) { return; } AddNewFace(model.CurrentMesh, vertices); } }
public static string Dump(this ObjVertex vertex) { StringBuilder sb = new StringBuilder(); sb.Append("["); int count = vertex.attrIndex.Length; for (int i = 0; i < count; i++) { sb.Append(string.Format("<{0}>", vertex.attrIndex[i])); } sb.Append("]"); return(sb.ToString()); }
static int GetCornerIndex(Mesh mesh, ObjVertex vertex, bool addNewCorner = true) { for (int i = 0; i < mesh.objVertexList.Count; i++) { if (mesh.objVertexList[i].Equals(vertex)) { return(i); } } if (addNewCorner) { mesh.objVertexList.Add(vertex); return(mesh.objVertexList.Count - 1); } return(-1); }
public List <ParamVector[]> Select(params string[] attrNames) { List <ParamVector[]> result = new List <ParamVector[]>(); int vertexCount = objVertexList.Count; if (attrNames == null) { attrNames = this.attrNames.ToArray(); } int vectorRowLength = attrNames.Length; for (int cornerIndex = 0; cornerIndex < vertexCount; cornerIndex++) { ParamVector[] vectorRow = new ParamVector[vectorRowLength]; ObjVertex objVertex = objVertexList[cornerIndex]; for (int i = 0; i < vectorRow.Length; i++) { string componentName = attrNames[i]; int nameIndex = this.attrNames.FindIndex(str => str == componentName); if (nameIndex >= 0 && nameIndex < objVertex.attrIndex.Length) { int componentIndex = objVertex.attrIndex[nameIndex]; var componentList = data[componentName]; if (componentIndex >= 0 && componentIndex < componentList.Count) { vectorRow[i] = componentList[componentIndex]; } else { vectorRow[i] = null; } } else { vectorRow[i] = null; } } result.Add(vectorRow); } return(result); }
static bool VerifyVertex(Mesh mesh, ObjVertex vertex, ulong flag = 0) { if (flag == 0) { flag = mesh.vertexVaiidFlag; } if (vertex.GetValidFlag() != flag) { return(false); } int componentCount = mesh.attrCount; for (int i = 0; i < componentCount; i++) { if (vertex.attrIndex[i] >= mesh.data[mesh.attrNames[i]].Count) { return(false); } } return(true); }