EmissiveMaterial allows a 2d brush to be used on a 3d model that has been lit as if it were emitting light equal to the color of the brush
Наследование: System.Windows.Media.Media3D.Material
Пример #1
0
        //------------------------------------------------------
        //
        //  Public Properties
        //
        //------------------------------------------------------

        private static void ColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            EmissiveMaterial target = ((EmissiveMaterial)d);


            target.PropertyChanged(ColorProperty);
        }
Пример #2
0
 //Create a default material of the specified colour:
 public static MaterialGroup getSurfaceMaterial(Color colour)
 {
     var materialGroup = new MaterialGroup();
     var emmMat = new EmissiveMaterial(new SolidColorBrush(colour));
     materialGroup.Children.Add(emmMat);
     materialGroup.Children.Add(new DiffuseMaterial(new SolidColorBrush(colour)));
     var specMat = new SpecularMaterial(new SolidColorBrush(Colors.White), 30);
     materialGroup.Children.Add(specMat);
     return materialGroup;
 }
Пример #3
0
        public void CreateVisual3D(Model model)
        {
            UI ui = new UI(UITemplate);

            Viewport2DVisual3D visual = new Viewport2DVisual3D();
            visual.Geometry = Geometry;
            visual.Visual = ui.Visual;
            EmissiveMaterial material = new EmissiveMaterial(Brushes.White);
            Viewport2DVisual3D.SetIsVisualHostMaterial(material, true);
            visual.Material = material;

            model.Children.Add(visual);
        }
Пример #4
0
        public VideoSurface(string mediaSource)
        {
            this.ModelVisual3D = new ModelVisual3D();

            var geometryModel = new GeometryModel3D();
            this.ModelVisual3D.Content = geometryModel;

            this.geometry = new MeshGeometry3D();
            geometryModel.Geometry = geometry;

            var positions = new Point3DCollection();
            positions.Add(new Point3D(0, 0, 0));
            positions.Add(new Point3D(640, 0, 0));
            positions.Add(new Point3D(640, 480, 0));
            positions.Add(new Point3D(0, 480, 0));
            this.geometry.Positions = positions;

            var textureCoordinates = new PointCollection();
            textureCoordinates.Add(new System.Windows.Point(0, 1));
            textureCoordinates.Add(new System.Windows.Point(1, 1));
            textureCoordinates.Add(new System.Windows.Point(1, 0));
            textureCoordinates.Add(new System.Windows.Point(0, 0));
            this.geometry.TextureCoordinates = textureCoordinates;

            var triangleIndices = new Int32Collection();
            triangleIndices.Add(0);
            triangleIndices.Add(1);
            triangleIndices.Add(2);
            triangleIndices.Add(2);
            triangleIndices.Add(3);
            triangleIndices.Add(0);
            this.geometry.TriangleIndices = triangleIndices;

            var material = new EmissiveMaterial();
            var brush = new VisualBrush();
            this.border = new Border();
            this.border.BorderBrush = Brushes.White;
            this.border.BorderThickness = new Thickness(10);
            this.border.Opacity = 0;

            this.mediaElement = new MediaElement();
            mediaElement.LoadedBehavior = MediaState.Manual;
            mediaElement.Source = new Uri(mediaSource);

            this.border.Child = mediaElement;
            brush.Visual = border;
            material.Brush = brush;
            geometryModel.Material = material;

            this.mediaElement.MediaEnded += new RoutedEventHandler(mediaElement_MediaEnded);
        }
Пример #5
0
        private static void BrushPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            // The first change to the default value of a mutable collection property (e.g. GeometryGroup.Children)
            // will promote the property value from a default value to a local value. This is technically a sub-property
            // change because the collection was changed and not a new collection set (GeometryGroup.Children.
            // Add versus GeometryGroup.Children = myNewChildrenCollection). However, we never marshalled
            // the default value to the compositor. If the property changes from a default value, the new local value
            // needs to be marshalled to the compositor. We detect this scenario with the second condition
            // e.OldValueSource != e.NewValueSource. Specifically in this scenario the OldValueSource will be
            // Default and the NewValueSource will be Local.
            if (e.IsASubPropertyChange &&
                (e.OldValueSource == e.NewValueSource))
            {
                return;
            }


            EmissiveMaterial target = ((EmissiveMaterial)d);


            Brush oldV = (Brush)e.OldValue;
            Brush newV = (Brush)e.NewValue;

            System.Windows.Threading.Dispatcher dispatcher = target.Dispatcher;

            if (dispatcher != null)
            {
                DUCE.IResource targetResource = (DUCE.IResource)target;
                using (CompositionEngineLock.Acquire())
                {
                    int channelCount = targetResource.GetChannelCount();

                    for (int channelIndex = 0; channelIndex < channelCount; channelIndex++)
                    {
                        DUCE.Channel channel = targetResource.GetChannel(channelIndex);
                        Debug.Assert(!channel.IsOutOfBandChannel);
                        Debug.Assert(!targetResource.GetHandle(channel).IsNull);
                        target.ReleaseResource(oldV, channel);
                        target.AddRefResource(newV, channel);
                    }
                }
            }

            target.PropertyChanged(BrushProperty);
        }
        internal static Model3DGroup CreateGeometry(List<MaterialColorProps> materialBrushes, List<EmissiveMaterial> selectionEmissives, Transform3D transform, Color baseColor, SpecularMaterial baseSpecular, Color colorColor, SpecularMaterial colorSpecular, bool isFinal)
        {
            Model3DGroup retVal = new Model3DGroup();

            GeometryModel3D geometry;
            MaterialGroup material;
            DiffuseMaterial diffuse;
            SpecularMaterial specular;

            #region Main Cube

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(baseColor));
            materialBrushes.Add(new MaterialColorProps(diffuse, baseColor));
            material.Children.Add(diffuse);
            specular = baseSpecular;
            materialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                selectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            geometry.Geometry = GetMeshBase(SCALE);

            retVal.Children.Add(geometry);

            #endregion

            #region Color Cube

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(colorColor));
            materialBrushes.Add(new MaterialColorProps(diffuse, colorColor));
            material.Children.Add(diffuse);
            specular = colorSpecular;
            materialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                selectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            geometry.Geometry = GetMeshColor(SCALE);

            retVal.Children.Add(geometry);

            #endregion

            // Transform
            retVal.Transform = transform;

            // Exit Function
            return retVal;
        }
Пример #7
0
        private Model3DGroup CreateGeometry(bool isFinal)
        {
            Model3DGroup retVal = new Model3DGroup();

            GeometryModel3D geometry;
            MaterialGroup material;
            DiffuseMaterial diffuse;
            SpecularMaterial specular;

            int domeSegments = isFinal ? 2 : 10;
            int cylinderSegments = isFinal ? 6 : 35;

            #region Mount Box

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.GunBase));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.GunBase));
            material.Children.Add(diffuse);
            specular = WorldColors.GunBaseSpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                this.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            geometry.Geometry = UtilityWPF.GetCube(new Point3D(-.115, -.1, -.5), new Point3D(.115, .1, -.1));

            retVal.Children.Add(geometry);

            #endregion

            #region Barrel

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.GunBarrel));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.GunBarrel));
            material.Children.Add(diffuse);
            specular = WorldColors.GunBarrelSpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                this.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            const double OUTERRADIUS = .045;
            const double INNERRADIUS = .04;

            List<TubeRingBase> rings = new List<TubeRingBase>();

            rings.Add(new TubeRingRegularPolygon(0, false, OUTERRADIUS * 1.75d, OUTERRADIUS * 1.75d, false));		// Start at the base of the barrel
            rings.Add(new TubeRingRegularPolygon(.49, false, OUTERRADIUS * 1.75d, OUTERRADIUS * 1.75d, false));
            rings.Add(new TubeRingRegularPolygon(.02, false, OUTERRADIUS, OUTERRADIUS, false));
            rings.Add(new TubeRingRegularPolygon(.24, false, OUTERRADIUS, OUTERRADIUS, false));
            rings.Add(new TubeRingRegularPolygon(.01, false, OUTERRADIUS * 1.25d, OUTERRADIUS * 1.25d, false));
            rings.Add(new TubeRingRegularPolygon(.08, false, OUTERRADIUS * 1.25d, OUTERRADIUS * 1.25d, false));		// This is the tip of the barrel
            rings.Add(new TubeRingRegularPolygon(0, false, INNERRADIUS, INNERRADIUS, false));		// Curl to the inside
            rings.Add(new TubeRingRegularPolygon(-.75d, false, INNERRADIUS, INNERRADIUS, false));		// Loop back to the base

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, false, new TranslateTransform3D(0, 0, -.49d));

            retVal.Children.Add(geometry);

            #endregion

            #region Grapple Pad

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.GrapplePad));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.GrapplePad));
            material.Children.Add(diffuse);
            specular = WorldColors.GrapplePadSpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                this.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            rings = new List<TubeRingBase>();
            rings.Add(new TubeRingRegularPolygon(0, false, OUTERRADIUS * 2d, OUTERRADIUS * 2d, false));
            rings.Add(new TubeRingRegularPolygon(.1, false, OUTERRADIUS * 4d, OUTERRADIUS * 4d, false));
            rings.Add(new TubeRingDome(.05, false, domeSegments));

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, false, new TranslateTransform3D(0, 0, .35d));

            retVal.Children.Add(geometry);

            #endregion

            #region Trim

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.GunTrim));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.GunTrim));
            material.Children.Add(diffuse);
            specular = WorldColors.GunTrimSpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                this.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            geometry.Geometry = UtilityWPF.GetCube(new Point3D(-.095, -.11, -.45), new Point3D(.095, .11, -.15));

            retVal.Children.Add(geometry);

            #endregion

            // Transform
            retVal.Transform = GetTransformForGeometry(isFinal);

            // Exit Function
            return retVal;
        }
