private void AddCharacterMeshes(string currentText, TypeFacePrinter printer)
        {
            int            newIndex = asynchMeshGroups.Count;
            StyledTypeFace typeFace = printer.TypeFaceStyle;

            for (int i = 0; i < currentText.Length; i++)
            {
                string          letter        = currentText[i].ToString();
                TypeFacePrinter letterPrinter = new TypeFacePrinter(letter, typeFace);

                if (CharacterHasMesh(letterPrinter, letter))
                {
                    Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, unscaledLetterHeight / 2);

                    asynchMeshGroups.Add(new MeshGroup(textMesh));

                    PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData();

                    newMeshInfo.spacing = printer.GetOffsetLeftOfCharacterIndex(i);
                    asynchPlatingDatas.Add(newMeshInfo);
                    asynchMeshGroupTransforms.Add(ScaleRotateTranslate.Identity());

                    PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, newIndex, null);
                    ScaleRotateTranslate moved = asynchMeshGroupTransforms[newIndex];
                    moved.translation *= Matrix4X4.CreateTranslation(new Vector3(0, 0, unscaledLetterHeight / 2));
                    asynchMeshGroupTransforms[newIndex] = moved;

                    newIndex++;
                }

                processingProgressControl.PercentComplete = ((i + 1) * 95 / currentText.Length);
            }
        }
		private void createSelectionDataBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
		{
			string makingCopyLabel = LocalizedString.Get("Preparing Meshes");
			string makingCopyLabelFull = string.Format("{0}:", makingCopyLabel);
			processingProgressControl.ProcessType = makingCopyLabelFull;

			Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
			BackgroundWorker backgroundWorker = (BackgroundWorker)sender;

			PushMeshGroupDataToAsynchLists(TraceInfoOpperation.DONT_COPY);

			asynchPlatingDatas.Clear();
			double ratioPerMeshGroup = 1.0 / asynchMeshGroups.Count;
			double currentRatioDone = 0;
			for (int i = 0; i < asynchMeshGroups.Count; i++)
			{
				PlatingMeshGroupData newInfo = new PlatingMeshGroupData();
				asynchPlatingDatas.Add(newInfo);

				MeshGroup meshGroup = asynchMeshGroups[i];

				// create the selection info
				PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, i, (double progress0To1, string processingState, out bool continueProcessing) =>
				{
					BackgroundWorker_ProgressChanged(progress0To1, processingState, out continueProcessing);
				});

				currentRatioDone += ratioPerMeshGroup;
			}

			bool continueProcessing2;
			BackgroundWorker_ProgressChanged(1, "Creating GL Data", out continueProcessing2);
			meshViewerWidget.CreateGlDataForMeshes(asynchMeshGroups);
		}
Esempio n. 3
0
        private void insertTextBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            BackgroundWorker backgroundWorker = (BackgroundWorker)sender;

            asynchMeshGroups.Clear();
            asynchMeshGroupTransforms.Clear();
            asynchPlatingDatas.Clear();

            string          currentText  = (string)e.Argument;
            TypeFacePrinter printer      = new TypeFacePrinter(currentText, new StyledTypeFace(boldTypeFace, 12));
            Vector2         size         = printer.GetSize(currentText);
            double          centerOffset = -size.x / 2;

            double ratioPerMeshGroup = 1.0 / currentText.Length;
            double currentRatioDone  = 0;

            for (int i = 0; i < currentText.Length; i++)
            {
                int newIndex = asynchMeshGroups.Count;

                TypeFacePrinter letterPrinter = new TypeFacePrinter(currentText[i].ToString(), new StyledTypeFace(boldTypeFace, 12));
                Mesh            textMesh      = VertexSourceToMesh.Extrude(letterPrinter, 10 + (i % 2));

                if (textMesh.Faces.Count > 0)
                {
                    asynchMeshGroups.Add(new MeshGroup(textMesh));

                    PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData();

                    newMeshInfo.xSpacing = printer.GetOffsetLeftOfCharacterIndex(i).x + centerOffset;
                    asynchPlatingDatas.Add(newMeshInfo);
                    asynchMeshGroupTransforms.Add(ScaleRotateTranslate.Identity());

                    PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, newIndex, (double progress0To1, string processingState, out bool continueProcessing) =>
                    {
                        continueProcessing = true;
                        int nextPercent    = (int)((currentRatioDone + ratioPerMeshGroup * progress0To1) * 100);
                        backgroundWorker.ReportProgress(nextPercent);
                    });

                    currentRatioDone += ratioPerMeshGroup;

                    PlatingHelper.PlaceMeshGroupOnBed(asynchMeshGroups, asynchMeshGroupTransforms, newIndex);
                }

                backgroundWorker.ReportProgress((i + 1) * 95 / currentText.Length);
            }

            SetWordSpacing(asynchMeshGroups, asynchMeshGroupTransforms, asynchPlatingDatas);
            SetWordSize(asynchMeshGroups, asynchMeshGroupTransforms);
            SetWordHeight(asynchMeshGroups, asynchMeshGroupTransforms);

            if (createUnderline.Checked)
            {
                CreateUnderline(asynchMeshGroups, asynchMeshGroupTransforms, asynchPlatingDatas);
            }

            backgroundWorker.ReportProgress(95);
        }
        private void PushMeshGroupDataToAsynchLists(bool copyTraceInfo)
        {
            asynchMeshGroups.Clear();
            asynchMeshGroupTransforms.Clear();
            for (int meshGroupIndex = 0; meshGroupIndex < MeshGroups.Count; meshGroupIndex++)
            {
                MeshGroup meshGroup    = MeshGroups[meshGroupIndex];
                MeshGroup newMeshGroup = new MeshGroup();
                for (int meshIndex = 0; meshIndex < meshGroup.Meshes.Count; meshIndex++)
                {
                    Mesh mesh = meshGroup.Meshes[meshIndex];
                    newMeshGroup.Meshes.Add(Mesh.Copy(mesh));
                    asynchMeshGroupTransforms.Add(MeshGroupTransforms[meshGroupIndex]);
                }
                asynchMeshGroups.Add(newMeshGroup);
            }
            asynchPlatingDatas.Clear();

            for (int meshGroupIndex = 0; meshGroupIndex < MeshGroupExtraData.Count; meshGroupIndex++)
            {
                PlatingMeshGroupData meshData = new PlatingMeshGroupData();
                meshData.currentScale = MeshGroupExtraData[meshGroupIndex].currentScale;
                MeshGroup meshGroup = MeshGroups[meshGroupIndex];
                for (int meshIndex = 0; meshIndex < meshGroup.Meshes.Count; meshIndex++)
                {
                    if (copyTraceInfo)
                    {
                        meshData.meshTraceableData.AddRange(MeshGroupExtraData[meshGroupIndex].meshTraceableData);
                    }
                }
                asynchPlatingDatas.Add(meshData);
            }
        }
