Esempio n. 1
0
        protected override void OnContentRendered(EventArgs e)
        {
            // Get the body parts
            String[] fileNames = new String[]
            {
                Assets + "figure_Object001.eye",
                Assets + "figure_Object002.eye",
                Assets + "figure_Object003.eye",
                Assets + "figure_Object004.eye",
                Assets + "figure_Object005.eye",
                Assets + "figure_Object006.eye",
                Assets + "figure_Object007.eye",
                Assets + "figure_Object008.eye",
                Assets + "figure_Object009.eye",
                Assets + "figure_Object010.eye",
                Assets + "figure_Object011.eye",
                Assets + "figure_Object012.eye",
                Assets + "figure_Object013.eye",
                Assets + "figure_Object014.eye",
                Assets + "figure_Object015.eye",
                Assets + "figure_Object016.eye",
                Assets + "figure_Object017.eye",
                Assets + "figure_Object018.eye",
                Assets + "figure_Object019.eye",
                Assets + "figure_Object020.eye",
                Assets + "figure_Object021.eye",
                Assets + "figure_Object022.eye",
                Assets + "figure_Object023.eye",
                Assets + "figure_Object024.eye"
            };

            string[] partNames =
            {
                "LeftFoot",
                "RightFoot",
                "LeftAnkle",
                "RightAnkle",
                "LeftLowerLeg",
                "RightLowerLeg",
                "LeftKnee",
                "RightKnee",
                "LeftUpperLeg",
                "RightUpperLeg",
                "Torso",
                "LeftShoulder",
                "LeftUpperArm",
                "LeftElbow",
                "LeftLowerArm",
                "LeftWrist",
                "LeftHand",
                "RightShoulder",
                "RightUpperArm",
                "RightElbow",
                "RightLowerArm",
                "RightWrist",
                "RightHand",
                "Head"
            };

            // Create a BlockReference for each body part
            Entity[] entities = new Entity[fileNames.Length];

            for (int i = 0; i < fileNames.Length; i++)
            {
                entities[i] = CreateBlockReference(partNames[i], fileNames[i]);
            }

            // Creates a dictionary to identify the body part index from its name
            Dictionary <string, int> parts = new Dictionary <string, int>();

            for (int i = 0; i < partNames.Length; i++)
            {
                parts.Add(partNames[i], i);
            }

            // Creates BlockReferences for the various groups of entities that form the body parts
            // and set in the EntityData proerty of each one the point to be used as the ObjectManipulator origin

            BlockReference brTemp, brTemp2;

            SetRotationPoint(entities[parts["LeftWrist"]], (BlockReference)entities[parts["LeftHand"]]);
            SetRotationPoint(entities[parts["RightWrist"]], (BlockReference)entities[parts["RightHand"]]);
            SetRotationPoint(entities[parts["LeftAnkle"]], (BlockReference)entities[parts["LeftFoot"]]);
            SetRotationPoint(entities[parts["RightAnkle"]], (BlockReference)entities[parts["RightFoot"]]);

            //Left leg
            brTemp = BuildBlockReference("BrLeftLowerLeg", new Entity[] { entities[parts["LeftFoot"]],
                                                                          entities[parts["LeftAnkle"]],
                                                                          entities[parts["LeftLowerLeg"]] });

            SetRotationPoint(entities[parts["LeftKnee"]], brTemp);

            brTemp2 = BuildBlockReference("BrLeftUpperLeg", new Entity[]
            {
                entities[parts["LeftUpperLeg"]],
                entities[parts["LeftKnee"]]
            });

            BlockReference br1 = BuildBlockReference("BrLeftLeg", new Entity[]
            {
                brTemp,
                brTemp2
            });

            br1.EntityData = new Point3D(3.8, 44, 1.6);

            // Right leg
            brTemp = BuildBlockReference("BrRightLowerLeg", new Entity[] { entities[parts["RightFoot"]],
                                                                           entities[parts["RightAnkle"]],
                                                                           entities[parts["RightLowerLeg"]] });

            SetRotationPoint(entities[parts["RightKnee"]], brTemp);

            brTemp2 = BuildBlockReference("BrRightUpperLeg", new Entity[] {
                entities[parts["RightUpperLeg"]],
                entities[parts["RightKnee"]]
            });

            BlockReference br2 = BuildBlockReference("BrRightLeg", new Entity[] {
                brTemp,
                brTemp2
            });

            br2.EntityData = new Point3D(-3.8, 44, 1.6);

            // Left arm
            brTemp = BuildBlockReference("BrLeftLowerArm", new Entity[] { entities[parts["LeftHand"]],
                                                                          entities[parts["LeftWrist"]],
                                                                          entities[parts["LeftLowerArm"]] });

            SetRotationPoint(entities[parts["LeftElbow"]], brTemp);

            BlockReference br3 = BuildBlockReference("BrLefArm", new Entity[] {
                brTemp,
                entities[parts["LeftElbow"]],
                entities[parts["LeftUpperArm"]],
                entities[parts["LeftShoulder"]]
            });

            SetRotationPoint(entities[parts["LeftShoulder"]], br3);


            // Right arm
            brTemp = BuildBlockReference("BrRightLowerArm", new Entity[] { entities[parts["RightHand"]],
                                                                           entities[parts["RightWrist"]],
                                                                           entities[parts["RightLowerArm"]] });

            SetRotationPoint(entities[parts["RightElbow"]], brTemp);

            BlockReference br4 = BuildBlockReference("BrRightArm", new Entity[]
            {
                brTemp,
                entities[parts["RightElbow"]],
                entities[parts["RightUpperArm"]],
                entities[parts["RightShoulder"]]
            });

            SetRotationPoint(entities[parts["RightShoulder"]], br4);

            // Creates the final BlockReference containing the whole model
            BlockReference brBody = BuildBlockReference("BrMan", new Entity[]
            {
                br1, br2, br3, br4,
                entities[parts["Torso"]],
                entities[parts["Head"]]
            }
                                                        );

            entities[parts["Head"]].EntityData = new Point3D(0, 63, .38); // set the rotation point

            brBody.Rotate(Math.PI / 2, Vector3D.AxisX);

            model1.Entities.Add(brBody, System.Drawing.Color.Pink);

            Mesh baseBox = Mesh.CreateBox(20, 20, 10);

            baseBox.Translate(50, 50, 0);
            model1.Materials.Add(new Material("wood", new Bitmap(Assets + "Textures/Wenge.jpg")));
            baseBox.ApplyMaterial("wood", textureMappingType.Cubic, 1, 1);
            model1.Entities.Add(baseBox);

            model1.ZoomFit();

            model1.ActionMode = actionType.SelectVisibleByPick;
            model1.GetViewCubeIcon().Visible = false;
            model1.Rendered.ShadowMode = shadowType.None;
            model1.Rendered.ShowEdges  = false;

            // Hide the original part when editing it
            model1.ObjectManipulator.ShowOriginalWhileEditing = false;
            model1.Invalidate();

            base.OnContentRendered(e);
        }