Пример #8
0
        internal static Model3DGroup CreateGeometry(List<MaterialColorProps> materialBrushes, List<EmissiveMaterial> selectionEmissives, Transform3D transform, Color baseColor, SpecularMaterial baseSpecular, EmissiveMaterial baseEmissive, Color colorColor, SpecularMaterial colorSpecular, bool isFinal)
        {
            const double SCALE = .5d;

            Model3DGroup retVal = new Model3DGroup();

            GeometryModel3D geometry;
            MaterialGroup material;
            DiffuseMaterial diffuse;
            SpecularMaterial specular;
            EmissiveMaterial emissive;

            int numSegments = isFinal ? 3 : 20;

            #region Main Sphere

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(colorColor));
            materialBrushes.Add(new MaterialColorProps(diffuse, colorColor));
            material.Children.Add(diffuse);
            specular = colorSpecular;
            materialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                selectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            geometry.Geometry = UtilityWPF.GetSphere_LatLon(numSegments, .9 * SCALE, .9 * SCALE, .65d * SCALE);

            retVal.Children.Add(geometry);

            #endregion

            #region Ring

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(baseColor));
            materialBrushes.Add(new MaterialColorProps(diffuse, baseColor));
            material.Children.Add(diffuse);
            specular = baseSpecular;
            materialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);
            emissive = baseEmissive;
            materialBrushes.Add(new MaterialColorProps(emissive));
            material.Children.Add(emissive);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                selectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            geometry.Geometry = UtilityWPF.GetSphere_LatLon(numSegments, 1d * SCALE, 1d * SCALE, .15d * SCALE);

            retVal.Children.Add(geometry);

            #endregion

            #region Axis

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(baseColor));
            materialBrushes.Add(new MaterialColorProps(diffuse, baseColor));
            material.Children.Add(diffuse);
            specular = baseSpecular;
            materialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);
            emissive = baseEmissive;
            materialBrushes.Add(new MaterialColorProps(emissive));
            material.Children.Add(emissive);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                selectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            geometry.Geometry = UtilityWPF.GetSphere_LatLon(numSegments, .25d * SCALE, .25d * SCALE, 1d * SCALE);

            retVal.Children.Add(geometry);

            #endregion

            // Transform
            retVal.Transform = transform;

            // Exit Function
            return retVal;
        }
Пример #9
0
        private Model3D CreateGeometry(bool isFinal)
        {
            #region Material

            DiffuseMaterial diffuse = WorldColorsArco.MotionController_Linear_Diffuse.Value;
            SpecularMaterial specular = WorldColorsArco.MotionController_Linear_Specular.Value;
            if (!isFinal)
            {
                diffuse = diffuse.Clone();      // cloning, because the editor will manipulate the brush, and WorldColors is handing out a shared brush
                specular = specular.Clone();
            }

            MaterialGroup material = new MaterialGroup();
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColorsArco.MotionController_Linear_Color));
            material.Children.Add(diffuse);
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                base.SelectionEmissives.Add(selectionEmissive);
            }

            #endregion

            double radius = ((this.Scale.X * SensorVisionDesign.SIZEPERCENTOFSCALE_XY) + (this.Scale.Y * SensorVisionDesign.SIZEPERCENTOFSCALE_XY)) / 2d;
            double height = this.Scale.Z * SensorVisionDesign.SIZEPERCENTOFSCALE_Z;
            double halfHeight = height / 2d;

            Model3DGroup retVal = new Model3DGroup();

            #region Center

            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = material;

            List<TubeRingBase> rings = new List<TubeRingBase>();

            rings.Add(new TubeRingPoint(0, false));
            rings.Add(new TubeRingRegularPolygon(halfHeight, false, radius * .3, radius * .3, false));
            rings.Add(new TubeRingPoint(halfHeight, false));

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(5, rings, false, true);

            retVal.Children.Add(geometry);

            #endregion

            #region Ring

            geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = material;

            int segments = isFinal ? 10 : 35;

            geometry.Geometry = UtilityWPF.GetRing(segments, radius - (height / 2d), radius, height);

            retVal.Children.Add(geometry);

            #endregion

            // Transform
            retVal.Transform = GetTransformForGeometry(isFinal);

            // Exit Function
            return retVal;
        }
Пример #10
0
        private Model3DGroup CreateGeometry(bool isFinal)
        {
            const double SCALE = 1d / ((1.5d + 1d) * 2d);		// the rod is longer than the base, so double that

            ScaleTransform3D transform = new ScaleTransform3D(SCALE, SCALE, SCALE);

            int domeSegments = isFinal ? 2 : 10;
            int cylinderSegments = isFinal ? 6 : 35;

            Model3DGroup retVal = new Model3DGroup();

            #region Base

            GeometryModel3D geometry = new GeometryModel3D();
            MaterialGroup material = new MaterialGroup();
            DiffuseMaterial diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.TractorBeamBase));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.TractorBeamBase));
            material.Children.Add(diffuse);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                base.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            List<TubeRingBase> rings = new List<TubeRingBase>();
            rings.Add(new TubeRingPoint(0, false));
            rings.Add(new TubeRingRegularPolygon(.3, false, .5, .5, false));
            rings.Add(new TubeRingRegularPolygon(2, false, 1, 1, false));
            rings.Add(new TubeRingDome(.66, false, domeSegments));

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, true, transform);

            retVal.Children.Add(geometry);

            #endregion
            #region Rod

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.TractorBeamRod));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.TractorBeamRod));
            material.Children.Add(diffuse);
            SpecularMaterial specular = WorldColors.TractorBeamRodSpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);
            EmissiveMaterial emissive = WorldColors.TractorBeamRodEmissive;
            this.MaterialBrushes.Add(new MaterialColorProps(emissive));
            material.Children.Add(emissive);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                base.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            rings = new List<TubeRingBase>();
            rings.Add(new TubeRingRegularPolygon(0, false, .25, .25, false));
            rings.Add(new TubeRingRegularPolygon(1.5, false, .25, .25, false));
            rings.Add(new TubeRingDome(1, false, domeSegments));

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, false, transform);

            retVal.Children.Add(geometry);

            #endregion

            // Transform
            retVal.Transform = GetTransformForGeometry(isFinal);

            // Exit Function
            return retVal;
        }
Пример #11
0
        private Model3DGroup CreateGeometry(bool isFinal)
        {
            const double BOXWIDTHHALF = .47d;
            const double PLATEHEIGHT = .1d;
            const double PLATEHEIGHTHALF = PLATEHEIGHT * .5d;
            const double TRIMWIDTH = .1d;
            const double TRIMWIDTHHALF = TRIMWIDTH * .5d;

            Model3DGroup retVal = new Model3DGroup();

            GeometryModel3D geometry;
            MaterialGroup material;
            DiffuseMaterial diffuse;
            SpecularMaterial specular;

            #region Main Box

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.HangarBay));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.HangarBay));
            material.Children.Add(diffuse);
            specular = WorldColors.HangarBaySpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                this.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            if (isFinal)
            {
                geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-.5, -.5, -.5), new Point3D(.5, .5, .5));
            }
            else
            {
                geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-BOXWIDTHHALF, -BOXWIDTHHALF, -BOXWIDTHHALF), new Point3D(BOXWIDTHHALF, BOXWIDTHHALF, BOXWIDTHHALF));
            }

            retVal.Children.Add(geometry);

            #endregion

            if (!isFinal)
            {
                #region Plates

                for (int cntr = -1; cntr <= 1; cntr += 2)
                {
                    geometry = new GeometryModel3D();
                    material = new MaterialGroup();
                    diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.HangarBayTrim));
                    this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.HangarBayTrim));
                    material.Children.Add(diffuse);
                    specular = WorldColors.HangarBayTrimSpecular;
                    this.MaterialBrushes.Add(new MaterialColorProps(specular));
                    material.Children.Add(specular);

                    //if (!isFinal)
                    //{
                    EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                    material.Children.Add(selectionEmissive);
                    this.SelectionEmissives.Add(selectionEmissive);
                    //}

                    geometry.Material = material;
                    geometry.BackMaterial = material;

                    double z = (.5d - PLATEHEIGHTHALF) * cntr;
                    geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-.5d, -.5d, z - PLATEHEIGHTHALF), new Point3D(.5d, .5d, z + PLATEHEIGHTHALF));

                    retVal.Children.Add(geometry);
                }

                #endregion

                #region Supports

                for (int xCntr = -1; xCntr <= 1; xCntr += 2)
                {
                    for (int yCntr = -1; yCntr <= 1; yCntr += 2)
                    {
                        geometry = new GeometryModel3D();
                        material = new MaterialGroup();
                        diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.HangarBayTrim));
                        this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.HangarBayTrim));
                        material.Children.Add(diffuse);
                        specular = WorldColors.HangarBayTrimSpecular;
                        this.MaterialBrushes.Add(new MaterialColorProps(specular));
                        material.Children.Add(specular);

                        //if (!isFinal)
                        //{
                        EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                        material.Children.Add(selectionEmissive);
                        this.SelectionEmissives.Add(selectionEmissive);
                        //}

                        geometry.Material = material;
                        geometry.BackMaterial = material;

                        double x = (.5d - TRIMWIDTHHALF) * xCntr;
                        double y = (.5d - TRIMWIDTHHALF) * yCntr;
                        geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(x - TRIMWIDTHHALF, y - TRIMWIDTHHALF, -.5d), new Point3D(x + TRIMWIDTHHALF, y + TRIMWIDTHHALF, .5d));

                        retVal.Children.Add(geometry);
                    }
                }

                #endregion
            }

            // Transform
            retVal.Transform = GetTransformForGeometry(isFinal);

            // Exit Function
            return retVal;
        }
Пример #12
0
            public MaterialColorProps(EmissiveMaterial emissive)
            {
                this.Emissive = emissive;

                SolidColorBrush brush = emissive.Brush as SolidColorBrush;
                if (brush == null)
                {
                    throw new ApplicationException("The emissive was expected to be set up with a solid color brush.  Expand this method");
                }

                this.OrigBrush = brush;
                this.OrigColor = brush.Color;
            }
Пример #13
0
 public void GenerateGeometry()
 {
     m_hideMaterial = new EmissiveMaterial(new SolidColorBrush(Colors.Transparent) { Opacity = 0 });
       m_geometry = new List<GeometryModel3D>();
       m_materials = new List<DiffuseMaterial>();
       foreach (Color color in m_points.Keys)
       {
     if (m_points[color].Count == 0)
       continue;
     GeometryModel3D geometryModel3D = new GeometryModel3D();
     MeshGeometry3D meshGeometry3D = new MeshGeometry3D
     {
       Positions = new Point3DCollection(m_points[color]),
       TriangleIndices = new Int32Collection(m_triangles[color]),
       Normals = new Vector3DCollection(m_normals[color])
     };
     geometryModel3D.Geometry = meshGeometry3D;
     DiffuseMaterial material = new DiffuseMaterial(new SolidColorBrush(color) {Opacity = m_isVisable ? Opacity : 0}) ;
     geometryModel3D.Material = material;
     m_materials.Add(material);
     geometryModel3D.Transform = new ScaleTransform3D(Scale,Scale,Scale);
     Geometry.Add(geometryModel3D);
       }
 }