Esempio n. 5
0
		private void UngroupSelected()
		{
			if (SelectedMeshGroupIndex == -1)
			{
				SelectedMeshGroupIndex = 0;
			}
			string makingCopyLabel = LocalizedString.Get("Ungrouping");
			string makingCopyLabelFull = string.Format("{0}:", makingCopyLabel);
			processingProgressControl.ProcessType = makingCopyLabelFull;

			Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

			PushMeshGroupDataToAsynchLists(TraceInfoOpperation.DO_COPY);

			int indexBeingReplaced = SelectedMeshGroupIndex;
			List<Mesh> discreetMeshes = new List<Mesh>();
			asynchMeshGroups[indexBeingReplaced].Transform(asynchMeshGroupTransforms[indexBeingReplaced].TotalTransform);
			// if there are multiple meshes than just make them separate groups
			if (asynchMeshGroups[indexBeingReplaced].Meshes.Count > 1)
			{
				foreach (Mesh mesh in asynchMeshGroups[indexBeingReplaced].Meshes)
				{
					discreetMeshes.Add(mesh);
				}
			}
			else // actually try and cut up the mesh into separate parts
			{
				discreetMeshes = CreateDiscreteMeshes.SplitConnectedIntoMeshes(asynchMeshGroups[indexBeingReplaced], (double progress0To1, string processingState, out bool continueProcessing) =>
				{
					ReportProgressChanged(progress0To1 * .5, processingState, out continueProcessing);
				});
			}

			asynchMeshGroups.RemoveAt(indexBeingReplaced);
			asynchPlatingDatas.RemoveAt(indexBeingReplaced);
			asynchMeshGroupTransforms.RemoveAt(indexBeingReplaced);
			double ratioPerDiscreetMesh = 1.0 / discreetMeshes.Count;
			double currentRatioDone = 0;
			for (int discreetMeshIndex = 0; discreetMeshIndex < discreetMeshes.Count; discreetMeshIndex++)
			{
				PlatingMeshGroupData newInfo = new PlatingMeshGroupData();
				asynchPlatingDatas.Add(newInfo);
				asynchMeshGroups.Add(new MeshGroup(discreetMeshes[discreetMeshIndex]));
				int addedMeshIndex = asynchMeshGroups.Count - 1;
				MeshGroup addedMeshGroup = asynchMeshGroups[addedMeshIndex];

				ScaleRotateTranslate transform = ScaleRotateTranslate.Identity();
				transform.SetCenteringForMeshGroup(addedMeshGroup);
				asynchMeshGroupTransforms.Add(transform);

				//PlatingHelper.PlaceMeshGroupOnBed(asynchMeshGroups, asynchMeshGroupTransforms, addedMeshIndex, false);

				// and create selection info
				PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, addedMeshIndex, (double progress0To1, string processingState, out bool continueProcessing) =>
				{
					ReportProgressChanged(.5 + progress0To1 * .5 * currentRatioDone, processingState, out continueProcessing);
				});
				currentRatioDone += ratioPerDiscreetMesh;
			}
		}
		public DeleteUndoCommand(View3DWidget view3DWidget, int deletedIndex)
		{
			this.view3DWidget = view3DWidget;
			this.deletedIndex = deletedIndex;
			meshGroupThatWasDeleted = view3DWidget.MeshGroups[deletedIndex];
			deletedTransform = view3DWidget.MeshGroupTransforms[deletedIndex];
			deletedPlatingData = view3DWidget.MeshGroupExtraData[deletedIndex];
		}
Esempio n. 7
0
 public DeleteUndoCommand(View3DWidget view3DWidget, int deletedIndex)
 {
     this.view3DWidget       = view3DWidget;
     this.deletedIndex       = deletedIndex;
     meshGroupThatWasDeleted = view3DWidget.MeshGroups[deletedIndex];
     deletedTransform        = view3DWidget.MeshGroupTransforms[deletedIndex];
     deletedPlatingData      = view3DWidget.MeshGroupExtraData[deletedIndex];
 }
Esempio n. 8
0
 public CopyUndoCommand(View3DWidget view3DWidget, int newItemIndex)
 {
     this.view3DWidget       = view3DWidget;
     this.newItemIndex       = newItemIndex;
     meshGroupThatWasDeleted = view3DWidget.MeshGroups[newItemIndex];
     newItemTransform        = view3DWidget.MeshGroupTransforms[newItemIndex];
     newItemPlatingData      = view3DWidget.MeshGroupExtraData[newItemIndex];
 }
Esempio n. 9
0
		public CopyUndoCommand(View3DWidget view3DWidget, int newItemIndex)
		{
			this.view3DWidget = view3DWidget;
			this.newItemIndex = newItemIndex;
			meshGroupThatWasDeleted = view3DWidget.MeshGroups[newItemIndex];
			newItemTransform = view3DWidget.MeshGroupTransforms[newItemIndex];
			newItemPlatingData = view3DWidget.MeshGroupExtraData[newItemIndex];
		}
Esempio n. 10
0
        private void AddCharacterMeshes(string currentText, TypeFacePrinter printer)
        {
            int            newIndex = asyncMeshGroups.Count;
            StyledTypeFace typeFace = printer.TypeFaceStyle;

            for (int i = 0; i < currentText.Length; i++)
            {
                string          letter        = currentText[i].ToString();
                TypeFacePrinter letterPrinter = new TypeFacePrinter(letter, typeFace);

                if (CharacterHasMesh(letterPrinter, letter))
                {
#if true
                    Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, unscaledLetterHeight / 2);
#else
                    Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, unscaledLetterHeight / 2);
                    // this is the code to make rounded tops
                    // convert the letterPrinter to clipper polygons
                    List <List <IntPoint> > insetPoly = VertexSourceToPolygon.CreatePolygons(letterPrinter);
                    // inset them
                    ClipperOffset clipper = new ClipperOffset();
                    clipper.AddPaths(insetPoly, JoinType.jtMiter, EndType.etClosedPolygon);
                    List <List <IntPoint> > solution = new List <List <IntPoint> >();
                    clipper.Execute(solution, 5.0);
                    // convert them back into a vertex source
                    // merge both the inset and original vertex sources together
                    // convert the new vertex source into a mesh (trianglulate them)
                    // offset the inner loop in z
                    // create the polygons from the inner loop to a center point so that there is the rest of an approximation of the bubble
                    // make the mesh for the bottom
                    // add the top and bottom together
                    // done
#endif

                    asyncMeshGroups.Add(new MeshGroup(textMesh));

                    PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData();

                    newMeshInfo.spacing = printer.GetOffsetLeftOfCharacterIndex(i);
                    asyncPlatingDatas.Add(newMeshInfo);
                    asyncMeshGroupTransforms.Add(ScaleRotateTranslate.Identity());

                    PlatingHelper.CreateITraceableForMeshGroup(asyncPlatingDatas, asyncMeshGroups, newIndex, null);
                    ScaleRotateTranslate moved = asyncMeshGroupTransforms[newIndex];
                    moved.translation *= Matrix4X4.CreateTranslation(new Vector3(0, 0, unscaledLetterHeight / 2));
                    asyncMeshGroupTransforms[newIndex] = moved;

                    newIndex++;
                }

                processingProgressControl.PercentComplete = ((i + 1) * 95 / currentText.Length);
            }
        }
