public static void GenerateMeshes(MeshFilter _oldMeshF, MeshRenderer _oldMeshR, SliceData _dataPlane, bool _showDebug = false) { FindNewTriangles(_oldMeshF, ref _dataPlane, _showDebug); GenerateLeftMesh(_oldMeshF, _oldMeshR, _dataPlane); GenerateRightMesh(_oldMeshF, _oldMeshR, _dataPlane); GameObject.Destroy(_oldMeshF.gameObject); }
// Use this for initialization void Start() { data = new SliceData(); hasClicked = false; lastMousePos = Vector2.zero; lftBtn = 0; }
public PathGeometry makeIsecak(Point origin, double startAngle, double terminalAngle) { SliceData isecakPodaci = new SliceData(origin, startAngle, terminalAngle); double angle = terminalAngle - startAngle; double thetaInit = ConvertToRadians(startAngle); double thetaEnd = ConvertToRadians(terminalAngle); isecakPodaci.InitialSide = CreatePointFromAngle(thetaInit, origin); isecakPodaci.TerminalSide = CreatePointFromAngle(thetaEnd, origin); isecakPodaci.IsGreaterThan180 = (angle > 180); PathGeometry isecakGeometry = new PathGeometry(); isecakGeometry.Figures.Add(CreateIsecak(isecakPodaci)); return(isecakGeometry); }
private SliceData ReadSliceData() { var slice = new SliceData(); var count = ReadDWord(); var flags = (SliceFlags)ReadDWord(); ReadDWord(); // reserved slice.Name = ReadString(); for (var i = 0; i < count; i++) { slice.From = ReadDWord(); slice.X = ReadLong(); slice.Y = ReadLong(); slice.Width = ReadDWord(); // can be 0 if hidden slice.Height = ReadDWord(); // 9 slice... if (flags.HasFlag(SliceFlags.IsNinePatch)) { var cx = ReadLong(); var cy = ReadLong(); var cw = ReadDWord(); var ch = ReadDWord(); } // if (flags.HasFlag(SliceFlags.HasPivot)) { slice.PivotX = ReadLong(); slice.PivotY = ReadLong(); } } return(slice); }
private PathFigure CreateIsecak(SliceData isecakData) { SweepDirection sweepDirection; if (isecakData.StartAngle < 0 && isecakData.StartAngle > isecakData.TerminalAngle) { sweepDirection = SweepDirection.Counterclockwise; } else { sweepDirection = SweepDirection.Clockwise; } PathFigure isecak = new PathFigure(); Point origin = isecakData.Origin; isecak.StartPoint = origin; // Create initial side isecak.Segments.Add(new LineSegment(isecakData.InitialSide, true)); // Add arc Size size = new Size(origin.X, origin.X); isecak.Segments.Add( new ArcSegment( isecakData.TerminalSide, size, 0, isecakData.IsGreaterThan180, sweepDirection, true ) ); // Complete the terminal side line isecak.Segments.Add(new LineSegment(new Point(origin.X, origin.Y), true)); return(isecak); }
public static void GenerateRightMesh(MeshFilter _oldMeshF, MeshRenderer _oldMeshR, SliceData _dataPlane) { GameObject newMesh; CustomMesh mesh = new CustomMesh(out newMesh, "right Mesh", _oldMeshF.transform, _oldMeshR.material); int vertexID = 0; for (int faceID = 1; faceID < _dataPlane.Faces.Count; faceID += 2) { if (!_dataPlane.Faces.ContainsKey(faceID)) { continue; } foreach (Edge e in _dataPlane.Faces[faceID].Edges) { foreach (Vector3 p in _dataPlane.Faces[faceID].GetDistinctsPoints()) { Vector3 vertexPos = _oldMeshF.transform.InverseTransformPoint(p); mesh.vertices.Add(vertexPos); mesh.triangles.Add(vertexID); vertexID++; } } } /*Debug.Log("nb vertices " + mesh.vertices.Count); * Debug.Log("nb triangles " + mesh.triangles.Count);*/ mesh.Recalculate(); mesh.AssignToMesh(newMesh.GetComponent <MeshFilter>()); mesh.AssignToSharedMesh(newMesh.GetComponent <MeshCollider>()); }
public static void FindNewTriangles(MeshFilter _mf, ref SliceData _data, bool _showDebug) { CustomPlane secondPlane = new CustomPlane(); Vector3 pointOnSliceVec; Vector3 sliceDir; Vector3 finalPoint; for (int i = 0, FaceID = 0; i < _mf.mesh.triangles.Length; i += 3, FaceID += 2) { Vector3 V1 = _mf.transform.TransformPoint(_mf.mesh.vertices[_mf.mesh.triangles[i]]); Vector3 V2 = _mf.transform.TransformPoint(_mf.mesh.vertices[_mf.mesh.triangles[i + 1]]); Vector3 V3 = _mf.transform.TransformPoint(_mf.mesh.vertices[_mf.mesh.triangles[i + 2]]); if (_showDebug) { _data.AddNewSlVectorDebug(V1, Vector3.zero, Color.magenta, false, true); _data.AddNewSlVectorDebug(V2, Vector3.zero, Color.magenta, false, true); _data.AddNewSlVectorDebug(V3, Vector3.zero, Color.magenta, false, true); } secondPlane.Set3Points(V1, V2, V3); Face face1 = new Face(); Face face2 = new Face(); _data.AddFace(FaceID, face1); _data.AddFace(FaceID + 1, face2); Edge[] edges = { new Edge(V1, V2), new Edge(V2, V3), new Edge(V3, V1) }; if (!IntersectionPlanToPlan(out pointOnSliceVec, out sliceDir, _data.CtmPlane, secondPlane)) { foreach (Edge e in edges) { _data.AddEdge(FaceID, new Edge(e.Points[0])); } continue; } bool drawSlice = false; foreach (Edge e in edges) { if (IntersectionVectorToVector(out finalPoint, e.Points[0], e.Points[1], pointOnSliceVec, sliceDir)) { if (_showDebug) { drawSlice = true; _data.AddNewSlVectorDebug(finalPoint, Vector3.zero, Color.magenta, true, false); } _data.AddSeperateEdges(FaceID, e, finalPoint); } else { _data.AddEdge(FaceID, new Edge(e.Points[0])); } } if (drawSlice && _showDebug) { _data.AddNewSlVectorDebug(pointOnSliceVec, sliceDir, Color.green); } } if (_showDebug) { _data.CleanUnusedDebugIntersections(); } }
internal SliceDataResults QuerySliceData(string direction, string sliceType, SliceData aSlice, List <int> variableColumnsToCalculate, int sliceNum, float domainToQuery, bool weightByVol, bool weightByTonnes, int domainColumnID, bool weightByLength) { SliceDataResults sres = new SliceDataResults(); // pick out all records for the slice // get the variable columns int numCols = variableColumnsToCalculate.Count; sres.Initialise(numCols, sliceNum); Object[] cols = new Object[numCols]; for (int i = 0; i < numCols; i++) { cols[i] = columnData[variableColumnsToCalculate[i]]; } List <int> sliceRowIDs = aSlice.rowIDList; sres.sliceCentrePoint = aSlice.sliceCentre; for (int col = 0; col < numCols; col++) { DataColumn <float> varColumn = (DataColumn <float>)cols[col]; double tot = 0; double totVol = 0; double totVolAdjustedWt = 0; int dataRecords = 0; double tonnes = 0; foreach (int zz in sliceRowIDs) { int domain = 0; domain = GetDomainForRow(zz, domainColumnID); double ff = varColumn.GetRecordAt(zz); if (ff != columnNullVal && domain == domainToQuery) { float weighting = 1; if (weightByVol == true && weightByTonnes == false) { weighting = GetVolumeForRow(zz); } else if (weightByVol == true && weightByTonnes == true) { weighting = GetTonnesForRow(zz); } else { // no weighting for composites weighting = 1.0f; if (weightByLength) { GetWeightForRow(zz); } } tot += ff; dataRecords++; double vaw = weighting * ff; totVolAdjustedWt += vaw; totVol += weighting; if (weightByTonnes) { tonnes += GetTonnesForRow(zz); } // write the data to a datafile // string dtLine = ""; // dtLine = ff + ", " + weighting; // dtLine = GetDebugDataPrintout(zz) + ", Val, " + ff + " , Vol, " + weighting; // sw.WriteLine(dtLine); } } sres.wtAvg[col] = totVolAdjustedWt / totVol; sres.total[col] = tot; sres.ave[col] = tot / dataRecords; sres.totVolArr[col] = totVol; sres.totTonneArr[col] = tonnes; sres.dataRecordsUsed[col] = dataRecords; sres.maxCoord = aSlice.sliceMax; sres.minCoord = aSlice.sliceMin; sres.midCoord = aSlice.sliceCentre; } //sw.WriteLine("\nSummary: "); //sw.WriteLine("Ave, " + sres.ave[0]); //sw.WriteLine("wtAvg, " + sres.wtAvg[0]); //sw.WriteLine("Records, " + sres.dataRecordsUsed[0]); //sw.WriteLine("Tot volume, " + sres.totVolArr[0]); //sw.WriteLine("Tot tonnes, " + sres.totTonneArr[0]); // } return(sres); }
internal List <SliceData> SliceBy(int colNum, float sliceWidth, float startPosition, float endPosition, out string messages, BackgroundWorker workerProcessData, int startPerc, int endPerc, string statsusTagMessage) { List <SliceData> rowIDsBySlice = new List <SliceData>(); Object ob = columnData[colNum]; messages = ""; if (ob.GetType() == floatTypeColumn) { DataColumn <float> col = (DataColumn <float>)ob; int numSlices = 0; float currentPosition = startPosition; float estNumSlices = (endPosition - startPosition) / sliceWidth; int tot = (int)(col.ColumnCount() * estNumSlices); float scaleWidth = endPerc - startPerc; float topScale = scaleWidth / tot; int reportingInterval = 10; int reportCounter = 0; int pCount = 0; while (currentPosition <= endPosition) { reportCounter++; List <int> rowIDs = new List <int>(); int rowNum = 0; float halfWidth = sliceWidth / 2.0f; float limA = currentPosition; // (currentPosition - halfWidth); float limB = currentPosition + sliceWidth; //(currentPosition + halfWidth); messages += "Examining slice " + numSlices + " bewtween " + limA + " and " + limB + "\n"; foreach (float cv in col.GetDataList()) { pCount++; if (cv > limA && cv <= limB) { // match rowIDs.Add(rowNum); } rowNum++; } SliceData sd = new SliceData(); sd.sliceMin = limA; sd.sliceMax = limB; sd.sliceCentre = currentPosition; sd.rowIDList = rowIDs; rowIDsBySlice.Add(sd); currentPosition += sliceWidth; messages += "Slice " + numSlices + " has " + rowIDs.Count + " records\n"; if (reportCounter == reportingInterval) { float perc = (pCount * topScale) + startPerc; workerProcessData.ReportProgress((int)(perc), "Slice " + (numSlices) + " of " + estNumSlices); reportCounter = 0; } numSlices++; } messages += numSlices + " slices."; } return(rowIDsBySlice); }
private static IMap GenerateMap() { rock = Content.Load<Texture2D>("rock_single"); tile_green = Content.Load<Texture2D>("tile_green"); tile_brown = Content.Load<Texture2D>("tile_brown"); map = new Map(new Point(100, 100)); int width = 100; int length = 100; int threadCount = 2; // Environment.ProcessorCount int stepWidth = width / threadCount; int stepLength = length / threadCount; List<Thread> threads = new List<Thread>(); for (int i = 0; i < threadCount; i++) { threads.Add(new Thread(new ParameterizedThreadStart(GenerateMapSlice))); } List<SliceData> sliceDataList = new List<SliceData>(); for (int i = 0; i < threadCount; i++) { SliceData data = new SliceData(new List<Tile>(), new Rectangle(0, stepLength * i, width, stepLength)); threads[i].Start(data); sliceDataList.Add(data); } for (int i = 0; i < threadCount; i++) { threads[i].Join(); } foreach(SliceData data in sliceDataList) { foreach(Tile tile in data.TileList) { tile.MapIndex = map.AddTile(tile); } } // Clear thread list threads.Clear(); // Build adjacent tile arrays for (int i = 0; i < threadCount; i++) { threads.Add(new Thread(new ParameterizedThreadStart(PopulateAdjacentTiles))); } int range = map.TileCount / threadCount; for (int i = 0; i < threadCount; i++) { PopulateAdjacentTilesData Data = new PopulateAdjacentTilesData(map, i * range, range); threads[i].Start(Data); } for (int i = 0; i < threadCount; i++) { threads[i].Join(); } return map; }