Пример #14
0
        // Creates new material
        void CreateMaterial()
        {
            // Creates materials
            material = new MaterialGroup();
            diffuseMaterial = new DiffuseMaterial(new SolidColorBrush(diffuse.Value)){AmbientColor = ambient.Value};
            if (bumpImage == null) bumpImage = new BitmapImage(new Uri("pack://application:,,,/NuGenBioChem;component/Images/Noise.png"));
            bumpMaterial = new DiffuseMaterial(new ImageBrush(bumpImage) { TileMode = TileMode.Tile, Opacity = bumpLevel.Value }) { Color = diffuse.Value, AmbientColor = ambient.Value };
            if(reflectionImage==null) reflectionImage = new BitmapImage(new Uri("pack://application:,,,/NuGenBioChem;component/Images/Clouds.png"));
            enviromentMaterial = new DiffuseMaterial(new ImageBrush(reflectionImage) { TileMode = TileMode.Tile, Opacity = reflectionLevel.Value }) { Color = diffuse.Value, AmbientColor = ambient.Value };
            emissiveMaterial = new EmissiveMaterial(new SolidColorBrush(emissive.Value){Opacity = emissiveLevel.Value});
            specularMaterial = new SpecularMaterial(new SolidColorBrush(specular.Value){Opacity = glossiness.Value},specularPower.Value);

            // Fill group
            if (diffuse.Value.A > 5) // Only if diffuse is not transparent
            {
                if ((bumpLevel.Value < 1) && (reflectionLevel.Value < 1)) material.Children.Add(diffuseMaterial);
                if ((bumpLevel.Value > 0) && (reflectionLevel.Value < 1)) material.Children.Add(bumpMaterial);
                if (reflectionLevel.Value > 0) material.Children.Add(enviromentMaterial);
                if ((emissiveLevel.Value > 0) && (emissive.Value != Colors.Black))
                    material.Children.Add(emissiveMaterial);
                if ((glossiness.Value > 0) && (specular.Value != Colors.Black)) material.Children.Add(specularMaterial);
            }
            RaisePropertyChanged("VisualMaterial");
        }
Пример #15
0
        internal static Model3D CreateGeometry(List<MaterialColorProps> materialBrushes, List<EmissiveMaterial> selectionEmissives, Transform3D transform, Color color, SpecularMaterial specular, bool isFinal)
        {
            // Material
            MaterialGroup material = new MaterialGroup();
            DiffuseMaterial diffuse = new DiffuseMaterial(new SolidColorBrush(color));
            materialBrushes.Add(new MaterialColorProps(diffuse, color));
            material.Children.Add(diffuse);
            materialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                selectionEmissives.Add(selectionEmissive);
            }

            // Geometry Model
            GeometryModel3D retVal = new GeometryModel3D();
            retVal.Material = material;
            retVal.BackMaterial = material;

            int domeSegments = isFinal ? 2 : 10;
            int cylinderSegments = isFinal ? 6 : 35;

            retVal.Geometry = UtilityWPF.GetCapsule_AlongZ(cylinderSegments, domeSegments, RADIUSPERCENTOFSCALE, 1d);

            // Transform
            retVal.Transform = transform;

            // Exit Function
            return retVal;
        }
Пример #16
0
        internal static Model3DGroup CreateGeometry(List<MaterialColorProps> materialBrushes, List<EmissiveMaterial> selectionEmissives, Transform3D transform, Color cameraBase, SpecularMaterial cameraBaseSpecular, Color cameraLensColor, SpecularMaterial cameraLensSpecular, bool isFinal)
        {
            ScaleTransform3D scaleTransformLocal = new ScaleTransform3D(SCALE, SCALE, SCALE);

            int domeSegments = isFinal ? 2 : 10;
            int cylinderSegments = isFinal ? 6 : 35;

            Model3DGroup retVal = new Model3DGroup();

            GeometryModel3D geometry;
            MaterialGroup material;
            DiffuseMaterial diffuse;
            SpecularMaterial specular;

            Transform3DGroup transformGroup = new Transform3DGroup();
            transformGroup.Children.Add(new TranslateTransform3D(0, 0, (HEIGHT / 2d) - .15d));
            transformGroup.Children.Add(scaleTransformLocal);

            #region Spotlight

            //// Even when I make it extreme, it doesn't seem to make the gradient brighter
            //SpotLight spotLight = new SpotLight();
            //spotLight.Color = Colors.White;
            ////spotLight.LinearAttenuation = 1d;
            //spotLight.LinearAttenuation = .1d;
            //spotLight.Range = 10;
            //spotLight.InnerConeAngle = 66;
            //spotLight.OuterConeAngle = 80;
            //spotLight.Direction = new Vector3D(0, 0, -1);
            //spotLight.Transform = new TranslateTransform3D(0, 0, 1);

            //retVal.Children.Add(spotLight);

            #endregion

            #region Back Lens

            if (!isFinal)
            {
                geometry = new GeometryModel3D();
                material = new MaterialGroup();

                RadialGradientBrush eyeBrush = new RadialGradientBrush();
                eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FFFFEA00"), 0d));
                eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FFF5E100"), 0.0187702d));
                eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FFECD800"), 0.0320388d));
                eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FFD46C00"), 0.0485437d));
                eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FFBC0000"), 0.104167d));
                eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FF8E0000"), 0.267322d));
                eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FF600000"), 0.486408d));
                eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FF3E0000"), 0.61068d));
                eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FF1D0000"), 0.713592d));
                eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FF0E0000"), 0.760544d));
                eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FF000000"), 1d));

                diffuse = new DiffuseMaterial(eyeBrush);
                materialBrushes.Add(new MaterialColorProps(diffuse, cameraLensColor));		// using the final's lens color, because it's a solid color
                material.Children.Add(diffuse);

                //if (!isFinal)
                //{
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                selectionEmissives.Add(selectionEmissive);
                //}

                geometry.Material = material;
                geometry.BackMaterial = material;

                geometry.Geometry = UtilityWPF.GetCircle2D(cylinderSegments, transformGroup, transformGroup);

                retVal.Children.Add(geometry);
            }

            #endregion

            #region Glass Cover

            geometry = new GeometryModel3D();
            material = new MaterialGroup();

            if (isFinal)
            {
                material.Children.Add(new DiffuseMaterial(new SolidColorBrush(cameraLensColor)));		// no need to add these to this.MaterialBrushes (those are only for editing)
                material.Children.Add(cameraLensSpecular);
            }
            else
            {
                //NOTE: Not using the world color, because that's for final.  The editor has a HAL9000 eye, and this is a glass plate
                Color color = Color.FromArgb(26, 255, 255, 255);
                diffuse = new DiffuseMaterial(new SolidColorBrush(color));
                materialBrushes.Add(new MaterialColorProps(diffuse, color));
                material.Children.Add(diffuse);
                specular = new SpecularMaterial(new SolidColorBrush(Color.FromArgb(224, 255, 255, 255)), 95d);
                materialBrushes.Add(new MaterialColorProps(specular));
                material.Children.Add(specular);

                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                selectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            //NOTE: The position handed to the camera pool is the center of this camera.  So need to leave the back material null, or it would
            //be like taking pictures with the lens cap on
            //geometry.BackMaterial = material;

            List<TubeRingBase> rings = new List<TubeRingBase>();
            rings.Add(new TubeRingRegularPolygon(0, false, 1, 1, false));
            rings.Add(new TubeRingDome(.15, false, domeSegments));

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, false, transformGroup);

            retVal.Children.Add(geometry);

            #endregion

            #region Silver Ring

            if (!isFinal)
            {
                geometry = new GeometryModel3D();
                material = new MaterialGroup();
                Color color = Color.FromRgb(90, 90, 90);
                diffuse = new DiffuseMaterial(new SolidColorBrush(color));
                materialBrushes.Add(new MaterialColorProps(diffuse, color));
                material.Children.Add(diffuse);
                specular = new SpecularMaterial(Brushes.White, 100d);
                materialBrushes.Add(new MaterialColorProps(specular));
                material.Children.Add(specular);

                //if (!isFinal)
                //{
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                selectionEmissives.Add(selectionEmissive);
                //}

                geometry.Material = material;
                geometry.BackMaterial = material;

                geometry.Geometry = UtilityWPF.GetRing(cylinderSegments, .97, 1.03, .05, transformGroup);

                retVal.Children.Add(geometry);
            }

            #endregion

            #region Back Cover

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(cameraBase));
            materialBrushes.Add(new MaterialColorProps(diffuse, cameraBase));
            material.Children.Add(diffuse);
            specular = cameraBaseSpecular;
            materialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                selectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            rings = new List<TubeRingBase>();
            rings.Add(new TubeRingDome(0, false, domeSegments));
            rings.Add(new TubeRingRegularPolygon(1.5, false, 1, 1, false));

            transformGroup = new Transform3DGroup();
            transformGroup.Children.Add(new TranslateTransform3D(0, 0, 1.65 / -2d));
            transformGroup.Children.Add(scaleTransformLocal);

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, false, transformGroup);

            retVal.Children.Add(geometry);

            #endregion

            // Transform
            retVal.Transform = transform;

            // Exit Function
            return retVal;
        }