Esempio n. 11
0
        void ungroupSelectedBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string makingCopyLabel     = LocalizedString.Get("Ungrouping");
            string makingCopyLabelFull = string.Format("{0}:", makingCopyLabel);

            processingProgressControl.ProcessType = makingCopyLabelFull;

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            BackgroundWorker backgroundWorker = (BackgroundWorker)sender;

            PushMeshGroupDataToAsynchLists(TraceInfoOpperation.DO_COPY);

            int indexBeingReplaced = SelectedMeshGroupIndex;

            asynchMeshGroups[indexBeingReplaced].Transform(asynchMeshGroupTransforms[indexBeingReplaced].TotalTransform);
            List <Mesh> discreetMeshes = CreateDiscreteMeshes.SplitConnectedIntoMeshes(asynchMeshGroups[indexBeingReplaced], (double progress0To1, string processingState, out bool continueProcessing) =>
            {
                BackgroundWorker_ProgressChanged(progress0To1 * .5, processingState, out continueProcessing);
            });

            asynchMeshGroups.RemoveAt(indexBeingReplaced);
            asynchPlatingDatas.RemoveAt(indexBeingReplaced);
            asynchMeshGroupTransforms.RemoveAt(indexBeingReplaced);
            double ratioPerDiscreetMesh = 1.0 / discreetMeshes.Count;
            double currentRatioDone     = 0;

            for (int discreetMeshIndex = 0; discreetMeshIndex < discreetMeshes.Count; discreetMeshIndex++)
            {
                PlatingMeshGroupData newInfo = new PlatingMeshGroupData();
                asynchPlatingDatas.Add(newInfo);
                asynchMeshGroups.Add(new MeshGroup(discreetMeshes[discreetMeshIndex]));
                int       addedMeshIndex = asynchMeshGroups.Count - 1;
                MeshGroup addedMeshGroup = asynchMeshGroups[addedMeshIndex];

                ScaleRotateTranslate transform = ScaleRotateTranslate.Identity();
                transform.SetCenteringForMeshGroup(addedMeshGroup);
                asynchMeshGroupTransforms.Add(transform);

                //PlatingHelper.PlaceMeshGroupOnBed(asynchMeshGroups, asynchMeshGroupTransforms, addedMeshIndex, false);

                // and create selection info
                PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, addedMeshIndex, (double progress0To1, string processingState, out bool continueProcessing) =>
                {
                    BackgroundWorker_ProgressChanged(progress0To1 * .5 + .5, processingState, out continueProcessing);
                });
                currentRatioDone += ratioPerDiscreetMesh;
            }
        }
Esempio n. 12
0
        private void DoGroup(BackgroundWorker backgroundWorker)
        {
            if (SelectedMeshGroupIndex == -1)
            {
                SelectedMeshGroupIndex = 0;
            }
            MeshGroup meshGroupWeAreKeeping = asynchMeshGroups[SelectedMeshGroupIndex];

            for (int meshGroupToMoveIndex = asynchMeshGroups.Count - 1; meshGroupToMoveIndex >= 0; meshGroupToMoveIndex--)
            {
                MeshGroup meshGroupToMove = asynchMeshGroups[meshGroupToMoveIndex];
                if (meshGroupToMove != meshGroupWeAreKeeping)
                {
                    for (int moveIndex = 0; moveIndex < meshGroupToMove.Meshes.Count; moveIndex++)
                    {
                        Mesh mesh = meshGroupToMove.Meshes[moveIndex];
                        meshGroupWeAreKeeping.Meshes.Add(mesh);
                    }

                    asynchMeshGroups.RemoveAt(meshGroupToMoveIndex);
                    asynchMeshGroupTransforms.RemoveAt(meshGroupToMoveIndex);
                }
                else
                {
                    asynchMeshGroupTransforms[meshGroupToMoveIndex] = ScaleRotateTranslate.Identity();
                }
            }

            asynchPlatingDatas.Clear();
            double ratioPerMeshGroup = 1.0 / asynchMeshGroups.Count;
            double currentRatioDone  = 0;

            for (int i = 0; i < asynchMeshGroups.Count; i++)
            {
                PlatingMeshGroupData newInfo = new PlatingMeshGroupData();
                asynchPlatingDatas.Add(newInfo);

                MeshGroup meshGroup = asynchMeshGroups[i];

                // create the selection info
                PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, i, (double progress0To1, string processingState, out bool continueProcessing) =>
                {
                    ReportProgressChanged(progress0To1, processingState, out continueProcessing);
                });

                currentRatioDone += ratioPerMeshGroup;
            }
        }
