Beispiel #1
0
        public void SetMeshAfterLoad(Mesh loadedMesh)
        {
            meshsToRender.Clear();

            if (loadedMesh == null)
            {
                TextWidget no3DView = new TextWidget(string.Format("No 3D view for this file."));
                no3DView.Margin  = new BorderDouble(0, 0, 0, 0);
                no3DView.VAnchor = Agg.UI.VAnchor.ParentCenter;
                no3DView.HAnchor = Agg.UI.HAnchor.ParentCenter;
                this.AddChild(no3DView);
            }
            else
            {
                meshsToRender.Add(loadedMesh);

                trackballTumbleWidget.TrackBallController = new TrackBallController();
                trackballTumbleWidget.OnBoundsChanged(null);
                trackballTumbleWidget.TrackBallController.Scale = .03;
                trackballTumbleWidget.TrackBallController.Rotate(Quaternion.FromEulerAngles(new Vector3(0, 0, MathHelper.Tau / 16)));
                trackballTumbleWidget.TrackBallController.Rotate(Quaternion.FromEulerAngles(new Vector3(-MathHelper.Tau * .19, 0, 0)));
                if (partScale != 1)
                {
                    foreach (Vertex vertex in meshsToRender[0].Vertices)
                    {
                        vertex.Position = vertex.Position * partScale;
                    }
                }

                PlaceMeshOnBed(0);
            }
        }
Beispiel #2
0
        public void SetMeshAfterLoad(List <MeshGroup> loadedMeshGroups, CenterPartAfterLoad centerPart)
        {
            MeshGroups.Clear();

            if (loadedMeshGroups == null)
            {
                partProcessingInfo.centeredInfoText.Text = string.Format("Sorry! No 3D view available\nfor this file.");
            }
            else
            {
                CreateGlDataForMeshes(loadedMeshGroups);

                AxisAlignedBoundingBox bounds = new AxisAlignedBoundingBox(Vector3.Zero, Vector3.Zero);
                bool first = true;
                foreach (MeshGroup meshGroup in loadedMeshGroups)
                {
                    if (first)
                    {
                        bounds = meshGroup.GetAxisAlignedBoundingBox();
                        first  = false;
                    }
                    else
                    {
                        bounds = AxisAlignedBoundingBox.Union(bounds, meshGroup.GetAxisAlignedBoundingBox());
                    }
                }

                foreach (MeshGroup meshGroup in loadedMeshGroups)
                {
                    // make sure the mesh is centered about the origin so rotations will come from a reasonable place
                    ScaleRotateTranslate centering = ScaleRotateTranslate.Identity();
                    centering.SetCenteringForMeshGroup(meshGroup);
                    meshTransforms.Add(centering);
                    MeshGroups.Add(meshGroup);
                }

                if (centerPart == CenterPartAfterLoad.DO)
                {
                    // make sure the entile load is centered and on the bed
                    Vector3 boundsCenter = (bounds.maxXYZ + bounds.minXYZ) / 2;
                    for (int i = 0; i < MeshGroups.Count; i++)
                    {
                        ScaleRotateTranslate moved = meshTransforms[i];
                        moved.translation *= Matrix4X4.CreateTranslation(-boundsCenter + new Vector3(0, 0, bounds.ZSize / 2));
                        meshTransforms[i]  = moved;
                    }
                }

                trackballTumbleWidget.TrackBallController = new TrackBallController();
                trackballTumbleWidget.OnBoundsChanged(null);
                trackballTumbleWidget.TrackBallController.Scale = .03;
                trackballTumbleWidget.TrackBallController.Rotate(Quaternion.FromEulerAngles(new Vector3(0, 0, MathHelper.Tau / 16)));
                trackballTumbleWidget.TrackBallController.Rotate(Quaternion.FromEulerAngles(new Vector3(-MathHelper.Tau * .19, 0, 0)));
            }
        }