Пример #17
0
        public Material MakeMaterial(MFnMesh fnMesh)
        {
            MaterialGroup matGroup =new MaterialGroup () ;

            MObjectArray shaders =new MObjectArray() ;
            MIntArray indices =new MIntArray () ;
            fnMesh.getConnectedShaders (0, shaders, indices) ;
            for ( int i =0 ; i < shaders.length ; i++ ) {
                MFnDependencyNode shaderGroup =new MFnDependencyNode (shaders [i]) ;
                MPlug shaderPlug =shaderGroup.findPlug ("surfaceShader") ;
                MPlugArray connections =new MPlugArray () ;
                shaderPlug.connectedTo (connections, true, false) ;
                for ( int u =0 ; u < connections.length ; u++ ) {
                    MFnDependencyNode depNode =new MFnDependencyNode (connections [u].node) ;

                    //MPlug colorPlug =depNode.findPlug ("color") ;
                    //MColor mcolor =new MColor () ;
                    ///*MPlugArray cc =new MPlugArray () ;
                    //colorPlug.connectedTo (cc, true , false) ;
                    //if ( cc.length > 0 ) {
                    //    // Plug is driven by an input connection.
                    //    for ( int v =0 ; v < cc.length ; v++ ) {
                    //        MPlug color2Plug =cc [v] ;
                    //        Console.WriteLine (color2Plug.numChildren) ;
                    //        color2Plug.child (0).getValue (mcolor.r) ;
                    //        color2Plug.child (1).getValue (mcolor.g) ;
                    //        color2Plug.child (2).getValue (mcolor.b) ;
                    //        //color2Plug.child (3).getValue (mcolor.a) ;
                    //    }
                    //} else {*/
                    //    mcolor.r =colorPlug.child (0).asFloat () ;
                    //    mcolor.g =colorPlug.child (1).asFloat () ;
                    //    mcolor.b =colorPlug.child (2).asFloat () ;
                    //    //colorPlug.child (3).getValue (mcolor.a) ;
                    ////}

                    //MPlug trPlug =depNode.findPlug ("transparency") ;
                    //float transparency =1.0f - trPlug.child (0).asFloat () ;
                    ////return new DiffuseMaterial (new SolidColorBrush (Color.FromScRgb (transparency, mcolor.r, mcolor.g, mcolor.b))) ;

                    //DiffuseMaterial diffuse =new DiffuseMaterial (new SolidColorBrush (Color.FromScRgb (transparency, mcolor.r, mcolor.g, mcolor.b))) ;
                    //colorPlug =depNode.findPlug ("ambientColor") ;
                    //mcolor.r =colorPlug.child (0).asFloat () ;
                    //mcolor.g =colorPlug.child (1).asFloat () ;
                    //mcolor.b =colorPlug.child (2).asFloat () ;
                    //diffuse.AmbientColor =Color.FromScRgb (transparency, mcolor.r, mcolor.g, mcolor.b) ;
                    //matGroup.Children.Add (diffuse) ;

                    //colorPlug =depNode.findPlug ("specularColor") ;
                    //mcolor.r =colorPlug.child (0).asFloat () ;
                    //mcolor.g =colorPlug.child (1).asFloat () ;
                    //mcolor.b =colorPlug.child (2).asFloat () ;
                    //MPlug powerPlug =depNode.findPlug ("cosinePower") ;

                    //SpecularMaterial specular =new SpecularMaterial (new SolidColorBrush (Color.FromScRgb (1.0f, mcolor.r, mcolor.g, mcolor.b)), powerPlug.asDouble ()) ;
                    //matGroup.Children.Add (specular) ;

                    //EmissiveMaterial emissive =new EmissiveMaterial () ;
                    //matGroup.Children.Add (emissive) ;

                    try {
                        MFnLambertShader lambert =new MFnLambertShader (connections [u].node) ;

                        SolidColorBrush brush =new SolidColorBrush (Color.FromScRgb (1.0f - lambert.transparency.r, lambert.color.r, lambert.color.g, lambert.color.b)) ;
                        brush.Opacity =1.0f - lambert.transparency.r ;
                        DiffuseMaterial diffuse =new DiffuseMaterial (brush) ;
                        diffuse.AmbientColor =Color.FromScRgb (1.0f - lambert.ambientColor.a, lambert.ambientColor.r, lambert.ambientColor.g, lambert.ambientColor.b) ;
                        // no more attributes
                        matGroup.Children.Add (diffuse) ;

                        // No specular color

                        EmissiveMaterial emissive =new EmissiveMaterial (new SolidColorBrush (Color.FromScRgb (1.0f - lambert.incandescence.a, lambert.incandescence.r, lambert.incandescence.g, lambert.incandescence.b))) ;
                        // no more attributes
                        matGroup.Children.Add (emissive) ;
                    } catch {
                    }

                    //try {
                    //    MFnReflectShader reflect =new MFnReflectShader (connections [u].node) ;

                    //    SpecularMaterial specular =new SpecularMaterial (new SolidColorBrush (Color.FromScRgb (1.0f - reflect.specularColor.a, reflect.specularColor.r, reflect.specularColor.g, reflect.specularColor.b)), reflect.cosPower) ;
                    //    // no more attributes
                    //    matGroup.Children.Add (specular) ;
                    //} catch {
                    //}

                    try {
                        MFnPhongShader phong =new MFnPhongShader (connections [u].node) ;

                        //See Lambert
                        //SolidColorBrush brush =new SolidColorBrush (Color.FromScRgb (1.0f - phong.transparency.r, phong.color.r, phong.color.g, phong.color.b)) ;
                        //brush.Opacity =1.0f - phong.transparency.r ;
                        //DiffuseMaterial diffuse =new DiffuseMaterial (brush) ;
                        //diffuse.AmbientColor =Color.FromScRgb (1.0f - phong.ambientColor.a, phong.ambientColor.r, phong.ambientColor.g, phong.ambientColor.b) ;
                        //// no more attributes
                        //matGroup.Children.Add (diffuse) ;

                        SpecularMaterial specular =new SpecularMaterial (new SolidColorBrush (Color.FromScRgb (1.0f - phong.specularColor.a, phong.specularColor.r, phong.specularColor.g, phong.specularColor.b)), phong.cosPower) ;
                        // no more attributes
                        matGroup.Children.Add (specular) ;

                        //See Lambert
                        //EmissiveMaterial emissive =new EmissiveMaterial (new SolidColorBrush (Color.FromScRgb (1.0f - phong.incandescence.a, phong.incandescence.r, phong.incandescence.g, phong.incandescence.b))) ;
                        //// no more attributes
                        //matGroup.Children.Add (emissive) ;
                    } catch {
                    }

                    // todo
                    //try {
                    //    MFnBlinnShader phong =new MFnBlinnShader (connections [u].node) ;

                    //    //See Lambert
                    //    //SolidColorBrush brush =new SolidColorBrush (Color.FromScRgb (1.0f - phong.transparency.r, phong.color.r, phong.color.g, phong.color.b)) ;
                    //    //brush.Opacity =1.0f - phong.transparency.r ;
                    //    //DiffuseMaterial diffuse =new DiffuseMaterial (brush) ;
                    //    //diffuse.AmbientColor = Color.FromScRgb (1.0f - phong.ambientColor.a, phong.ambientColor.r, phong.ambientColor.g, phong.ambientColor.b) ;
                    //    //// no more attributes
                    //    //matGroup.Children.Add (diffuse) ;

                    //    //See Lambert
                    //    //EmissiveMaterial emissive =new EmissiveMaterial (new SolidColorBrush (Color.FromScRgb (1.0f - phong.incandescence.a, phong.incandescence.r, phong.incandescence.g, phong.incandescence.b))) ;
                    //    //// no more attributes
                    //    //matGroup.Children.Add (emissive) ;
                    //} catch {
                    //}
                }
            }

            // Default to Blue
            if ( matGroup.Children.Count == 0 )
                 matGroup.Children.Add (new DiffuseMaterial (new SolidColorBrush (Color.FromRgb (0, 0, 255)))) ;
            return (matGroup) ;
        }