Esempio n. 13
0
		private void DoGroup(BackgroundWorker backgroundWorker)
		{
			if (SelectedMeshGroupIndex == -1)
			{
				SelectedMeshGroupIndex = 0;
			}
			MeshGroup meshGroupWeAreKeeping = asynchMeshGroups[SelectedMeshGroupIndex];
			for (int meshGroupToMoveIndex = asynchMeshGroups.Count - 1; meshGroupToMoveIndex >= 0; meshGroupToMoveIndex--)
			{
				MeshGroup meshGroupToMove = asynchMeshGroups[meshGroupToMoveIndex];
				if (meshGroupToMove != meshGroupWeAreKeeping)
				{
					for (int moveIndex = 0; moveIndex < meshGroupToMove.Meshes.Count; moveIndex++)
					{
						Mesh mesh = meshGroupToMove.Meshes[moveIndex];
						meshGroupWeAreKeeping.Meshes.Add(mesh);
					}

					asynchMeshGroups.RemoveAt(meshGroupToMoveIndex);
					asynchMeshGroupTransforms.RemoveAt(meshGroupToMoveIndex);
				}
				else
				{
					asynchMeshGroupTransforms[meshGroupToMoveIndex] = ScaleRotateTranslate.Identity();
				}
			}

			asynchPlatingDatas.Clear();
			double ratioPerMeshGroup = 1.0 / asynchMeshGroups.Count;
			double currentRatioDone = 0;
			for (int i = 0; i < asynchMeshGroups.Count; i++)
			{
				PlatingMeshGroupData newInfo = new PlatingMeshGroupData();
				asynchPlatingDatas.Add(newInfo);

				MeshGroup meshGroup = asynchMeshGroups[i];

				// create the selection info
				PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, i, (double progress0To1, string processingState, out bool continueProcessing) =>
				{
					ReportProgressChanged(progress0To1, processingState, out continueProcessing);
				});

				currentRatioDone += ratioPerMeshGroup;
			}
		}
        void createSelectionDataBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string makingCopyLabel     = LocalizedString.Get("Preparing Meshes");
            string makingCopyLabelFull = string.Format("{0}:", makingCopyLabel);

            processingProgressControl.ProcessType = makingCopyLabelFull;

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            BackgroundWorker backgroundWorker = (BackgroundWorker)sender;

            PushMeshGroupDataToAsynchLists(TraceInfoOpperation.DONT_COPY);

            asynchPlatingDatas.Clear();
            double ratioPerMeshGroup = 1.0 / asynchMeshGroups.Count;
            double currentRatioDone  = 0;

            for (int i = 0; i < asynchMeshGroups.Count; i++)
            {
                PlatingMeshGroupData newInfo = new PlatingMeshGroupData();
                asynchPlatingDatas.Add(newInfo);

                MeshGroup meshGroup = asynchMeshGroups[i];

                // create the selection info
                PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, i, (double progress0To1, string processingState, out bool continueProcessing) =>
                {
                    BackgroundWorker_ProgressChanged(progress0To1, processingState, out continueProcessing);
                });

                currentRatioDone += ratioPerMeshGroup;
            }

            bool continueProcessing2;

            BackgroundWorker_ProgressChanged(1, "Creating GL Data", out continueProcessing2);
            meshViewerWidget.CreateGlDataForMeshes(asynchMeshGroups);
        }
Esempio n. 15
0
		private void PushMeshGroupDataToAsynchLists(TraceInfoOpperation traceInfoOpperation, ReportProgressRatio reportProgress = null)
		{
			UiThread.RunOnIdle(() =>
			{
				processingProgressControl.ProgressMessage = "Async Copy";
			});
			asynchMeshGroups.Clear();
			asynchMeshGroupTransforms.Clear();
			for (int meshGroupIndex = 0; meshGroupIndex < MeshGroups.Count; meshGroupIndex++)
			{
				MeshGroup meshGroup = MeshGroups[meshGroupIndex];
				MeshGroup newMeshGroup = new MeshGroup();
				for (int meshIndex = 0; meshIndex < meshGroup.Meshes.Count; meshIndex++)
				{
					Mesh mesh = meshGroup.Meshes[meshIndex];
					newMeshGroup.Meshes.Add(Mesh.Copy(mesh));
				}
				asynchMeshGroups.Add(newMeshGroup);
				asynchMeshGroupTransforms.Add(MeshGroupTransforms[meshGroupIndex]);
			}
			asynchPlatingDatas.Clear();

			for (int meshGroupIndex = 0; meshGroupIndex < MeshGroupExtraData.Count; meshGroupIndex++)
			{
				PlatingMeshGroupData meshData = new PlatingMeshGroupData();
				meshData.currentScale = MeshGroupExtraData[meshGroupIndex].currentScale;
				MeshGroup meshGroup = MeshGroups[meshGroupIndex];

				if (traceInfoOpperation == TraceInfoOpperation.DO_COPY)
				{
					meshData.meshTraceableData.AddRange(MeshGroupExtraData[meshGroupIndex].meshTraceableData);
				}

				asynchPlatingDatas.Add(meshData);
			}
			UiThread.RunOnIdle(() =>
			{
				processingProgressControl.ProgressMessage = "";
			});
		}
		private void AddCharacterMeshes(string currentText, TypeFacePrinter printer)
		{
			int newIndex = asynchMeshGroups.Count;
			StyledTypeFace typeFace = printer.TypeFaceStyle;

			for (int i = 0; i < currentText.Length; i++)
			{
				string letter = currentText[i].ToString();
				TypeFacePrinter letterPrinter = new TypeFacePrinter(letter, typeFace);

				if (CharacterHasMesh(letterPrinter, letter))
				{
					Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, unscaledLetterHeight / 2);

					asynchMeshGroups.Add(new MeshGroup(textMesh));

					PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData();

					newMeshInfo.spacing = printer.GetOffsetLeftOfCharacterIndex(i);
					asynchPlatingDatas.Add(newMeshInfo);
					asynchMeshGroupTransforms.Add(ScaleRotateTranslate.Identity());

					PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, newIndex, null);
					ScaleRotateTranslate moved = asynchMeshGroupTransforms[newIndex];
					moved.translation *= Matrix4X4.CreateTranslation(new Vector3(0, 0, unscaledLetterHeight / 2));
					asynchMeshGroupTransforms[newIndex] = moved;

					newIndex++;
				}

				processingProgressControl.PercentComplete = ((i + 1) * 95 / currentText.Length);
			}
		}
