public Capstone(CsArch arch, CsMode mode) { var result = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>()); var err = CsNative.CsOpen(arch, mode, result); if (err != CsErr.CS_ERR_OK) { throw new CsException($"Failed to create native Capstone instance, error {err}.", err); } Handle = (IntPtr)Marshal.PtrToStructure(result, typeof(IntPtr)); }
public cSectionGCD() { csMode = CsMode.None; ready = false; sloxelResolution = Vector3.one * (float)InspectorT.slicerForm.ResUpDown.Value; increment = 1.0f / sloxelResolution.x; csPlaneEqn = new Vector4(0f, 1f, 0f, 0f); triangles.Clear(); layers.Clear(); layerHeights.Clear(); voxelHeights.Clear(); highlights.Clear(); foreach (var voxel in voxels) { MonoBehaviour.Destroy(voxel.Value.Voxel); } voxels.Clear(); topLayerHeight = -1000000; bottomLayerHeight = 1000000; tlhGrid = -1000000; blhGrid = 1000000; voxelHeight = 0; voxelLayers = 0; minLineSepSloxels = 1000000; maxLineSepSloxels = -1; minLineCountSloxels = 1000000; maxLineCountSloxels = -1; InspectorR.voxelsFitted = false; foreach (var l in LoadFile.gcdLines) { if (!layers.ContainsKey(l.p1.y)) { var newLayer = new CrossSectionLayer(l.p1.y); newLayer.Layer = layers.Count; layers.Add(l.p1.y, newLayer); layerHeights.Add(l.p1.y); if (l.p1.y < bottomLayerHeight) { bottomLayerHeight = l.p1.y; blhGrid = Mathf.Floor(bottomLayerHeight * sloxelResolution.x) * increment - increment / 2.0f; } if (l.p1.y > topLayerHeight) { topLayerHeight = l.p1.y; tlhGrid = Mathf.Ceil(topLayerHeight * sloxelResolution.x) * increment + increment / 2.0f; } } layers[l.p1.y].gcdLines.Add(l); } var modelHeight = topLayerHeight - bottomLayerHeight; var sloxelHeight = (modelHeight / layers.Count); var sloxelsPerVoxel = Mathf.RoundToInt(increment / sloxelHeight); voxelHeight = sloxelHeight * sloxelsPerVoxel;// layers.Count / sloxelsPerVoxel;// (topLayerHeight - bottomLayerHeight + increment) / sloxelsPerVoxel; for (float i = bottomLayerHeight - voxelHeight; i <= topLayerHeight + voxelHeight; i += voxelHeight) { if (!voxelHeights.Contains(i)) voxelHeights.Add(i); } var verts = new List<Vector3>(); foreach (var _v in MakeMesh.verts) { verts.Add(_v); } var count = (int)(verts.Count / 3); for (int i = 0; i < count; i++) { var newTriangle = new Triangle(); for (int j = 0; j <= 2; j++) { if (verts[3 * i + j].y > newTriangle.Max) newTriangle.Max = verts[3 * i + j].y; if (verts[3 * i + j].y < newTriangle.Min) newTriangle.Min = verts[3 * i + j].y; newTriangle.Points[j] = verts[3 * i + j]; newTriangle.Normal = MakeMesh.normals[3 * i + j]; } newTriangle.PlaneEquation = GetPlane(newTriangle.Points); triangles.Add(newTriangle); } foreach (var layer in layers) { csPlaneEqn.w = layer.Key; CrossSection(); } //var wt = new CheckWalls(); foreach (var layer in layers) { var min = layer.Value.Min; var max = layer.Value.Max; foreach (var line in layer.Value.border) { if (line.Endpoint0.x < min.x) min.x = line.Endpoint0.x; if (line.Endpoint1.x < min.x) min.x = line.Endpoint1.x; if (line.Endpoint0.x > max.x) max.x = line.Endpoint0.x; if (line.Endpoint1.x > max.x) max.x = line.Endpoint1.x; if (line.Endpoint0.z < min.z) min.z = line.Endpoint0.z; if (line.Endpoint1.z < min.z) min.z = line.Endpoint1.z; if (line.Endpoint0.z > max.z) max.z = line.Endpoint0.z; if (line.Endpoint1.z > max.z) max.z = line.Endpoint1.z; } layer.Value.Min = min; layer.Value.Max = max; } GetSloxels(); //getXLines(); //getZLines(); ready = true; if (InspectorT.slicerForm != null) InspectorT.slicerForm.LayerTrackbar.Maximum = cSectionGCD.layers.Count - 1; InspectorR.voxelsLoaded = true; InspectorT.slicerForm.panel1.Invalidate(); }
public static extern CsErr CsOpen(CsArch arch, CsMode mode, IntPtr engine);