Пример #18
0
        /// <summary>
        /// The part may be created in an arbitrary thread.  When that happens, wpf specific objects can't be stored (they aren't threadsafe).
        /// But this method is complex enough that I don't want to duplicate bits of it
        /// </summary>
        private Model3DGroup CreateGeometry(bool isFinal, bool shouldCommitWPF)
        {
            #region Materials

            // Front Material
            MaterialGroup frontMaterial = new MaterialGroup();
            DiffuseMaterial diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.Thruster));
            if (shouldCommitWPF)
            {
                this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.Thruster));
            }
            frontMaterial.Children.Add(diffuse);

            SpecularMaterial specular = WorldColors.ThrusterSpecular;
            if (shouldCommitWPF)
            {
                this.MaterialBrushes.Add(new MaterialColorProps(specular));
            }
            frontMaterial.Children.Add(specular);

            // Back Material
            MaterialGroup backMaterial = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.ThrusterBack));
            if (shouldCommitWPF)
            {
                this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.ThrusterBack));
            }
            backMaterial.Children.Add(diffuse);

            // Glow
            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                frontMaterial.Children.Add(selectionEmissive);
                if (shouldCommitWPF)
                {
                    base.SelectionEmissives.Add(selectionEmissive);
                }

                selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                backMaterial.Children.Add(selectionEmissive);
                if (shouldCommitWPF)
                {
                    base.SelectionEmissives.Add(selectionEmissive);
                }
            }

            #endregion

            GeometryModel3D geometry;
            List<TubeRingBase> rings;
            Transform3DGroup transform;
            double scale;

            int domeSegments = isFinal ? 2 : 10;
            int cylinderSegments = isFinal ? 6 : 35;

            Model3DGroup retVal = new Model3DGroup();

            switch (this.ThrusterType)
            {
                case ThrusterType.One:
                    #region OneWay

                    // Geometry 1
                    geometry = new GeometryModel3D();
                    geometry.Material = frontMaterial;
                    geometry.BackMaterial = backMaterial;

                    rings = GetThrusterRings1Full(domeSegments);

                    scale = 1d / rings.Sum(o => o.DistFromPrevRing);		// Scale this so the height is 1
                    transform = new Transform3DGroup();
                    transform.Children.Add(new ScaleTransform3D(scale, scale, scale));

                    geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, true, transform);
                    retVal.Children.Add(geometry);

                    #endregion
                    break;

                case ThrusterType.Two:
                    #region TwoWay

                    // Geometry 1
                    geometry = new GeometryModel3D();
                    geometry.Material = frontMaterial;
                    geometry.BackMaterial = backMaterial;

                    rings = GetThrusterRings2Full();

                    scale = 1d / rings.Sum(o => o.DistFromPrevRing);		// Scale this so the height is 1
                    transform = new Transform3DGroup();
                    transform.Children.Add(new ScaleTransform3D(scale, scale, scale));

                    geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, true, transform);
                    retVal.Children.Add(geometry);

                    // This will make a glass tube around the thruster
                    //MaterialGroup testMaterial = new MaterialGroup();
                    //testMaterial.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("#30FFFFFF"))));

                    //geometry = new GeometryModel3D();
                    //geometry.Material = testMaterial;
                    //geometry.BackMaterial = testMaterial;
                    //geometry.Geometry = UtilityWPF.GetCylinder_AlongX(20, RADIUSPERCENTOFSCALE, 1, new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90)));
                    //retVal.Children.Add(geometry);

                    #endregion
                    break;

                case ThrusterType.Two_One:
                    #region Two_One

                    // Geometry 1
                    geometry = new GeometryModel3D();
                    geometry.Material = frontMaterial;
                    geometry.BackMaterial = backMaterial;

                    rings = GetThrusterRings2Full();

                    scale = 1d / rings.Sum(o => o.DistFromPrevRing);		// Scale this so the height is 1
                    transform = new Transform3DGroup();
                    transform.Children.Add(new ScaleTransform3D(scale, scale, scale));

                    geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, true, transform);
                    retVal.Children.Add(geometry);

                    // Geometry 2
                    geometry = new GeometryModel3D();
                    geometry.Material = frontMaterial;
                    geometry.BackMaterial = backMaterial;

                    rings = GetThrusterRings1Half(false, domeSegments);
                    transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90)));
                    transform.Children.Add(new TranslateTransform3D(-scale * rings.Sum(o => o.DistFromPrevRing), 0, 0));
                    geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, false, transform);

                    retVal.Children.Add(geometry);

                    #endregion
                    break;

                case ThrusterType.Two_Two:
                    #region Two_Two

                    // Geometry Model1
                    geometry = new GeometryModel3D();
                    geometry.Material = frontMaterial;
                    geometry.BackMaterial = backMaterial;

                    rings = GetThrusterRings2Full();

                    scale = 1d / rings.Sum(o => o.DistFromPrevRing);		// Scale this so the height is 1
                    transform = new Transform3DGroup();
                    transform.Children.Add(new ScaleTransform3D(scale, scale, scale));

                    geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, true, transform);

                    retVal.Children.Add(geometry);

                    // Geometry Model2
                    geometry = new GeometryModel3D();
                    geometry.Material = frontMaterial;
                    geometry.BackMaterial = backMaterial;

                    transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90)));
                    geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, true, transform);

                    retVal.Children.Add(geometry);

                    #endregion
                    break;

                case ThrusterType.Two_Two_One:
                    #region Two_Two_One

                    // Geometry Model1
                    geometry = new GeometryModel3D();
                    geometry.Material = frontMaterial;
                    geometry.BackMaterial = backMaterial;

                    rings = GetThrusterRings2Full();

                    scale = 1d / rings.Sum(o => o.DistFromPrevRing);		// Scale this so the height is 1
                    transform = new Transform3DGroup();
                    transform.Children.Add(new ScaleTransform3D(scale, scale, scale));

                    geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, true, transform);

                    retVal.Children.Add(geometry);

                    // Geometry Model2
                    geometry = new GeometryModel3D();
                    geometry.Material = frontMaterial;
                    geometry.BackMaterial = backMaterial;

                    transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90)));
                    geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, true, transform);

                    retVal.Children.Add(geometry);

                    // Geometry Model3
                    geometry = new GeometryModel3D();
                    geometry.Material = frontMaterial;
                    geometry.BackMaterial = backMaterial;

                    rings = GetThrusterRings1Half(false, domeSegments);
                    transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), 90)));
                    transform.Children.Add(new TranslateTransform3D(0, -scale * rings.Sum(o => o.DistFromPrevRing), 0));
                    geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, false, transform);

                    retVal.Children.Add(geometry);

                    #endregion
                    break;

                case ThrusterType.Two_Two_Two:
                    #region Two_Two_Two

                    // Geometry Model1
                    geometry = new GeometryModel3D();
                    geometry.Material = frontMaterial;
                    geometry.BackMaterial = backMaterial;

                    rings = GetThrusterRings2Full();

                    scale = 1d / rings.Sum(o => o.DistFromPrevRing);		// Scale this so the height is 1
                    transform = new Transform3DGroup();
                    transform.Children.Add(new ScaleTransform3D(scale, scale, scale));

                    geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, true, transform);

                    retVal.Children.Add(geometry);

                    // Geometry Model2
                    geometry = new GeometryModel3D();
                    geometry.Material = frontMaterial;
                    geometry.BackMaterial = backMaterial;

                    transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90)));
                    geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, true, transform);

                    retVal.Children.Add(geometry);

                    // Geometry Model3
                    geometry = new GeometryModel3D();
                    geometry.Material = frontMaterial;
                    geometry.BackMaterial = backMaterial;

                    transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), 90)));
                    geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, true, transform);

                    retVal.Children.Add(geometry);

                    #endregion
                    break;

                case ThrusterType.Custom:
                    #region Custom

                    if (this.ThrusterDirections.Length == 1)
                    {
                        #region One

                        geometry = new GeometryModel3D();
                        geometry.Material = frontMaterial;
                        geometry.BackMaterial = backMaterial;

                        rings = GetThrusterRings1Full(domeSegments);

                        scale = 1d / rings.Sum(o => o.DistFromPrevRing);		// Scale this so the height is 1
                        transform = new Transform3DGroup();
                        transform.Children.Add(new ScaleTransform3D(scale, scale, scale));
                        transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRotation(new Vector3D(0, 0, 1), this.ThrusterDirections[0]))));

                        geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, true, transform);
                        retVal.Children.Add(geometry);

                        #endregion
                    }
                    else
                    {
                        #region Many

                        scale = 1d / GetThrusterRings2Full().Sum(o => o.DistFromPrevRing);		// Scale this so the height is 1 (need to use full rings so scale is accurate)
                        double offset = -scale * GetThrusterRings1Half(true, domeSegments).Sum(o => o.DistFromPrevRing);		// get the height of half1 which is a bit smaller than half2

                        rings = GetThrusterRings1Half2(true, domeSegments);		// this is what will actually be drawn

                        for (int cntr = 0; cntr < this.ThrusterDirections.Length; cntr++)
                        {
                            geometry = new GeometryModel3D();
                            geometry.Material = frontMaterial;
                            geometry.BackMaterial = backMaterial;

                            transform = new Transform3DGroup();
                            transform.Children.Add(new ScaleTransform3D(scale, scale, scale));
                            transform.Children.Add(new TranslateTransform3D(0, 0, offset));		// this translation makes the thruster come out of origin (otherwise it would be centered funny on origin)
                            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRotation(new Vector3D(0, 0, 1), this.ThrusterDirections[cntr]))));

                            geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, false, transform);

                            retVal.Children.Add(geometry);
                        }

                        #endregion
                    }

                    #endregion
                    break;

                default:
                    throw new ApplicationException("Unknown ThrusterType: " + this.ThrusterType.ToString());
            }

            // Remember the points
            if (isFinal)
            {
                _pointsForHull = UtilityWPF.GetPointsFromMesh(retVal);
            }

            // Transform
            retVal.Transform = GetTransformForGeometry(isFinal);

            // Exit Function
            return retVal;
        }
Пример #19
0
        private Model3DGroup CreateGeometry(bool isFinal)
        {
            Model3DGroup retVal = new Model3DGroup();

            GeometryModel3D geometry;
            MaterialGroup material;
            DiffuseMaterial diffuse;
            SpecularMaterial specular;
            EmissiveMaterial emissive;

            int domeSegments = isFinal ? 2 : 10;
            int cylinderSegments = isFinal ? 6 : 35;

            #region Mount Box

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.GunBase));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.GunBase));
            material.Children.Add(diffuse);
            specular = WorldColors.GunBaseSpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                this.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            geometry.Geometry = UtilityWPF.GetCube(new Point3D(-.115, -.1, -.5), new Point3D(.115, .1, -.1));

            retVal.Children.Add(geometry);

            #endregion

            #region Barrel

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.GunBarrel));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.GunBarrel));
            material.Children.Add(diffuse);
            specular = WorldColors.GunBarrelSpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                this.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            const double OUTERRADIUS = .045;
            const double INNERRADIUS = .04;

            List<TubeRingBase> rings = new List<TubeRingBase>();

            rings.Add(new TubeRingRegularPolygon(0, false, OUTERRADIUS * .33, OUTERRADIUS * .33, false));		// Start at the base of the barrel
            rings.Add(new TubeRingRegularPolygon(.69, false, OUTERRADIUS * .33, OUTERRADIUS * .33, false));		// This is the tip of the barrel
            //rings.Add(new TubeRingRegularPolygon(0, false, INNERRADIUS, INNERRADIUS, false));		// Curl to the inside
            //rings.Add(new TubeRingRegularPolygon(-.75d, false, INNERRADIUS, INNERRADIUS, false));		// Loop back to the base

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, false, new TranslateTransform3D(0, 0, -.49d));

            retVal.Children.Add(geometry);

            #endregion

            #region Dish

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.BeamGunDish));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.BeamGunDish));
            material.Children.Add(diffuse);
            specular = WorldColors.BeamGunDishSpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                this.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            rings = new List<TubeRingBase>();
            rings.Add(new TubeRingDome(0, false, domeSegments));
            rings.Add(new TubeRingRegularPolygon(.16, false, OUTERRADIUS * 3.5d, OUTERRADIUS * 3.5d, false));
            rings.Add(new TubeRingDome(-.08, false, domeSegments));		// concave dish

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, false, new TranslateTransform3D(0, 0, -.12d));

            retVal.Children.Add(geometry);

            #endregion

            #region Focus Crystal

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.BeamGunCrystal));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.BeamGunCrystal));
            material.Children.Add(diffuse);
            specular = WorldColors.BeamGunCrystalSpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);
            emissive = WorldColors.BeamGunCrystalEmissive;
            this.MaterialBrushes.Add(new MaterialColorProps(emissive));
            material.Children.Add(emissive);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                this.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            //rings = new List<TubeRingBase>();
            //rings.Add(new TubeRingPoint(0, false));
            //rings.Add(new TubeRingRegularPolygon(.667, false, OUTERRADIUS * 2d, OUTERRADIUS * 2d, false));
            //rings.Add(new TubeRingPoint(1.33, false));

            //geometry.Geometry = UtilityWPF.GetMultiRingedTube(3, rings, true, false, new TranslateTransform3D(0, 0, .25d));

            List<TubeRingDefinition_ORIG> rings2 = new List<TubeRingDefinition_ORIG>();
            rings2.Add(new TubeRingDefinition_ORIG(0, false));
            rings2.Add(new TubeRingDefinition_ORIG(OUTERRADIUS * 3d, OUTERRADIUS * 3d, .067d, true, false));		// I think the old tube definition is diameter instead of radius, so needs to be doubled
            rings2.Add(new TubeRingDefinition_ORIG(.133, false));

            geometry.Geometry = UtilityWPF.GetMultiRingedTube_ORIG(5, rings2, false, false);
            geometry.Transform = new TranslateTransform3D(0, 0, .15d);

            retVal.Children.Add(geometry);

            #endregion

            #region Trim

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.BeamGunTrim));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.BeamGunTrim));
            material.Children.Add(diffuse);
            specular = WorldColors.BeamGunTrimSpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                this.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            geometry.Geometry = UtilityWPF.GetCube(new Point3D(-.095, -.11, -.45), new Point3D(.095, .11, -.15));

            retVal.Children.Add(geometry);

            #endregion

            // Transform
            retVal.Transform = GetTransformForGeometry(isFinal);

            // Exit Function
            return retVal;
        }