Esempio n. 17
0
        private void AlignSelected()
        {
            if (SelectedMeshGroupIndex == -1)
            {
                SelectedMeshGroupIndex = 0;
            }
            // make sure our thread traslates numbmers correctly (always do this in a thread)
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            // save our data so we don't mess up the display while doing work
            PushMeshGroupDataToAsynchLists(TraceInfoOpperation.DO_COPY);

            // try to move all the not selected meshes relative to the selected mesh
            AxisAlignedBoundingBox selectedOriginalBounds = asyncMeshGroups[SelectedMeshGroupIndex].GetAxisAlignedBoundingBox();
            Vector3 selectedOriginalCenter = selectedOriginalBounds.Center;
            AxisAlignedBoundingBox selectedCurrentBounds = asyncMeshGroups[SelectedMeshGroupIndex].GetAxisAlignedBoundingBox(asyncMeshGroupTransforms[SelectedMeshGroupIndex].TotalTransform);
            Vector3 selctedCurrentCenter = selectedCurrentBounds.Center;

            for (int meshGroupToMoveIndex = 0; meshGroupToMoveIndex < asyncMeshGroups.Count; meshGroupToMoveIndex++)
            {
                MeshGroup meshGroupToMove = asyncMeshGroups[meshGroupToMoveIndex];
                if (meshGroupToMove != asyncMeshGroups[SelectedMeshGroupIndex])
                {
                    AxisAlignedBoundingBox groupToMoveOriginalBounds = meshGroupToMove.GetAxisAlignedBoundingBox();
                    Vector3 groupToMoveOriginalCenter        = groupToMoveOriginalBounds.Center;
                    AxisAlignedBoundingBox groupToMoveBounds = meshGroupToMove.GetAxisAlignedBoundingBox(asyncMeshGroupTransforms[meshGroupToMoveIndex].TotalTransform);
                    Vector3 groupToMoveCenter = groupToMoveBounds.Center;

                    Vector3 originalCoordinatesDelta = groupToMoveOriginalCenter - selectedOriginalCenter;
                    Vector3 currentCoordinatesDelta  = groupToMoveCenter - selctedCurrentCenter;

                    Vector3 deltaRequired = originalCoordinatesDelta - currentCoordinatesDelta;

                    if (deltaRequired.Length > .0001)
                    {
                        ScaleRotateTranslate translated = asyncMeshGroupTransforms[meshGroupToMoveIndex];
                        translated.translation *= Matrix4X4.CreateTranslation(deltaRequired);
                        asyncMeshGroupTransforms[meshGroupToMoveIndex] = translated;
                        PartHasBeenChanged();
                    }
                }
            }

            // now put all the meshes into just one group
            MeshGroup meshGroupWeAreKeeping = asyncMeshGroups[SelectedMeshGroupIndex];

            for (int meshGroupToMoveIndex = asyncMeshGroups.Count - 1; meshGroupToMoveIndex >= 0; meshGroupToMoveIndex--)
            {
                MeshGroup meshGroupToMove = asyncMeshGroups[meshGroupToMoveIndex];
                if (meshGroupToMove != meshGroupWeAreKeeping)
                {
                    // move all the meshes into the new aligned mesh group
                    for (int moveIndex = 0; moveIndex < meshGroupToMove.Meshes.Count; moveIndex++)
                    {
                        Mesh mesh = meshGroupToMove.Meshes[moveIndex];
                        meshGroupWeAreKeeping.Meshes.Add(mesh);
                    }

                    asyncMeshGroups.RemoveAt(meshGroupToMoveIndex);
                    asyncMeshGroupTransforms.RemoveAt(meshGroupToMoveIndex);
                }
            }

            asyncPlatingDatas.Clear();
            double ratioPerMeshGroup = 1.0 / asyncMeshGroups.Count;
            double currentRatioDone  = 0;

            for (int i = 0; i < asyncMeshGroups.Count; i++)
            {
                PlatingMeshGroupData newInfo = new PlatingMeshGroupData();
                asyncPlatingDatas.Add(newInfo);

                MeshGroup meshGroup = asyncMeshGroups[i];

                // create the selection info
                PlatingHelper.CreateITraceableForMeshGroup(asyncPlatingDatas, asyncMeshGroups, i, (double progress0To1, string processingState, out bool continueProcessing) =>
                {
                    ReportProgressChanged(progress0To1, processingState, out continueProcessing);
                });

                currentRatioDone += ratioPerMeshGroup;
            }
        }
Esempio n. 18
0
        private void GroupSelected()
        {
            string makingCopyLabel     = "Grouping".Localize();
            string makingCopyLabelFull = string.Format("{0}:", makingCopyLabel);

            processingProgressControl.ProcessType = makingCopyLabelFull;

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            PushMeshGroupDataToAsynchLists(TraceInfoOpperation.DO_COPY);

            for (int i = 0; i < asyncMeshGroups.Count; i++)
            {
                asyncMeshGroups[i].Transform(asyncMeshGroupTransforms[i]);

                bool continueProcessing;
                ReportProgressChanged((i + 1) * .4 / asyncMeshGroups.Count, "", out continueProcessing);
            }

            if (SelectedMeshGroupIndex == -1)
            {
                SelectedMeshGroupIndex = 0;
            }

            MeshGroup meshGroupWeAreKeeping = asyncMeshGroups[SelectedMeshGroupIndex];

            for (int meshGroupToMoveIndex = asyncMeshGroups.Count - 1; meshGroupToMoveIndex >= 0; meshGroupToMoveIndex--)
            {
                MeshGroup meshGroupToMove = asyncMeshGroups[meshGroupToMoveIndex];
                if (meshGroupToMove != meshGroupWeAreKeeping)
                {
                    for (int moveIndex = 0; moveIndex < meshGroupToMove.Meshes.Count; moveIndex++)
                    {
                        Mesh mesh = meshGroupToMove.Meshes[moveIndex];
                        meshGroupWeAreKeeping.Meshes.Add(mesh);
                    }

                    asyncMeshGroups.RemoveAt(meshGroupToMoveIndex);
                    asyncMeshGroupTransforms.RemoveAt(meshGroupToMoveIndex);
                }
                else
                {
                    asyncMeshGroupTransforms[meshGroupToMoveIndex] = Matrix4X4.Identity;
                }
            }

            asyncPlatingDatas.Clear();
            double ratioPerMeshGroup = 1.0 / asyncMeshGroups.Count;
            double currentRatioDone  = 0;

            for (int i = 0; i < asyncMeshGroups.Count; i++)
            {
                PlatingMeshGroupData newInfo = new PlatingMeshGroupData();
                asyncPlatingDatas.Add(newInfo);

                MeshGroup meshGroup = asyncMeshGroups[i];

                // create the selection info
                PlatingHelper.CreateITraceableForMeshGroup(asyncPlatingDatas, asyncMeshGroups, i, (double progress0To1, string processingState, out bool continueProcessing) =>
                {
                    ReportProgressChanged(progress0To1, processingState, out continueProcessing);
                });

                currentRatioDone += ratioPerMeshGroup;
            }
        }
