Ejemplo n.º 1
0
        /// <summary>
        /// Generates the piece 3D visual according to the piece type.
        /// </summary>
        /// <param name="pieceType"></param>
        /// <returns></returns>
        private ModelVisual3D GeneratePieceVisual(Type pieceType)
        {
            string pieceName = pieceType.Name.Substring(5);
            string colorName = pieceType.Name.Substring(0, 5);

            // get the piece geometry
            MeshGeometry3D pieceGeometry = FindResource(pieceName + "Geometry") as MeshGeometry3D;

            // set the geometry and the material
            GeometryModel3D pieceModel = new GeometryModel3D(pieceGeometry, FindResource(colorName + "Material") as Material);

            // if the piece is black, rotate the model by 180 degrees
            if (colorName == "Black")
            {
                pieceModel.Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 180));
            }

            ModelVisual3D pieceVisual = new ModelVisual3D();

            pieceVisual.Content = pieceModel;
            pieceVisual.SetValue(name, pieceType.Name + random.Next(100000000, 1000000000).ToString(CultureInfo.InvariantCulture));

            pieceVisual.Transform = new TranslateTransform3D();

            // add it to the viewable group and register its tranform
            viewableGroup.Children.Add(pieceVisual);
            RegisterName(pieceVisual.GetValue(name).ToString() + "Transform", pieceVisual.Transform);

            return(pieceVisual);
        }
Ejemplo n.º 2
0
        internal static void _SetCollisionMask(ModelVisual3D visual, CollisionMask value)
        {
            if (visual == null)
            {
                throw new ArgumentNullException("visual");
            }

            TerrianCollisionMask3D collisionMask = (value as TerrianCollisionMask3D);

            if (collisionMask != null)
            {
                if (!(visual.Content is GeometryModel3D))
                {
                    throw new InvalidOperationException("Current only GeometryModel3D models supported for TerrianCollisionMask3D.");
                }
                collisionMask.Visual = visual;
                visual.SetValue(World.CollisionMaskProperty, value);
            }
        }
Ejemplo n.º 3
0
 public static void SetMaterialShared(ModelVisual3D visual, bool value)
 {
     visual.SetValue(MaterialSharedProperty, value);
 }
Ejemplo n.º 4
0
 public static void SetOpacityShared(ModelVisual3D visual, bool value)
 {
     visual.SetValue(OpacitySharedProperty, value);
 }