Пример #20
0
        private GeometryModel3D CreateGeometry(bool isFinal)
        {
            DiffuseMaterial diffuse = WorldColorsArco.SensorVision_Any_Diffuse.Value;
            SpecularMaterial specular = WorldColorsArco.SensorVision_Any_Specular.Value;
            if (!isFinal)
            {
                diffuse = diffuse.Clone();      // cloning, because the editor will manipulate the brush, and WorldColors is handing out a shared brush
                specular = specular.Clone();
            }

            MaterialGroup material = new MaterialGroup();
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColorsArco.SensorVision_Any_Color));
            material.Children.Add(diffuse);
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                base.SelectionEmissives.Add(selectionEmissive);
            }

            GeometryModel3D retVal = new GeometryModel3D();
            retVal.Material = material;
            retVal.BackMaterial = material;

            int segments = isFinal ? 6 : 35;

            double radius = ((this.Scale.X * SIZEPERCENTOFSCALE_XY) + (this.Scale.Y * SIZEPERCENTOFSCALE_XY)) / 2d;
            double height = this.Scale.Z * SIZEPERCENTOFSCALE_Z;
            RotateTransform3D rotateTransform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90));     // this needs to be along Z instead of X

            retVal.Geometry = UtilityWPF.GetCylinder_AlongX(segments, radius, height, rotateTransform);

            // Transform
            retVal.Transform = GetTransformForGeometry(isFinal);

            // Exit Function
            return retVal;
        }
Пример #21
0
        private Model3DGroup CreateGeometry(bool isFinal)
        {
            const double INSIDEPOINTRADIUS = .45d;

            ScaleTransform3D scaleTransform = new ScaleTransform3D(SCALE, SCALE, SCALE);

            Model3DGroup retVal = new Model3DGroup();

            GeometryModel3D geometry;
            MaterialGroup material;
            DiffuseMaterial diffuse;
            SpecularMaterial specular;

            Transform3DGroup transformGroup = new Transform3DGroup();
            transformGroup.Children.Add(scaleTransform);

            #region Insides

            if (!isFinal)
            {
                Model3D[] insideModels = CreateInsideVisuals(INSIDEPOINTRADIUS, this.MaterialBrushes, base.SelectionEmissives, scaleTransform);
                retVal.Children.AddRange(insideModels);
            }

            #endregion

            #region Lights

            // Neat effect, but it makes my fan spin up, and won't slow back down.  Need to add an animation property to the options
            // class (and listen for when it toggles)

            //if (!isFinal)
            //{
            //    int numLights = 1 + this.Options.Random.Next(3);

            //    for (int cntr = 0; cntr < numLights; cntr++)
            //    {
            //        PointLight light = new PointLight();
            //        light.Color = Colors.Black;
            //        light.Range = SCALE * INSIDEPOINTRADIUS * 2d;
            //        light.LinearAttenuation = 1d;

            //        transformGroup = new Transform3DGroup();
            //        transformGroup.Children.Add(new TranslateTransform3D(Math3D.GetRandomVectorSpherical(this.Options.Random, INSIDEPOINTRADIUS)));
            //        transformGroup.Children.Add(scaleTransform);
            //        light.Transform = transformGroup;

            //        retVal.Children.Add(light);

            //        ColorAnimation animation = new ColorAnimation();
            //        animation.From = UtilityWPF.ColorFromHex("CC1266");
            //        animation.To = Colors.Black;
            //        animation.Duration = new Duration(TimeSpan.FromSeconds(1d + (this.Options.Random.NextDouble() * 5d)));
            //        animation.AutoReverse = true;
            //        animation.RepeatBehavior = RepeatBehavior.Forever;
            //        animation.AccelerationRatio = .5d;
            //        animation.DecelerationRatio = .5d;

            //        light.BeginAnimation(PointLight.ColorProperty, animation);
            //    }
            //}

            #endregion

            #region Outer Shell

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            Color shellColor = WorldColors.Brain;
            if (!isFinal)
            {
                shellColor = UtilityWPF.AlphaBlend(shellColor, Colors.Transparent, .75d);
            }
            diffuse = new DiffuseMaterial(new SolidColorBrush(shellColor));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, shellColor));
            material.Children.Add(diffuse);

            specular = WorldColors.BrainSpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                base.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            transformGroup = new Transform3DGroup();
            transformGroup.Children.Add(scaleTransform);
            transformGroup.Children.Add(new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRandomRotation())));		// this is just so it's not obvious that the brains are shared visuals

            geometry.Geometry = SharedVisuals.BrainMesh;		// SharedVisuals keeps track of which thread made the request
            geometry.Transform = transformGroup;

            retVal.Children.Add(geometry);

            #endregion

            // Transform
            retVal.Transform = GetTransformForGeometry(isFinal);

            // Exit Function
            return retVal;
        }
Пример #22
0
        private Model3DGroup GetHighlightModel3D(Gesture g, List<GestureFrame> fs)
        {
            // Create material
              EmissiveMaterial material = new EmissiveMaterial(new SolidColorBrush() { Color = Colors.White, Opacity = 0.3 });

              Model3DGroup modelGroup = new Model3DGroup();
              foreach (GestureFrame f in fs)
              {
            foreach (GestureFrameCell fc in f.FrontCells.Where(fc => fc.IsHotspot == true))
            {
              int fcIndex = Array.IndexOf(f.FrontCells, fc);
              foreach (GestureFrameCell sc in f.SideCells.Where(
              sc => sc.IsHotspot == true && (int)(Array.IndexOf(f.SideCells, sc) / 20) == (int)(fcIndex / 20)))
              {
            // Init mesh
            MeshBuilder meshBuilder = new MeshBuilder(false, false);
            // Make cube and add to mesh
            double y = (fc.LeftCM + fc.RightCM) / 2;
            double z = (fc.TopCM + fc.BottomCM) / 2;
            double x = (sc.LeftCM + sc.RightCM) / 2;
            Point3D cubeCenter = new Point3D(x, y, z);
            meshBuilder.AddBox(cubeCenter, 15, 15, 15);
            // Create and freeze mesh
            var mesh = meshBuilder.ToMesh(true);
            // Create models
            modelGroup.Children.Add(new GeometryModel3D(mesh, material));
              }
            }
              }
              return modelGroup;
        }
Пример #23
0
        private Model3DGroup CreateGeometry(bool isFinal)
        {
            int domeSegments = isFinal ? 2 : 10;
            int cylinderSegments = isFinal ? 6 : 35;

            Model3DGroup retVal = new Model3DGroup();

            GeometryModel3D geometry;
            MaterialGroup material;
            DiffuseMaterial diffuse;
            SpecularMaterial specular;

            #region Insides

            if (!isFinal)
            {
                ScaleTransform3D scaleTransform = new ScaleTransform3D(HEIGHT, HEIGHT, HEIGHT);

                //TODO: This caps them to a sphere.  It doesn't look too bad, but could be better
                Model3D[] insideModels = BrainDesign.CreateInsideVisuals(.4, this.MaterialBrushes, base.SelectionEmissives, scaleTransform);

                retVal.Children.AddRange(insideModels);
            }

            #endregion
            #region Outer Shell

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            Color shellColor = WorldColors.Brain;
            if (!isFinal)
            {
                shellColor = UtilityWPF.AlphaBlend(shellColor, Colors.Transparent, .75d);
            }
            diffuse = new DiffuseMaterial(new SolidColorBrush(shellColor));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, shellColor));
            material.Children.Add(diffuse);

            specular = WorldColors.BrainSpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                base.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            List<TubeRingBase> rings = new List<TubeRingBase>();

            rings.Add(new TubeRingRegularPolygon(0, false, RADIUSPERCENTOFSCALE_NARROW, RADIUSPERCENTOFSCALE_NARROW, true));
            rings.Add(new TubeRingRegularPolygon(HEIGHT, false, RADIUSPERCENTOFSCALE_WIDE, RADIUSPERCENTOFSCALE_WIDE, true));

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, true);

            retVal.Children.Add(geometry);

            #endregion

            retVal.Transform = GetTransformForGeometry(isFinal);

            return retVal;
        }
Пример #24
0
        /// <summary>
        /// Replaces any instances of the sentinal brush with the internal brush
        /// </summary>
        /// <param name="material">The material to look through</param>
        private void SwapInCyclicBrush(Material material)
        {
            int numMaterialsSwapped        = 0;
            Stack <Material> materialStack = new Stack <Material>();

            materialStack.Push(material);

            Brush internalBrush = (CacheMode as BitmapCache != null) ? (Brush)InternalBitmapCacheBrush : (Brush)InternalVisualBrush;

            while (materialStack.Count > 0)
            {
                Material currMaterial = materialStack.Pop();

                if (currMaterial is DiffuseMaterial)
                {
                    DiffuseMaterial diffMaterial = (DiffuseMaterial)currMaterial;
                    if ((Boolean)diffMaterial.GetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty))
                    {
                        diffMaterial.Brush = internalBrush;
                        numMaterialsSwapped++;
                    }
                }
                else if (currMaterial is EmissiveMaterial)
                {
                    EmissiveMaterial emmMaterial = (EmissiveMaterial)currMaterial;
                    if ((Boolean)emmMaterial.GetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty))
                    {
                        emmMaterial.Brush = internalBrush;
                        numMaterialsSwapped++;
                    }
                }
                else if (currMaterial is SpecularMaterial)
                {
                    SpecularMaterial specMaterial = (SpecularMaterial)currMaterial;
                    if ((Boolean)specMaterial.GetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty))
                    {
                        specMaterial.Brush = internalBrush;
                        numMaterialsSwapped++;
                    }
                }
                else if (currMaterial is MaterialGroup)
                {
                    MaterialGroup matGroup = (MaterialGroup)currMaterial;

                    // the IsVisualHostMaterialProperty should not be set on a MaterialGroup - verify that
                    if ((Boolean)matGroup.GetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty))
                    {
                        throw new ArgumentException(SR.Get(SRID.Viewport2DVisual3D_MaterialGroupIsInteractiveMaterial), "material");
                    }

                    // iterate over the children and put them on the stack of materials to modify
                    MaterialCollection children = matGroup.Children;

                    if (children != null)
                    {
                        for (int i = 0, count = children.Count; i < count; i++)
                        {
                            Material m = children[i];
                            materialStack.Push(m);
                        }
                    }
                }
                else
                {
                    Invariant.Assert(true, "Unexpected Material type encountered.  V2DV3D handles DiffuseMaterial, EmissiveMaterial, SpecularMaterial, and MaterialGroup.");
                }
            }

            // throw if there is more than 1 interactive material
            if (numMaterialsSwapped > 1)
            {
                throw new ArgumentException(SR.Get(SRID.Viewport2DVisual3D_MultipleInteractiveMaterials), "material");
            }
        }