Esempio n. 19
0
        private void arrangeMeshGroupsBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            PushMeshGroupDataToAsynchLists(TraceInfoOpperation.DONT_COPY);

            BackgroundWorker backgroundWorker = (BackgroundWorker)sender;

            // move them all out of the way
            for (int i = 0; i < asynchMeshGroups.Count; i++)
            {
                ScaleRotateTranslate translate = asynchMeshGroupTransforms[i];
                translate.translation       *= Matrix4X4.CreateTranslation(10000, 10000, 0);
                asynchMeshGroupTransforms[i] = translate;
            }

            // sort them by size
            for (int i = 0; i < asynchMeshGroups.Count; i++)
            {
                AxisAlignedBoundingBox iAABB = asynchMeshGroups[i].GetAxisAlignedBoundingBox(asynchMeshGroupTransforms[i].TotalTransform);
                for (int j = i + 1; j < asynchMeshGroups.Count; j++)
                {
                    AxisAlignedBoundingBox jAABB = asynchMeshGroups[j].GetAxisAlignedBoundingBox(asynchMeshGroupTransforms[j].TotalTransform);
                    if (Math.Max(iAABB.XSize, iAABB.YSize) < Math.Max(jAABB.XSize, jAABB.YSize))
                    {
                        PlatingMeshGroupData tempData = asynchPlatingDatas[i];
                        asynchPlatingDatas[i] = asynchPlatingDatas[j];
                        asynchPlatingDatas[j] = tempData;

                        MeshGroup tempMeshGroup = asynchMeshGroups[i];
                        asynchMeshGroups[i] = asynchMeshGroups[j];
                        asynchMeshGroups[j] = tempMeshGroup;

                        ScaleRotateTranslate iTransform    = asynchMeshGroupTransforms[i];
                        ScaleRotateTranslate jTransform    = asynchMeshGroupTransforms[j];
                        Matrix4X4            tempTransform = iTransform.translation;
                        iTransform.translation = jTransform.translation;
                        jTransform.translation = tempTransform;

                        asynchMeshGroupTransforms[i] = jTransform;
                        asynchMeshGroupTransforms[j] = iTransform;

                        iAABB = jAABB;
                    }
                }
            }

            double ratioPerMeshGroup = 1.0 / asynchMeshGroups.Count;
            double currentRatioDone  = 0;

            // put them onto the plate (try the center) starting with the biggest and moving down
            for (int meshGroupIndex = 0; meshGroupIndex < asynchMeshGroups.Count; meshGroupIndex++)
            {
                bool continueProcessing2 = true;
                ReportProgressChanged(currentRatioDone, "Calculating Positions...".Localize(), out continueProcessing2);

                MeshGroup            meshGroup     = asynchMeshGroups[meshGroupIndex];
                Vector3              meshLowerLeft = meshGroup.GetAxisAlignedBoundingBox(asynchMeshGroupTransforms[meshGroupIndex].TotalTransform).minXYZ;
                ScaleRotateTranslate atZero        = asynchMeshGroupTransforms[meshGroupIndex];
                atZero.translation *= Matrix4X4.CreateTranslation(-meshLowerLeft);
                asynchMeshGroupTransforms[meshGroupIndex] = atZero;

                PlatingHelper.MoveMeshGroupToOpenPosition(meshGroupIndex, asynchPlatingDatas, asynchMeshGroups, asynchMeshGroupTransforms);

                // and create the trace info so we can select it
                if (asynchPlatingDatas[meshGroupIndex].meshTraceableData.Count == 0)
                {
                    PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, meshGroupIndex, null);
                }

                currentRatioDone += ratioPerMeshGroup;

                // and put it on the bed
                PlatingHelper.PlaceMeshGroupOnBed(asynchMeshGroups, asynchMeshGroupTransforms, meshGroupIndex);
            }

            // and finally center whatever we have as a group
            {
                AxisAlignedBoundingBox bounds = asynchMeshGroups[0].GetAxisAlignedBoundingBox(asynchMeshGroupTransforms[0].TotalTransform);
                for (int i = 1; i < asynchMeshGroups.Count; i++)
                {
                    bounds = AxisAlignedBoundingBox.Union(bounds, asynchMeshGroups[i].GetAxisAlignedBoundingBox(asynchMeshGroupTransforms[i].TotalTransform));
                }

                Vector3 boundsCenter = (bounds.maxXYZ + bounds.minXYZ) / 2;
                for (int i = 0; i < asynchMeshGroups.Count; i++)
                {
                    ScaleRotateTranslate translate = asynchMeshGroupTransforms[i];
                    translate.translation       *= Matrix4X4.CreateTranslation(-boundsCenter + new Vector3(0, 0, bounds.ZSize / 2));
                    asynchMeshGroupTransforms[i] = translate;
                }
            }
        }
