public void LogMeshResults() { string info = ""; for (int i = 0; i < faceSets.Count; ++i) { FaceSet fs = faceSets[i]; if (fs != null) { bug("FACE AGGRTR: got a face set at: " + i); MeshSet ms = fs.CalculateGeometry(4f); int count = 0; foreach (Vector3 vv in ms.geometrySet.vertices) { info += "[" + vv.x + "," + vv.z + "]"; if (count % 4 == 3) { info += "\n"; } ++count; } bug(info); } else { bug("face set was null"); } } }
private void newFaceSetAtCoord(AlignedCoord coord, BlockType type, Direction dir, byte lightLevel, ILightDataProvider lightDataProvider) { //TODO: figure out what we should really to in this case. // maybe some kind of look up table re: which block type wins? int currentLookupIndex = indexOfFaceSetAtCoord(coord, dir); if (indexRepresentsAnOccupiedCoord(currentLookupIndex)) // { // remove // b.bug("represents an occupied coord: cur lookup index: " + currentLookupIndex + " direction: " + dir); FaceSet currentOccupantFaceSet = faceSets[currentLookupIndex]; currentOccupantFaceSet.removeFaceAtCoord(coord); // hang on to your hats! (no bugs please!) } // b.bug("adding a new face set at coord: " + coord.toString() ); int faceSetsCount = faceSets.Count; FaceSet fs = new FaceSet(type, dir, coord, lightLevel, lightDataProvider); faceSets.Add(fs); int nudge_lookup = ((int)dir % 2 == 0) ? 0 : 1; // pos dirs are 0, 2 and 4 faceSetTable[coord.across * 2 + nudge_lookup, coord.up] = faceSetsCount + FaceAggregator.FACETABLE_LOOKUP_SHIFT; }
private bool addCoordToFaceSetAtCoord(AlignedCoord addMeCoord, AlignedCoord adjacentCoord, BlockType type, Direction dir, byte lightLevel) { // if there is a face set here int faceSetIndex = indexOfFaceSetAtCoord(adjacentCoord, dir); if (indexRepresentsAnOccupiedCoord(faceSetIndex)) { FaceSet fset = faceSets[faceSetIndex]; // if it matches the type we want, add if (type == fset.blockType && fset.blockFaceDirection == dir) { //beyond limit for this face set? if (coordIsBeyondFaceSetMaxAllowArea(fset, addMeCoord)) { // b.bug("need a new faceset at coord: " + addMeCoord.toString() + "face set limits: " + fset.getFaceSetLimits().toString() + " direction: " + dir); return(false); } fset.addCoord(addMeCoord, lightLevel); //, adjacentCoord); copyFaceSetIndexFromToCoord(adjacentCoord, addMeCoord, dir); return(true); } } return(false); }
public void ShapeCell(Mesh m) { vertices = new VertexSet(); edges = new EdgeSet(); faces = new FaceSet(); copy(m); }
public void LogFaceSets() { for (int i = 0; i < faceSets.Count; ++i) { FaceSet fs = faceSets[i]; if (fs != null) { // bug("FACE AGGRTR: got a face set at: " + i); // fs.logStripsArray(); // bug (" quads: " + fs.getQuadsString()); } else { bug("face set was null"); } } }
/// <summary> /// Reads face sets. /// </summary> /// <param name="reader"> /// The reader. /// </param> /// <param name="chunkSize"> /// The chunk size. /// </param> /// <returns> /// A list of face sets. /// </returns> private List <FaceSet> ReadFaceSets(BinaryReader reader, int chunkSize) { int total = 6; var list = new List <FaceSet>(); while (total < chunkSize) { var id = this.ReadChunkId(reader); int size = this.ReadChunkSize(reader); total += size; switch (id) { case ChunkID.TRI_FACEMAT: { string name = this.ReadString(reader); int n = reader.ReadUInt16(); var c = new List <int>(); for (int i = 0; i < n; i++) { c.Add(reader.ReadUInt16()); } var fm = new FaceSet { Name = name, Faces = c }; list.Add(fm); break; } case ChunkID.TRI_SMOOTH: { this.ReadData(reader, size - 6); break; } default: { this.ReadData(reader, size - 6); break; } } } return(list); }
public void TestGetFaceSetsShouldReturnOnlyOneFaceSet() { HttpClient client = new HttpClient(); StringContent content = new StringContent("api_key=oxzC5V_7DvpM7uNQITr2ICdBKs1S1f2V&api_secret=IElJ3_FXpUrOxeFMYzcUziNLQq-WLX3W", System.Text.Encoding.UTF8, "application/x-www-form-urlencoded"); HttpResponseMessage response = Task.Run <HttpResponseMessage>(() => client.PostAsync("https://api.megvii.com/facepp/v3/faceset/getfacesets", content)).Result; Assert.IsTrue(response.IsSuccessStatusCode); DtoGetFaceSets result = JsonConvert.DeserializeObject <DtoGetFaceSets>(response.Content.ReadAsStringAsync().Result); Assert.AreEqual(1, result.facesets.Length); FaceSet f = result.facesets[0]; Assert.AreEqual("Face One", f.displayname); Assert.AreEqual("Face One", f.outer_id); }
private MeshSet newMeshSetByRemovingBlockAtCoordDONTCALL(AlignedCoord alco, float verticalHeight) { throw new Exception("don't call this anymore"); int pos_vert_count_before = 0; int neg_vert_count_before = 0; int pos_vert_count_after = 0; int neg_v_count_after = 0; int pos_change = 0; int neg_change = 0; MeshSet mset = MeshSet.emptyMeshSet(); FaceSet posFaceSet = faceSetAt(alco, direction(true)); if (posFaceSet != null) { pos_vert_count_before = posFaceSet.vertexCount(); posFaceSet.removeFaceAtCoord(alco); pos_vert_count_after = posFaceSet.vertexCount(); } FaceSet negFaceSet = faceSetAt(alco, direction(false)); if (negFaceSet != null) { neg_vert_count_before = negFaceSet.vertexCount(); negFaceSet.removeFaceAtCoord(alco); neg_v_count_after = negFaceSet.vertexCount(); } // rebuild the all facesets (instead, for now of trying to splice the verts/i/uv arrays) mset = getFaceGeometry(verticalHeight); pos_change = pos_vert_count_after - pos_vert_count_before; neg_change = neg_v_count_after - neg_vert_count_before; mset.deltaVertexCount = pos_change + neg_change; return(mset); }
/// <summary> /// Returns a list of arrays of 3 vertices, each representing a triangle in the mesh. /// Faces are taken from the first FaceSet in the mesh with the given flags, /// using None by default for the highest detail mesh. If not found, the first FaceSet is used. /// </summary> public List <FLVER.Vertex[]> GetFaces(FaceSet.FSFlags fsFlags = FaceSet.FSFlags.None) { if (FaceSets.Count == 0) { return(new List <FLVER.Vertex[]>()); } else { FaceSet faceSet = FaceSets.Find(fs => fs.Flags == fsFlags) ?? FaceSets[0]; List <int> indices = faceSet.Triangulate(Vertices.Count < ushort.MaxValue); var vertices = new List <FLVER.Vertex[]>(indices.Count); for (int i = 0; i < indices.Count - 2; i += 3) { int vi1 = indices[i]; int vi2 = indices[i + 1]; int vi3 = indices[i + 2]; vertices.Add(new FLVER.Vertex[] { Vertices[vi1], Vertices[vi2], Vertices[vi3] }); } return(vertices); } }
public List <MeshSet> getMeshResults() { List <MeshSet> result = new List <MeshSet>(); for (int i = 0; i < faceSets.Count; ++i) { FaceSet fs = faceSets[i]; if (fs != null) { b.bug("geom for faceSet: " + i); MeshSet mset = fs.CalculateGeometry(4f); result.Add(mset); faceSets[i] = fs; // need this? } else { bug("face set was null"); } } return(result); }
private void removeBlockFaceAtCoord(AlignedCoord alco, bool removePosFace, bool removeNegFace) { if (removePosFace) { FaceSet posFaceSet = faceSetAt(alco, direction(true)); if (posFaceSet != null) { posFaceSet.removeFaceAtCoord(alco); //now empty? if (posFaceSet.faceCount == 0) { removeFaceSetAtCoord(alco, direction(true)); } } else { throw new Exception("why? trying to remove a face set that was null already?"); } } if (removeNegFace) { FaceSet negFaceSet = faceSetAt(alco, direction(false)); if (negFaceSet != null) { negFaceSet.removeFaceAtCoord(alco); if (negFaceSet.faceCount == 0) { removeFaceSetAtCoord(alco, direction(false)); } } else { throw new Exception("why? trying to remove a face set that was null already?"); } } }
private static bool coordIsBeyondFaceSetMaxAllowArea(FaceSet fset, AlignedCoord alco) { Quad currentLimits = fset.getFaceSetLimits(); if (alco.across - currentLimits.origin.s >= FaceSet.MAX_DIMENSIONS.s) { return(true); } if (alco.up - currentLimits.origin.t >= FaceSet.MAX_DIMENSIONS.t) { return(true); } if (currentLimits.extentMinusOne().s - alco.across >= FaceSet.MAX_DIMENSIONS.s) { return(true); } if (currentLimits.extentMinusOne().t - alco.up >= FaceSet.MAX_DIMENSIONS.t) { return(true); } return(false); }
private void addToFaceSetsAt(int nextToRangeIndex, FaceInfo finfo) { Range1D addRange = finfo.range; Direction dir = finfo.direction; AssertUtil.Assert(nextToRangeIndex < this.faceSetTableHalfDims.s - 1, "need next to range to be in our table minus one column"); foreach (int faceSetIndex in faceSetsAtAcrossIndexFlushWithRange(nextToRangeIndex, addRange, dir)) { FaceSet nextToFS = faceSets[faceSetIndex]; if (nextToFS.canIncorporatePartOrAllOfRange(addRange, nextToRangeIndex + 1)) { Range1D usedRange = nextToFS.addRangeAtAcrossReturnAddedRange(addRange, nextToRangeIndex + 1); AssertUtil.Assert(usedRange.range > 0, "confusing used range was zero or less? (in face agg add fs w range)"); setIndicesOfFaceSetsAtRangeToIndex(usedRange, nextToRangeIndex + 1, dir, faceSetIndex + FaceAggregator.FACETABLE_LOOKUP_SHIFT); Range1D unusedRangeBelow = addRange.subRangeBelowRange(usedRange); if (!unusedRangeBelow.isErsatzNull()) { // addNewFaceSetsWith(nextToRangeIndex + 1, addRange, dir); addNewFaceSetsWith(nextToRangeIndex + 1, finfo); } Range1D unusedAbove = addRange.subRangeAboveRange(usedRange); if (!unusedAbove.isErsatzNull()) { finfo.range = unusedAbove; // addToFaceSetsAt(nextToRangeIndex, unusedAbove, dir); addToFaceSetsAt(nextToRangeIndex, finfo); } return; } } addNewFaceSetsWith(nextToRangeIndex + 1, finfo); }
private void addNewFaceSetsWith(int acrossI, FaceInfo finfo) { Range1D addRange = finfo.range; Direction dir = finfo.direction; AlignedCoord startAlco = new AlignedCoord(acrossI, addRange.start); int fsIndex = indexOfFaceSetAtCoord(startAlco, dir); if (!indexRepresentsAnOccupiedCoord(fsIndex)) { newFaceSetAtCoord(startAlco, addRange.blockType, dir, 0, finfo.lightDataProvider); } // newFaceSetAtCoord(startAlco, addRange.blockType, dir, addRange.bottom_light_level, finfo.lightDataProvider); FaceSet justAddedFS = faceSetAt(startAlco, dir); Range1D usedRange = justAddedFS.addRangeAtAcrossReturnAddedRange(addRange, acrossI); int nowOccupiedFS = unshiftedIndexOfFaceSetAtCoord(startAlco, dir); AssertUtil.Assert(nowOccupiedFS > -1, "wha negative occupied coord? " + nowOccupiedFS); setIndicesOfFaceSetsAtRangeToIndex(usedRange, acrossI, dir, nowOccupiedFS); AssertUtil.Assert(addRange.subRangeBelowRange(usedRange).isErsatzNull(), "we thought there would be no range below. whoops"); Range1D unusedRangeAbove = addRange.subRangeAboveRange(usedRange); if (!unusedRangeAbove.isErsatzNull()) { if (unusedRangeAbove.range > 0) { finfo.range = unusedRangeAbove; addNewFaceSetsWith(acrossI, finfo); } } }
/// <summary> /// Reads face sets. /// </summary> /// <param name="reader"> /// The reader. /// </param> /// <param name="chunkSize"> /// The chunk size. /// </param> /// <returns> /// A list of face sets. /// </returns> private List<FaceSet> ReadFaceSets(BinaryReader reader, int chunkSize) { int total = 6; var list = new List<FaceSet>(); while (total < chunkSize) { var id = this.ReadChunkId(reader); int size = this.ReadChunkSize(reader); total += size; switch (id) { case ChunkID.TRI_FACEMAT: { string name = this.ReadString(reader); int n = reader.ReadUInt16(); var c = new List<int>(); for (int i = 0; i < n; i++) { c.Add(reader.ReadUInt16()); } var fm = new FaceSet { Name = name, Faces = c }; list.Add(fm); break; } case ChunkID.TRI_SMOOTH: { this.ReadData(reader, size - 6); break; } default: { this.ReadData(reader, size - 6); break; } } } return list; }