Пример #25
0
        public SpaceStation(Point3D position, World world, int materialID, Quaternion orientation)
        {
            //TODO:  Windows, lights

            MaterialGroup material = null;
            GeometryModel3D geometry = null;
            Model3DGroup models = new Model3DGroup();

            // These are random, so pull them once
            Color hullColor = WorldColors.SpaceStationHull;
            SpecularMaterial hullSpecular = WorldColors.SpaceStationHullSpecular;

            double radius = 8;
            this.Radius = radius * 1.25;		// this is the extremes of the force field
            double mass = 10000;

            #region Interior Visuals

            // These are visuals that will stay oriented to the ship, but don't count in collision calculations

            #region Hull - Torus

            // Material
            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(hullColor)));
            material.Children.Add(hullSpecular);

            // Geometry Model
            geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = material;
            geometry.Geometry = UtilityWPF.GetTorus(30, 10, radius * .15, radius);

            // Model Group
            models.Children.Add(geometry);

            #endregion
            #region Hull - Spine

            // Material
            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(hullColor)));
            material.Children.Add(hullSpecular);

            // Geometry Model
            geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = material;
            geometry.Geometry = UtilityWPF.GetCylinder_AlongX(20, radius * .075, radius * .66);
            Transform3DGroup spineTransform2 = new Transform3DGroup();
            spineTransform2.Children.Add(new TranslateTransform3D(radius * .1, 0, 0));
            spineTransform2.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, -1, 0), 90)));
            geometry.Transform = spineTransform2;

            // Model Group
            models.Children.Add(geometry);

            #endregion
            #region Hull - Spokes

            for (int cntr = 0; cntr < 3; cntr++)
            {
                // Material
                material = new MaterialGroup();
                material.Children.Add(new DiffuseMaterial(new SolidColorBrush(hullColor)));
                material.Children.Add(hullSpecular);

                // Geometry Model
                geometry = new GeometryModel3D();
                geometry.Material = material;
                geometry.BackMaterial = material;
                geometry.Geometry = UtilityWPF.GetCylinder_AlongX(20, radius * .05, radius * .9);
                Transform3DGroup spokeTransform = new Transform3DGroup();
                spokeTransform.Children.Add(new TranslateTransform3D(radius * .45, 0, 0));     // the cylinder is built along the y axis, but is centered halfway
                spokeTransform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), cntr * 120d)));
                geometry.Transform = spokeTransform;

                // Model Group
                models.Children.Add(geometry);
            }

            #endregion
            #region Hull - Top inner

            // Material
            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.White, hullColor, .25d))));
            material.Children.Add(hullSpecular);

            // Geometry Model
            geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = material;
            geometry.Geometry = UtilityWPF.GetCylinder_AlongX(20, radius * .11, radius * .01);
            Transform3DGroup spokeTransform2 = new Transform3DGroup();
            spokeTransform2.Children.Add(new TranslateTransform3D((radius * .51) - .5, 0, 0));     // the cylinder is built along the x axis, but is centered halfway
            spokeTransform2.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, -1, 0), 90d)));
            geometry.Transform = spokeTransform2;

            // Model Group
            models.Children.Add(geometry);

            #endregion
            #region Hull - Top outer

            //TODO: The two cylinders cause flicker, come up with the definition of a ring (or do some texture mapping - if so, see if the texture can be vector graphics)

            // Material
            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.Black, hullColor, .25d))));
            material.Children.Add(hullSpecular);

            // Geometry Model
            geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = material;
            geometry.Geometry = UtilityWPF.GetCylinder_AlongX(20, radius * .12, radius * .0095);
            Transform3DGroup spokeTransform3 = new Transform3DGroup();
            spokeTransform3.Children.Add(new TranslateTransform3D((radius * .5) - .5, 0, 0));     // the cylinder is built along the y axis, but is centered halfway
            spokeTransform3.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, -1, 0), 90d)));
            geometry.Transform = spokeTransform3;

            // Model Group
            models.Children.Add(geometry);

            #endregion

            #endregion

            #region Glass

            // Material
            //NOTE:  There is an issue with drawing objects inside a semitransparent object - they have to be added in order (so stuff added after a semitransparent won't be visible behind it)
            Brush skinBrush = new SolidColorBrush(WorldColors.SpaceStationGlass);  // the skin is semitransparent, so you can see the components inside

            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(skinBrush));
            material.Children.Add(WorldColors.SpaceStationGlassSpecular_Front);     // more reflective (and white light)

            MaterialGroup backMaterial = new MaterialGroup();
            backMaterial.Children.Add(new DiffuseMaterial(skinBrush));
            backMaterial.Children.Add(WorldColors.SpaceStationGlassSpecular_Back);       // dark light, and not very reflective

            // Geometry Model
            geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = backMaterial;
            geometry.Geometry = UtilityWPF.GetSphere_LatLon(6, radius, radius, radius * .25);

            // Model Group
            models.Children.Add(geometry);

            #endregion

            #region Exterior Visuals

            // There is a bug in WPF where visuals added after a semitransparent one won't show inside.  So if you want to add exterior
            // bits that aren't visible inside, this would be the place

            #endregion

            #region Force Field

            Vector3D forceFieldSize = new Vector3D(radius * 1.25, radius * 1.25, radius * .75);

            // Material
            _forceField_DiffuseMaterial = new DiffuseMaterial(null);//Brushes.Transparent);		// the momentarily brush will change when there is a collision
            _forceField_EmissiveFront = new EmissiveMaterial(null);//Brushes.Transparent);
            _forceField_EmissiveRear = new EmissiveMaterial(null);//Brushes.Transparent);

            material = new MaterialGroup();
            material.Children.Add(_forceField_DiffuseMaterial);
            material.Children.Add(_forceField_EmissiveFront);

            backMaterial = new MaterialGroup();
            backMaterial.Children.Add(_forceField_DiffuseMaterial);
            backMaterial.Children.Add(_forceField_EmissiveRear);

            // Geometry Model
            geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = backMaterial;
            geometry.Geometry = UtilityWPF.GetSphere_LatLon(6, forceFieldSize.X, forceFieldSize.Y, forceFieldSize.Z);

            // Model Group
            models.Children.Add(geometry);

            #endregion

            this.Model = models;

            // Model Visual
            ModelVisual3D model = new ModelVisual3D();        // this is the expensive one, so as few of these should be made as possible
            model.Content = models;

            #region Physics Body

            Transform3DGroup transform = new Transform3DGroup();
            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(orientation)));
            transform.Children.Add(new TranslateTransform3D(position.ToVector()));

            using (CollisionHull hull = CollisionHull.CreateSphere(world, 0, forceFieldSize, null))
            {
                this.PhysicsBody = new Body(hull, transform.Value, mass, new Visual3D[] { model });
                this.PhysicsBody.MaterialGroupID = materialID;
                this.PhysicsBody.LinearDamping = .01f;
                this.PhysicsBody.AngularDamping = new Vector3D(.001f, .001f, .001f);
            }

            #endregion

            this.CreationTime = DateTime.UtcNow;
        }
Пример #26
0
 private GeometryModel3D MakeSelectedModel()
 {
     MeshGeometry3D m1 = (MeshGeometry3D)Core.Instance.Models["Road"];
     EmissiveMaterial glow = new EmissiveMaterial(new SolidColorBrush(_Color));
     DiffuseMaterial material = new DiffuseMaterial(new SolidColorBrush(_Color));
     GeometryModel3D model1 = new GeometryModel3D(m1, glow);
     model1.Transform = new ScaleTransform3D(1.05, 1.05, 1.05);
     return model1;
 }
Пример #27
0
        private Model3DGroup CreateGeometry(bool isFinal)
        {
            double SQRT2 = Math.Sqrt(2d);
            double SCALE = .5d / (SQRT2 * .5d);

            Model3DGroup retVal = new Model3DGroup();

            GeometryModel3D geometry;
            MaterialGroup material;
            DiffuseMaterial diffuse;
            SpecularMaterial specular;

            #region Main Box

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.SelfRepairBase));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.SelfRepairBase));
            material.Children.Add(diffuse);
            specular = WorldColors.SelfRepairBaseSpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                this.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            List<TubeRingBase> rings = new List<TubeRingBase>();
            rings.Add(new TubeRingRegularPolygon(0d, false, SQRT2 * .35d * SCALE, .4d * SCALE, true));
            rings.Add(new TubeRingRegularPolygon(.18d * SCALE, false, SQRT2 * .5d * SCALE, .5d * SCALE, true));
            rings.Add(new TubeRingRegularPolygon(.24d * SCALE, false, SQRT2 * .5d * SCALE, .5d * SCALE, true));
            rings.Add(new TubeRingRegularPolygon(.18d * SCALE, false, SQRT2 * .35d * SCALE, .4d * SCALE, true));
            geometry.Geometry = UtilityWPF.GetMultiRingedTube(7, rings, true, true);

            retVal.Children.Add(geometry);

            #endregion

            #region Cross

            for (int cntr = 0; cntr <= 1; cntr++)
            {
                geometry = new GeometryModel3D();
                material = new MaterialGroup();
                diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.SelfRepairCross));
                this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.SelfRepairCross));
                material.Children.Add(diffuse);
                specular = WorldColors.SelfRepairCrossSpecular;
                this.MaterialBrushes.Add(new MaterialColorProps(specular));
                material.Children.Add(specular);

                if (!isFinal)
                {
                    EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                    material.Children.Add(selectionEmissive);
                    this.SelectionEmissives.Add(selectionEmissive);
                }

                geometry.Material = material;
                geometry.BackMaterial = material;

                double halfWidth = cntr == 0 ? .1d : .3d;
                double halfHeight = cntr == 0 ? .3d : .1d;
                halfWidth *= SCALE;
                halfHeight *= SCALE;

                geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-halfWidth, -halfHeight, -.32d * SCALE), new Point3D(halfWidth, halfHeight, .32d * SCALE));

                retVal.Children.Add(geometry);
            }

            #endregion

            // Transform
            retVal.Transform = GetTransformForGeometry(isFinal);

            // Exit Function
            return retVal;
        }