Esempio n. 20
0
        private void UngroupSelected()
        {
            if (SelectedMeshGroupIndex == -1)
            {
                SelectedMeshGroupIndex = 0;
            }
            string makingCopyLabel     = LocalizedString.Get("Ungrouping");
            string makingCopyLabelFull = string.Format("{0}:", makingCopyLabel);

            processingProgressControl.ProcessType = makingCopyLabelFull;

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            PushMeshGroupDataToAsynchLists(TraceInfoOpperation.DO_COPY);

            int         indexBeingReplaced = SelectedMeshGroupIndex;
            List <Mesh> discreetMeshes     = new List <Mesh>();

            asyncMeshGroups[indexBeingReplaced].Transform(asyncMeshGroupTransforms[indexBeingReplaced]);
            // if there are multiple meshes than just make them separate groups
            if (asyncMeshGroups[indexBeingReplaced].Meshes.Count > 1)
            {
                foreach (Mesh mesh in asyncMeshGroups[indexBeingReplaced].Meshes)
                {
                    discreetMeshes.Add(mesh);
                }
            }
            else             // actually try and cut up the mesh into separate parts
            {
                discreetMeshes = CreateDiscreteMeshes.SplitConnectedIntoMeshes(asyncMeshGroups[indexBeingReplaced], (double progress0To1, string processingState, out bool continueProcessing) =>
                {
                    ReportProgressChanged(progress0To1 * .5, processingState, out continueProcessing);
                });
            }

            asyncMeshGroups.RemoveAt(indexBeingReplaced);
            asyncPlatingDatas.RemoveAt(indexBeingReplaced);
            asyncMeshGroupTransforms.RemoveAt(indexBeingReplaced);
            double ratioPerDiscreetMesh = 1.0 / discreetMeshes.Count;
            double currentRatioDone     = 0;

            for (int discreetMeshIndex = 0; discreetMeshIndex < discreetMeshes.Count; discreetMeshIndex++)
            {
                PlatingMeshGroupData newInfo = new PlatingMeshGroupData();
                asyncPlatingDatas.Add(newInfo);
                asyncMeshGroups.Add(new MeshGroup(discreetMeshes[discreetMeshIndex]));
                int       addedMeshIndex = asyncMeshGroups.Count - 1;
                MeshGroup addedMeshGroup = asyncMeshGroups[addedMeshIndex];

                Matrix4X4 transform = Matrix4X4.Identity;
                asyncMeshGroupTransforms.Add(transform);

                //PlatingHelper.PlaceMeshGroupOnBed(asyncMeshGroups, asyncMeshGroupTransforms, addedMeshIndex, false);

                // and create selection info
                PlatingHelper.CreateITraceableForMeshGroup(asyncPlatingDatas, asyncMeshGroups, addedMeshIndex, (double progress0To1, string processingState, out bool continueProcessing) =>
                {
                    ReportProgressChanged(.5 + progress0To1 * .5 * currentRatioDone, processingState, out continueProcessing);
                });
                currentRatioDone += ratioPerDiscreetMesh;
            }
        }
		private void AddCharacterMeshes(string currentText, TypeFacePrinter printer)
		{
			int newIndex = asyncMeshGroups.Count;
			StyledTypeFace typeFace = printer.TypeFaceStyle;

			for (int i = 0; i < currentText.Length; i++)
			{
				string letter = currentText[i].ToString();
				TypeFacePrinter letterPrinter = new TypeFacePrinter(letter, typeFace);

				if (CharacterHasMesh(letterPrinter, letter))
				{
#if true
					Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, unscaledLetterHeight / 2);
#else
					Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, unscaledLetterHeight / 2);
					// this is the code to make rounded tops
					// convert the letterPrinter to clipper polygons
					List<List<IntPoint>> insetPoly = VertexSourceToPolygon.CreatePolygons(letterPrinter);
					// inset them
					ClipperOffset clipper = new ClipperOffset();
					clipper.AddPaths(insetPoly, JoinType.jtMiter, EndType.etClosedPolygon);
					List<List<IntPoint>> solution = new List<List<IntPoint>>();
					clipper.Execute(solution, 5.0);
					// convert them back into a vertex source
					// merge both the inset and original vertex sources together
					// convert the new vertex source into a mesh (triangulate them)
					// offset the inner loop in z
					// create the polygons from the inner loop to a center point so that there is the rest of an approximation of the bubble
					// make the mesh for the bottom 
					// add the top and bottom together
					// done
#endif

					asyncMeshGroups.Add(new MeshGroup(textMesh));

					PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData();

					newMeshInfo.spacing = printer.GetOffsetLeftOfCharacterIndex(i);
					asyncPlatingDatas.Add(newMeshInfo);
					asyncMeshGroupTransforms.Add(Matrix4X4.Identity);

					PlatingHelper.CreateITraceableForMeshGroup(asyncPlatingDatas, asyncMeshGroups, newIndex, null);
					asyncMeshGroupTransforms[newIndex] *= Matrix4X4.CreateTranslation(new Vector3(0, 0, unscaledLetterHeight / 2));

					newIndex++;
				}

				processingProgressControl.PercentComplete = ((i + 1) * 95 / currentText.Length);
			}
		}
		private void PushMeshGroupDataToAsynchLists(bool copyTraceInfo)
		{
			asynchMeshGroups.Clear();
			asynchMeshGroupTransforms.Clear();
			for (int meshGroupIndex = 0; meshGroupIndex < MeshGroups.Count; meshGroupIndex++)
			{
				MeshGroup meshGroup = MeshGroups[meshGroupIndex];
				MeshGroup newMeshGroup = new MeshGroup();
				for (int meshIndex = 0; meshIndex < meshGroup.Meshes.Count; meshIndex++)
				{
					Mesh mesh = meshGroup.Meshes[meshIndex];
					newMeshGroup.Meshes.Add(Mesh.Copy(mesh));
					asynchMeshGroupTransforms.Add(MeshGroupTransforms[meshGroupIndex]);
				}
				asynchMeshGroups.Add(newMeshGroup);
			}
			asynchPlatingDatas.Clear();

			for (int meshGroupIndex = 0; meshGroupIndex < MeshGroupExtraData.Count; meshGroupIndex++)
			{
				PlatingMeshGroupData meshData = new PlatingMeshGroupData();
				meshData.currentScale = MeshGroupExtraData[meshGroupIndex].currentScale;
				MeshGroup meshGroup = MeshGroups[meshGroupIndex];
				for (int meshIndex = 0; meshIndex < meshGroup.Meshes.Count; meshIndex++)
				{
					if (copyTraceInfo)
					{
						meshData.meshTraceableData.AddRange(MeshGroupExtraData[meshGroupIndex].meshTraceableData);
					}
				}
				asynchPlatingDatas.Add(meshData);
			}
		}
		private void insertTextBackgroundWorker_DoWork(string currentText)
		{
			Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

			asynchMeshGroups.Clear();
			asynchMeshGroupTransforms.Clear();
			asynchPlatingDatas.Clear();

			TypeFacePrinter printer = new TypeFacePrinter(currentText, new StyledTypeFace(boldTypeFace, 12));
			Vector2 size = printer.GetSize(currentText);
			double centerOffset = -size.x / 2;

			double ratioPerMeshGroup = 1.0 / currentText.Length;
			double currentRatioDone = 0;
			for (int i = 0; i < currentText.Length; i++)
			{
				int newIndex = asynchMeshGroups.Count;

				TypeFacePrinter letterPrinter = new TypeFacePrinter(currentText[i].ToString(), new StyledTypeFace(boldTypeFace, 12));
				Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, 10 + (i % 2));

				if (textMesh.Faces.Count > 0)
				{
					asynchMeshGroups.Add(new MeshGroup(textMesh));

					PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData();

					newMeshInfo.xSpacing = printer.GetOffsetLeftOfCharacterIndex(i).x + centerOffset;
					asynchPlatingDatas.Add(newMeshInfo);
					asynchMeshGroupTransforms.Add(ScaleRotateTranslate.Identity());

					PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, newIndex, (double progress0To1, string processingState, out bool continueProcessing) =>
					{
						continueProcessing = true;
						int nextPercent = (int)((currentRatioDone + ratioPerMeshGroup * progress0To1) * 100);
						processingProgressControl.PercentComplete = nextPercent;
					});

					currentRatioDone += ratioPerMeshGroup;

					PlatingHelper.PlaceMeshGroupOnBed(asynchMeshGroups, asynchMeshGroupTransforms, newIndex);
				}

				processingProgressControl.PercentComplete = ((i + 1) * 95 / currentText.Length);
			}

			SetWordSpacing(asynchMeshGroups, asynchMeshGroupTransforms, asynchPlatingDatas);
			SetWordSize(asynchMeshGroups, asynchMeshGroupTransforms);
			SetWordHeight(asynchMeshGroups, asynchMeshGroupTransforms);

			if (createUnderline.Checked)
			{
				CreateUnderline(asynchMeshGroups, asynchMeshGroupTransforms, asynchPlatingDatas);
			}

			processingProgressControl.PercentComplete = 95;
		}
