public static void FindPositionForGroupAndAddToPlate(MeshGroup meshGroupToAdd, Matrix4X4 meshTransform, List <PlatingMeshGroupData> perMeshInfo, List <MeshGroup> meshesGroupsToAvoid, List <Matrix4X4> meshTransforms) { if (meshGroupToAdd == null || meshGroupToAdd.Meshes.Count < 1) { return; } // first find the bounds of what is already here. AxisAlignedBoundingBox allPlacedMeshBounds = GetAxisAlignedBoundingBox(meshesGroupsToAvoid[0], meshTransforms[0]); for (int i = 1; i < meshesGroupsToAvoid.Count; i++) { AxisAlignedBoundingBox nextMeshBounds = GetAxisAlignedBoundingBox(meshesGroupsToAvoid[i], meshTransforms[i]); allPlacedMeshBounds = AxisAlignedBoundingBox.Union(allPlacedMeshBounds, nextMeshBounds); } meshesGroupsToAvoid.Add(meshGroupToAdd); PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData(); perMeshInfo.Add(newMeshInfo); meshTransforms.Add(meshTransform); int meshGroupIndex = meshesGroupsToAvoid.Count - 1; // move the part to the total bounds lower left side MeshGroup meshGroup = meshesGroupsToAvoid[meshGroupIndex]; Vector3 meshLowerLeft = GetAxisAlignedBoundingBox(meshGroup, meshTransforms[meshGroupIndex]).minXYZ; meshTransforms[meshGroupIndex] *= Matrix4X4.CreateTranslation(-meshLowerLeft + allPlacedMeshBounds.minXYZ); MoveMeshGroupToOpenPosition(meshGroupIndex, perMeshInfo, meshesGroupsToAvoid, meshTransforms); PlaceMeshGroupOnBed(meshesGroupsToAvoid, meshTransforms, meshGroupIndex); }
public static void FindPositionForGroupAndAddToPlate(MeshGroup meshGroupToAdd, ScaleRotateTranslate meshTransform, List <PlatingMeshGroupData> perMeshInfo, List <MeshGroup> meshesGroupsToAvoid, List <ScaleRotateTranslate> meshTransforms) { if (meshGroupToAdd == null || meshGroupToAdd.Meshes.Count < 1) { return; } meshesGroupsToAvoid.Add(meshGroupToAdd); PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData(); perMeshInfo.Add(newMeshInfo); meshTransform.SetCenteringForMeshGroup(meshGroupToAdd); meshTransforms.Add(meshTransform); int meshGroupIndex = meshesGroupsToAvoid.Count - 1; MoveMeshGroupToOpenPosition(meshGroupIndex, perMeshInfo, meshesGroupsToAvoid, meshTransforms); PlaceMeshGroupOnBed(meshesGroupsToAvoid, meshTransforms, meshGroupIndex, false); }
public static void ArrangeMeshGroups(List <MeshGroup> asyncMeshGroups, List <ScaleRotateTranslate> asyncMeshGroupTransforms, List <PlatingMeshGroupData> asyncPlatingDatas, Action <double, string> reportProgressChanged) { // move them all out of the way for (int i = 0; i < asyncMeshGroups.Count; i++) { ScaleRotateTranslate translate = asyncMeshGroupTransforms[i]; translate.translation *= Matrix4X4.CreateTranslation(10000, 10000, 0); asyncMeshGroupTransforms[i] = translate; } // sort them by size for (int i = 0; i < asyncMeshGroups.Count; i++) { AxisAlignedBoundingBox iAABB = asyncMeshGroups[i].GetAxisAlignedBoundingBox(asyncMeshGroupTransforms[i].TotalTransform); for (int j = i + 1; j < asyncMeshGroups.Count; j++) { AxisAlignedBoundingBox jAABB = asyncMeshGroups[j].GetAxisAlignedBoundingBox(asyncMeshGroupTransforms[j].TotalTransform); if (Math.Max(iAABB.XSize, iAABB.YSize) < Math.Max(jAABB.XSize, jAABB.YSize)) { PlatingMeshGroupData tempData = asyncPlatingDatas[i]; asyncPlatingDatas[i] = asyncPlatingDatas[j]; asyncPlatingDatas[j] = tempData; MeshGroup tempMeshGroup = asyncMeshGroups[i]; asyncMeshGroups[i] = asyncMeshGroups[j]; asyncMeshGroups[j] = tempMeshGroup; ScaleRotateTranslate iTransform = asyncMeshGroupTransforms[i]; ScaleRotateTranslate jTransform = asyncMeshGroupTransforms[j]; Matrix4X4 tempTransform = iTransform.translation; iTransform.translation = jTransform.translation; jTransform.translation = tempTransform; asyncMeshGroupTransforms[i] = jTransform; asyncMeshGroupTransforms[j] = iTransform; iAABB = jAABB; } } } double ratioPerMeshGroup = 1.0 / asyncMeshGroups.Count; double currentRatioDone = 0; // put them onto the plate (try the center) starting with the biggest and moving down for (int meshGroupIndex = 0; meshGroupIndex < asyncMeshGroups.Count; meshGroupIndex++) { reportProgressChanged(currentRatioDone, "Calculating Positions...".Localize()); MeshGroup meshGroup = asyncMeshGroups[meshGroupIndex]; Vector3 meshLowerLeft = meshGroup.GetAxisAlignedBoundingBox(asyncMeshGroupTransforms[meshGroupIndex].TotalTransform).minXYZ; ScaleRotateTranslate atZero = asyncMeshGroupTransforms[meshGroupIndex]; atZero.translation *= Matrix4X4.CreateTranslation(-meshLowerLeft); asyncMeshGroupTransforms[meshGroupIndex] = atZero; PlatingHelper.MoveMeshGroupToOpenPosition(meshGroupIndex, asyncPlatingDatas, asyncMeshGroups, asyncMeshGroupTransforms); // and create the trace info so we can select it if (asyncPlatingDatas[meshGroupIndex].meshTraceableData.Count == 0) { PlatingHelper.CreateITraceableForMeshGroup(asyncPlatingDatas, asyncMeshGroups, meshGroupIndex, null); } currentRatioDone += ratioPerMeshGroup; // and put it on the bed PlatingHelper.PlaceMeshGroupOnBed(asyncMeshGroups, asyncMeshGroupTransforms, meshGroupIndex); } // and finally center whatever we have as a group { AxisAlignedBoundingBox bounds = asyncMeshGroups[0].GetAxisAlignedBoundingBox(asyncMeshGroupTransforms[0].TotalTransform); for (int i = 1; i < asyncMeshGroups.Count; i++) { bounds = AxisAlignedBoundingBox.Union(bounds, asyncMeshGroups[i].GetAxisAlignedBoundingBox(asyncMeshGroupTransforms[i].TotalTransform)); } Vector3 boundsCenter = (bounds.maxXYZ + bounds.minXYZ) / 2; for (int i = 0; i < asyncMeshGroups.Count; i++) { ScaleRotateTranslate translate = asyncMeshGroupTransforms[i]; translate.translation *= Matrix4X4.CreateTranslation(-boundsCenter + new Vector3(0, 0, bounds.ZSize / 2)); asyncMeshGroupTransforms[i] = translate; } } }
public static void FindPositionForGroupAndAddToPlate(MeshGroup meshGroupToAdd, ScaleRotateTranslate meshTransform, List<PlatingMeshGroupData> perMeshInfo, List<MeshGroup> meshesGroupsToAvoid, List<ScaleRotateTranslate> meshTransforms) { if (meshGroupToAdd == null || meshGroupToAdd.Meshes.Count < 1) { return; } // first find the bounds of what is already here. AxisAlignedBoundingBox allPlacedMeshBounds = GetAxisAlignedBoundingBox(meshesGroupsToAvoid[0], meshTransforms[0].TotalTransform); for (int i = 1; i < meshesGroupsToAvoid.Count; i++) { AxisAlignedBoundingBox nextMeshBounds = GetAxisAlignedBoundingBox(meshesGroupsToAvoid[i], meshTransforms[i].TotalTransform); allPlacedMeshBounds = AxisAlignedBoundingBox.Union(allPlacedMeshBounds, nextMeshBounds); } meshesGroupsToAvoid.Add(meshGroupToAdd); PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData(); perMeshInfo.Add(newMeshInfo); meshTransform.SetCenteringForMeshGroup(meshGroupToAdd); meshTransforms.Add(meshTransform); int meshGroupIndex = meshesGroupsToAvoid.Count - 1; // move the part to the total bounds lower left side MeshGroup meshGroup = meshesGroupsToAvoid[meshGroupIndex]; Vector3 meshLowerLeft = GetAxisAlignedBoundingBox(meshGroup, meshTransforms[meshGroupIndex].TotalTransform).minXYZ; ScaleRotateTranslate atLowerLeft = meshTransforms[meshGroupIndex]; atLowerLeft.translation *= Matrix4X4.CreateTranslation(-meshLowerLeft + allPlacedMeshBounds.minXYZ); meshTransforms[meshGroupIndex] = atLowerLeft; MoveMeshGroupToOpenPosition(meshGroupIndex, perMeshInfo, meshesGroupsToAvoid, meshTransforms); PlaceMeshGroupOnBed(meshesGroupsToAvoid, meshTransforms, meshGroupIndex); }