Пример #28
0
        internal static Model3D[] CreateInsideVisuals(double radius, List<MaterialColorProps> materialBrushes, List<EmissiveMaterial> selectionEmissives, ScaleTransform3D scaleTransform)
        {
            List<Point3D[]> insidePoints = new List<Point3D[]>();
            for (int cntr = 0; cntr < 3; cntr++)
            {
                GetLineBranch(insidePoints, Math3D.GetRandomVector_Spherical(radius).ToPoint(), radius, radius * .8d, .33d, 4);
            }

            Random rand = StaticRandom.GetRandomForThread();

            List<Model3D> retVal = new List<Model3D>();

            foreach (Point3D[] lineSegment in insidePoints)
            {
                GeometryModel3D geometry = new GeometryModel3D();
                MaterialGroup material = new MaterialGroup();

                Color color = WorldColors.BrainInsideStrand;		// storing this, because it's random
                DiffuseMaterial diffuse = new DiffuseMaterial(new SolidColorBrush(color));
                materialBrushes.Add(new MaterialColorProps(diffuse, color));
                material.Children.Add(diffuse);

                SpecularMaterial specular = WorldColors.BrainInsideStrandSpecular;
                materialBrushes.Add(new MaterialColorProps(specular));
                material.Children.Add(specular);

                //if (!isFinal)
                //{
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                selectionEmissives.Add(selectionEmissive);
                //}

                geometry.Material = material;
                geometry.BackMaterial = material;

                Vector3D line = lineSegment[1] - lineSegment[0];
                double lineLength = line.Length;
                double halfLength = lineLength * .5d;
                double widestWidth = lineLength * .033d;

                List<TubeRingBase> rings = new List<TubeRingBase>();
                rings.Add(new TubeRingPoint(0, false));
                rings.Add(new TubeRingRegularPolygon(halfLength, false, widestWidth, widestWidth, false));
                rings.Add(new TubeRingPoint(halfLength, false));

                Quaternion zRot = new Quaternion(new Vector3D(0, 0, 1), 360d * rand.NextDouble()).ToUnit();
                Quaternion rotation = Math3D.GetRotation(new Vector3D(0, 0, 1), line).ToUnit();

                Transform3DGroup transformGroup = new Transform3DGroup();
                transformGroup.Children.Add(new RotateTransform3D(new QuaternionRotation3D(Quaternion.Multiply(rotation, zRot))));
                transformGroup.Children.Add(new TranslateTransform3D(lineSegment[0].ToVector()));
                transformGroup.Children.Add(scaleTransform);

                geometry.Geometry = UtilityWPF.GetMultiRingedTube(3, rings, true, false, transformGroup);

                retVal.Add(geometry);
            }

            return retVal.ToArray();
        }
        private Model3DGroup CreateGeometry(bool isFinal)
        {
            Model3DGroup retVal = new Model3DGroup();

            GeometryModel3D geometry;
            MaterialGroup material;
            DiffuseMaterial diffuse;
            SpecularMaterial specular;

            MeshGeometry3D capGeometry, sideGeometry;
            GetShape(out capGeometry, out sideGeometry, this.Vertices.ToList(), THICKNESS, .95d);

            #region Caps

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.ConverterBase));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.ConverterBase));
            material.Children.Add(diffuse);
            specular = WorldColors.ConverterBaseSpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                this.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            geometry.Geometry = capGeometry;

            retVal.Children.Add(geometry);

            #endregion

            #region Sides

            for (int cntr = 0; cntr <= 1; cntr++)
            {
                geometry = new GeometryModel3D();
                material = new MaterialGroup();
                diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.ConverterEnergy));
                this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.ConverterEnergy));
                material.Children.Add(diffuse);
                specular = WorldColors.ConverterEnergySpecular;
                this.MaterialBrushes.Add(new MaterialColorProps(specular));
                material.Children.Add(specular);

                if (!isFinal)
                {
                    EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                    material.Children.Add(selectionEmissive);
                    this.SelectionEmissives.Add(selectionEmissive);
                }

                geometry.Material = material;
                geometry.BackMaterial = material;

                geometry.Geometry = sideGeometry;

                retVal.Children.Add(geometry);
            }

            #endregion

            // Transform
            retVal.Transform = GetTransformForGeometry(isFinal);

            // Exit Function
            return retVal;
        }
Пример #30
0
        //TODO: Rewrite this.  Make it look like a cave, or sea shell - something organic with an opening
        private Model3DGroup CreateGeometry(bool isFinal)
        {
            ScaleTransform3D scaleTransform = new ScaleTransform3D(SCALE, SCALE, SCALE);

            Model3DGroup retVal = new Model3DGroup();

            GeometryModel3D geometry;
            MaterialGroup material;
            DiffuseMaterial diffuse;
            SpecularMaterial specular;

            Transform3DGroup transformGroup = new Transform3DGroup();
            transformGroup.Children.Add(scaleTransform);

            #region Outer Shell

            geometry = new GeometryModel3D();
            material = new MaterialGroup();

            diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.SwarmBay));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.SwarmBay));
            material.Children.Add(diffuse);

            specular = WorldColors.SwarmBaySpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                base.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            transformGroup = new Transform3DGroup();
            transformGroup.Children.Add(scaleTransform);
            transformGroup.Children.Add(new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRandomRotation())));

            geometry.Geometry = UtilityWPF.GetSphere_Ico(.5, 0, false);
            geometry.Transform = transformGroup;

            retVal.Children.Add(geometry);

            #endregion
            #region Line

            BillboardLine3D line = new BillboardLine3D();
            line.Color = WorldColors.SwarmBay;
            line.Thickness = .05 * SCALE;
            line.IsReflectiveColor = false;
            line.FromPoint = new Point3D(0, 0, 0);
            line.ToPoint = new Point3D(0, 0, .55 * SCALE);

            retVal.Children.Add(line.Model);

            #endregion

            // Transform
            retVal.Transform = GetTransformForGeometry(isFinal);

            // Exit Function
            return retVal;
        }
        private Model3DGroup CreateGeometry(bool isFinal)
        {
            const double SCALE = .75d;

            Model3DGroup retVal = new Model3DGroup();

            GeometryModel3D geometry;
            MaterialGroup material;
            DiffuseMaterial diffuse;
            SpecularMaterial specular;

            int domeSegments = isFinal ? 2 : 10;
            int cylinderSegments = isFinal ? 6 : 35;

            #region Main Cylinder

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.ConverterBase));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.ConverterBase));
            material.Children.Add(diffuse);
            specular = WorldColors.ConverterBaseSpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                this.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            List<TubeRingBase> rings = new List<TubeRingBase>();
            rings.Add(new TubeRingRegularPolygon(0, false, .4, .4, true));
            rings.Add(new TubeRingRegularPolygon(.125, false, .48, .48, false));
            rings.Add(new TubeRingRegularPolygon(.25, false, .6, .6, false));

            rings.Add(new TubeRingRegularPolygon(.125, false, .65, .65, false));
            rings.Add(new TubeRingRegularPolygon(.25, false, .7, .7, false));
            rings.Add(new TubeRingRegularPolygon(.25, false, .65, .65, false));

            rings.Add(new TubeRingRegularPolygon(.125, false, .6, .6, false));
            rings.Add(new TubeRingRegularPolygon(.25, false, .48, .48, false));
            rings.Add(new TubeRingRegularPolygon(.125, false, .4, .4, true));

            // Scale this so the height is 1
            double localScale = SCALE * .85d / rings.Sum(o => o.DistFromPrevRing);

            Transform3DGroup transformInitial = new Transform3DGroup();
            transformInitial.Children.Add(new ScaleTransform3D(localScale, localScale, localScale));
            geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, true, transformInitial);

            retVal.Children.Add(geometry);

            #endregion

            #region Axis

            geometry = new GeometryModel3D();
            material = new MaterialGroup();
            diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.ConverterEnergy));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.ConverterEnergy));
            material.Children.Add(diffuse);
            specular = WorldColors.ConverterEnergySpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                this.SelectionEmissives.Add(selectionEmissive);
            }

            geometry.Material = material;
            geometry.BackMaterial = material;

            geometry.Geometry = UtilityWPF.GetCapsule_AlongZ(cylinderSegments, domeSegments, .15 * SCALE, SCALE);

            retVal.Children.Add(geometry);

            #endregion

            // Transform
            retVal.Transform = GetTransformForGeometry(isFinal);

            // Exit Function
            return retVal;
        }
Пример #32
0
        private GeometryModel3D CreateGeometry(bool isFinal)
        {
            MaterialGroup material = new MaterialGroup();
            DiffuseMaterial diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.EnergyTank));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.EnergyTank));
            material.Children.Add(diffuse);
            SpecularMaterial specular = WorldColors.EnergyTankSpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);
            EmissiveMaterial emissive = WorldColors.EnergyTankEmissive;
            this.MaterialBrushes.Add(new MaterialColorProps(emissive));
            material.Children.Add(emissive);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                base.SelectionEmissives.Add(selectionEmissive);
            }

            GeometryModel3D retVal = new GeometryModel3D();
            retVal.Material = material;
            retVal.BackMaterial = material;

            int domeSegments = isFinal ? 2 : 10;
            int cylinderSegments = isFinal ? 6 : 35;

            List<TubeRingBase> rings = new List<TubeRingBase>();
            rings.Add(new TubeRingDome(0, false, domeSegments));
            rings.Add(new TubeRingRegularPolygon(.4, false, 1, 1, false));
            rings.Add(new TubeRingRegularPolygon(2.5, false, 1, 1, false));
            rings.Add(new TubeRingDome(.4, false, domeSegments));

            // Scale this so the height is 1
            double scale = 1d / rings.Sum(o => o.DistFromPrevRing);

            Transform3DGroup transformInitial = new Transform3DGroup();
            transformInitial.Children.Add(new ScaleTransform3D(scale, scale, scale));
            retVal.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, true, transformInitial);

            // Transform
            retVal.Transform = GetTransformForGeometry(isFinal);

            // Exit Function
            return retVal;
        }
Пример #33
0
        private GeometryModel3D CreateGeometry(bool isFinal)
        {
            MaterialGroup material = new MaterialGroup();
            DiffuseMaterial diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.CargoBay));
            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.CargoBay));
            material.Children.Add(diffuse);
            SpecularMaterial specular = WorldColors.CargoBaySpecular;
            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                base.SelectionEmissives.Add(selectionEmissive);
            }

            GeometryModel3D retVal = new GeometryModel3D();
            retVal.Material = material;
            retVal.BackMaterial = material;

            if (isFinal)
            {
                retVal.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-.5, -.5, -.5), new Point3D(.5, .5, .5));
            }
            else
            {
                retVal.Geometry = GetMesh();
            }

            // Transform
            retVal.Transform = GetTransformForGeometry(isFinal);

            // Exit Function
            return retVal;
        }