Esempio n. 24
0
		private void alignSelectedBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
		{
			if (SelectedMeshGroupIndex == -1)
			{
				SelectedMeshGroupIndex = 0;
			}
			// make sure our thread traslates numbmers correctly (always do this in a thread)
			Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
			BackgroundWorker backgroundWorker = (BackgroundWorker)sender;

			// save our data so we don't mess up the display while doing work
			PushMeshGroupDataToAsynchLists(TraceInfoOpperation.DO_COPY);

			// try to move all the not selected meshes relative to the selected mesh
			AxisAlignedBoundingBox selectedOriginalBounds = asynchMeshGroups[SelectedMeshGroupIndex].GetAxisAlignedBoundingBox();
			Vector3 selectedOriginalCenter = selectedOriginalBounds.Center;
			AxisAlignedBoundingBox selectedCurrentBounds = asynchMeshGroups[SelectedMeshGroupIndex].GetAxisAlignedBoundingBox(asynchMeshGroupTransforms[SelectedMeshGroupIndex].TotalTransform);
			Vector3 selctedCurrentCenter = selectedCurrentBounds.Center;
			for (int meshGroupToMoveIndex = 0; meshGroupToMoveIndex < asynchMeshGroups.Count; meshGroupToMoveIndex++)
			{
				MeshGroup meshGroupToMove = asynchMeshGroups[meshGroupToMoveIndex];
				if (meshGroupToMove != asynchMeshGroups[SelectedMeshGroupIndex])
				{
					AxisAlignedBoundingBox groupToMoveOriginalBounds = meshGroupToMove.GetAxisAlignedBoundingBox();
					Vector3 groupToMoveOriginalCenter = groupToMoveOriginalBounds.Center;
					AxisAlignedBoundingBox groupToMoveBounds = meshGroupToMove.GetAxisAlignedBoundingBox(asynchMeshGroupTransforms[meshGroupToMoveIndex].TotalTransform);
					Vector3 groupToMoveCenter = groupToMoveBounds.Center;

					Vector3 originalCoordinatesDelta = groupToMoveOriginalCenter - selectedOriginalCenter;
					Vector3 currentCoordinatesDelta = groupToMoveCenter - selctedCurrentCenter;

					Vector3 deltaRequired = originalCoordinatesDelta - currentCoordinatesDelta;

					if (deltaRequired.Length > .0001)
					{
						ScaleRotateTranslate translated = asynchMeshGroupTransforms[meshGroupToMoveIndex];
						translated.translation *= Matrix4X4.CreateTranslation(deltaRequired);
						asynchMeshGroupTransforms[meshGroupToMoveIndex] = translated;
						PartHasBeenChanged();
					}
				}
			}

			// now put all the meshes into just one group
			MeshGroup meshGroupWeAreKeeping = asynchMeshGroups[SelectedMeshGroupIndex];
			for (int meshGroupToMoveIndex = asynchMeshGroups.Count - 1; meshGroupToMoveIndex >= 0; meshGroupToMoveIndex--)
			{
				MeshGroup meshGroupToMove = asynchMeshGroups[meshGroupToMoveIndex];
				if (meshGroupToMove != meshGroupWeAreKeeping)
				{
					// move all the meshes into the new aligned mesh group
					for (int moveIndex = 0; moveIndex < meshGroupToMove.Meshes.Count; moveIndex++)
					{
						Mesh mesh = meshGroupToMove.Meshes[moveIndex];
						meshGroupWeAreKeeping.Meshes.Add(mesh);
					}

					asynchMeshGroups.RemoveAt(meshGroupToMoveIndex);
					asynchMeshGroupTransforms.RemoveAt(meshGroupToMoveIndex);
				}
			}

			asynchPlatingDatas.Clear();
			double ratioPerMeshGroup = 1.0 / asynchMeshGroups.Count;
			double currentRatioDone = 0;
			for (int i = 0; i < asynchMeshGroups.Count; i++)
			{
				PlatingMeshGroupData newInfo = new PlatingMeshGroupData();
				asynchPlatingDatas.Add(newInfo);

				MeshGroup meshGroup = asynchMeshGroups[i];

				// create the selection info
				PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, i, (double progress0To1, string processingState, out bool continueProcessing) =>
				{
					BackgroundWorker_ProgressChanged(progress0To1, processingState, out continueProcessing);
				});

				currentRatioDone += ratioPerMeshGroup;
			}
		}
Esempio n. 25
0
		private void GroupSelected()
		{
			string makingCopyLabel = LocalizedString.Get("Grouping");
			string makingCopyLabelFull = string.Format("{0}:", makingCopyLabel);
			processingProgressControl.ProcessType = makingCopyLabelFull;

			Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

			PushMeshGroupDataToAsynchLists(TraceInfoOpperation.DO_COPY);

			for (int i = 0; i < asyncMeshGroups.Count; i++)
			{
				asyncMeshGroups[i].Transform(asyncMeshGroupTransforms[i]);

				bool continueProcessing;
				ReportProgressChanged((i + 1) * .4 / asyncMeshGroups.Count, "", out continueProcessing);
			}

			if (SelectedMeshGroupIndex == -1)
			{
				SelectedMeshGroupIndex = 0;
			}

			MeshGroup meshGroupWeAreKeeping = asyncMeshGroups[SelectedMeshGroupIndex];
			for (int meshGroupToMoveIndex = asyncMeshGroups.Count - 1; meshGroupToMoveIndex >= 0; meshGroupToMoveIndex--)
			{
				MeshGroup meshGroupToMove = asyncMeshGroups[meshGroupToMoveIndex];
				if (meshGroupToMove != meshGroupWeAreKeeping)
				{
					for (int moveIndex = 0; moveIndex < meshGroupToMove.Meshes.Count; moveIndex++)
					{
						Mesh mesh = meshGroupToMove.Meshes[moveIndex];
						meshGroupWeAreKeeping.Meshes.Add(mesh);
					}

					asyncMeshGroups.RemoveAt(meshGroupToMoveIndex);
					asyncMeshGroupTransforms.RemoveAt(meshGroupToMoveIndex);
				}
				else
				{
					asyncMeshGroupTransforms[meshGroupToMoveIndex] = Matrix4X4.Identity;
				}
			}

			asyncPlatingDatas.Clear();
			double ratioPerMeshGroup = 1.0 / asyncMeshGroups.Count;
			double currentRatioDone = 0;
			for (int i = 0; i < asyncMeshGroups.Count; i++)
			{
				PlatingMeshGroupData newInfo = new PlatingMeshGroupData();
				asyncPlatingDatas.Add(newInfo);

				MeshGroup meshGroup = asyncMeshGroups[i];

				// create the selection info
				PlatingHelper.CreateITraceableForMeshGroup(asyncPlatingDatas, asyncMeshGroups, i, (double progress0To1, string processingState, out bool continueProcessing) =>
				{
					ReportProgressChanged(progress0To1, processingState, out continueProcessing);
				});

				currentRatioDone += ratioPerMeshGroup;
			}
		}