public override void Calculate()
        {
            if (InputPorts[0].Data == null) return;

            if (InputPorts[0].Data is string)
            {
                var extension = Path.GetExtension(InputPorts[0].Data as string);

                var flag = false;

                switch (extension)
                {
                    case ".obj":
                        var currentHelixObjReader = new ObjReader();
                        try
                        {
                            var objModel = currentHelixObjReader.Read((string) InputPorts[0].Data);
                            var modelGroup = new GroupModel3D();
                            var modelGeometry = new Element3DCollection();
                            modelGeometry.AddRange(
                                objModel.Select(
                                    x =>
                                        new MeshGeometryModel3D
                                        {
                                            Geometry = x.Geometry as MeshGeometry3D,
                                            Material = x.Material
                                        }));

                            modelGroup.Children = modelGeometry;

                            Dispatcher.BeginInvoke((Action) delegate { _control.ViewPort3D.Items.Add(modelGroup); });
                        }
                        catch (Exception)
                        {
                            // ignore
                        }
                        break;
                    case ".stl":
                        var currentHelixStlReader = new StLReader();
                        try
                        {
                            var myModel = currentHelixStlReader.Read((string) InputPorts[0].Data);
                            // _control.ViewPort3D.Items.Add(myModel);
                        }
                        catch (Exception)
                        {
                            // ignore
                        }
                        break;
                }
            }
        }
            //builds a single permutation and ignores instancing
            public RenderModel3D BuildSection(int lod, int meshIndex, int meshCount, float scale, Matrix4x4 transform)
            {
                var model    = LodProperties[lod];
                var elements = new List <Helix.GroupElement3D>();

                for (int i = meshIndex; i < meshIndex + meshCount; i++)
                {
                    var template = templates[lod][i];

                    if (template.IsEmpty)
                    {
                        continue;
                    }

                    elements.Add(template.GenerateModelNoInstance((mesh, matIndex) =>
                    {
                        if (matIndex < 0 || matIndex >= model.Materials.Count)
                        {
                            mesh.IsTransparent = false;
                            mesh.Material      = ErrorMaterial;
                        }

                        bool isTransparent;
                        var mat = factory.CreateMaterial(model.Materials[matIndex], out isTransparent);

                        mesh.IsTransparent = isTransparent;
                        mesh.Material      = mat;
                    }));
                }

                Helix.GroupElement3D permutationRoot;
                if (elements.Count == 1)
                {
                    permutationRoot = elements[0];
                }
                else
                {
                    permutationRoot = new Helix.GroupModel3D();
                    foreach (var e in elements)
                    {
                        permutationRoot.Children.Add(e);
                    }
                }

                permutationRoot.Transform = GetTransform(scale, transform);

                return(RenderModel3D.FromElement(permutationRoot));
            }
Ejemplo n.º 3
0
        public Helix.GroupModel3D GenerateModelNoInstance(Action <Helix.MeshGeometryModel3D, int> applyMaterial)
        {
            var group = new Helix.GroupModel3D();

            for (int i = 0; i < submeshCount; i++)
            {
                var mesh = new Helix.MeshGeometryModel3D
                {
                    Geometry = submeshes[i],
                };

                applyMaterial(mesh, matIndex[i]);
                group.Children.Add(mesh);
            }

            return(group);
        }
Ejemplo n.º 4
0
        public override Helix.GroupModel3D GenerateModel(Action <Helix.MeshGeometryModel3D, int> applyMaterial)
        {
            if (group != null)
            {
                return(group);
            }

            group = new Helix.GroupModel3D();

            for (int i = 0; i < submeshCount; i++)
            {
                var mesh = rootMeshes[i] = new Helix.InstancingMeshGeometryModel3D
                {
                    Geometry = submeshes[i],
                };

                applyMaterial(mesh, matIndex[i]);
                group.Children.Add(mesh);
            }

            return(group);
        }
Ejemplo n.º 5
0
        public override void InitializeElements(ModelFactory factory)
        {
            foreach (var zone in scenario.SquadHierarchy.EnumerateZones())
            {
                #region Firing Positions
                var fposGroup   = new Helix.GroupModel3D();
                var fposMarkers = new ObservableCollection <PositionMarker3D>();

                foreach (var area in zone.FiringPositions)
                {
                    var fposMarker = new PositionMarker3D();
                    BindFiringPosition(area, fposMarker);
                    fposMarkers.Add(fposMarker);
                    fposGroup.Children.Add(fposMarker);
                }

                FiringPositionGroups.Add(zone, fposGroup);
                FiringPositions.Add(zone, fposMarkers);
                #endregion

                #region Areas
                var areaGroup   = new Helix.GroupModel3D();
                var areaMarkers = new ObservableCollection <PositionMarker3D>();

                foreach (var area in zone.Areas)
                {
                    var areaMarker = new PositionMarker3D();
                    BindArea(area, areaMarker);
                    areaMarkers.Add(areaMarker);
                    areaGroup.Children.Add(areaMarker);
                }

                AreaGroups.Add(zone, areaGroup);
                Areas.Add(zone, areaMarkers);
                #endregion

                foreach (var squad in zone.Squads)
                {
                    Helix.GroupModel3D locGroup;
                    ObservableCollection <SpawnPointMarker3D> locMarkers;

                    #region Encounter Starting Locations
                    foreach (var enc in squad.Encounters)
                    {
                        locGroup   = new Helix.GroupModel3D();
                        locMarkers = new ObservableCollection <SpawnPointMarker3D>();

                        foreach (var loc in enc.StartingLocations)
                        {
                            var locMarker = new SpawnPointMarker3D();
                            BindStartLocation(loc, locMarker);
                            locMarkers.Add(locMarker);
                            locGroup.Children.Add(locMarker);
                        }

                        StartLocationGroups.Add(enc, locGroup);
                        StartLocations.Add(enc, locMarkers);
                    }
                    #endregion

                    #region Formation Locations
                    locGroup   = new Helix.GroupModel3D();
                    locMarkers = new ObservableCollection <SpawnPointMarker3D>();

                    foreach (var loc in squad.GroupStartLocations)
                    {
                        var locMarker = new SpawnPointMarker3D();
                        BindStartLocation(loc, locMarker);
                        locMarkers.Add(locMarker);
                        locGroup.Children.Add(locMarker);
                    }

                    GroupStartLocationGroups.Add(squad, locGroup);
                    GroupStartLocations.Add(squad, locMarkers);
                    #endregion

                    #region Spawn Locations
                    locGroup   = new Helix.GroupModel3D();
                    locMarkers = new ObservableCollection <SpawnPointMarker3D>();

                    foreach (var loc in squad.SoloStartLocations)
                    {
                        var locMarker = new SpawnPointMarker3D();
                        BindStartLocation(loc, locMarker);
                        locMarkers.Add(locMarker);
                        locGroup.Children.Add(locMarker);
                    }

                    SoloStartLocationGroups.Add(squad, locGroup);
                    SoloStartLocations.Add(squad, locMarkers);
                    #endregion
                }
            }
        }
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.gridDropArea = ((System.Windows.Controls.Grid)(target));
                return;

            case 2:
                this.cbCalculation = ((System.Windows.Controls.ComboBox)(target));
                return;

            case 3:
                this.tbName = ((System.Windows.Controls.TextBox)(target));
                return;

            case 4:
                this.cbkApplyEnergyCosts = ((System.Windows.Controls.CheckBox)(target));
                return;

            case 5:
                this.ckbApplyTaxes = ((System.Windows.Controls.CheckBox)(target));
                return;

            case 6:
                this.nudTaxRate = ((MahApps.Metro.Controls.NumericUpDown)(target));
                return;

            case 7:
                this.ExpanderMultipleGcodeParserView = ((System.Windows.Controls.Expander)(target));
                return;

            case 8:
                this.TextBoxSearchStl = ((System.Windows.Controls.TextBox)(target));
                return;

            case 9:
                this.mslbStl = ((PrintCostCalculator3d.Controls.MultiSelectListBox)(target));
                return;

            case 10:

            #line 1018 "..\..\..\..\Views\3dPrinting\3dPrintingCalculationView.xaml"
                ((System.Windows.Controls.ContextMenu)(target)).Opened += new System.Windows.RoutedEventHandler(this.ContextMenu_Opened);

            #line default
            #line hidden
                return;

            case 11:

            #line 1032 "..\..\..\..\Views\3dPrinting\3dPrintingCalculationView.xaml"
                ((System.Windows.Controls.ContextMenu)(target)).Opened += new System.Windows.RoutedEventHandler(this.ContextMenu_Opened);

            #line default
            #line hidden
                return;

            case 12:
                this.TextBoxSearchGcode = ((System.Windows.Controls.TextBox)(target));
                return;

            case 13:
                this.mslbGCode = ((PrintCostCalculator3d.Controls.MultiSelectListBox)(target));
                return;

            case 14:

            #line 1251 "..\..\..\..\Views\3dPrinting\3dPrintingCalculationView.xaml"
                ((System.Windows.Controls.ContextMenu)(target)).Opened += new System.Windows.RoutedEventHandler(this.ContextMenu_Opened);

            #line default
            #line hidden
                return;

            case 15:

            #line 1265 "..\..\..\..\Views\3dPrinting\3dPrintingCalculationView.xaml"
                ((System.Windows.Controls.ContextMenu)(target)).Opened += new System.Windows.RoutedEventHandler(this.ContextMenu_Opened);

            #line default
            #line hidden
                return;

            case 16:
                this.TextBoxSearchPrinter = ((System.Windows.Controls.TextBox)(target));
                return;

            case 17:
                this.lbPrinters = ((PrintCostCalculator3d.Controls.MultiSelectListBox)(target));
                return;

            case 18:
                this.TextBoxSearchMaterial = ((System.Windows.Controls.TextBox)(target));
                return;

            case 19:
                this.lbMaterials = ((PrintCostCalculator3d.Controls.MultiSelectListBox)(target));
                return;

            case 20:
                this.ExpanderAdvancedView = ((System.Windows.Controls.Expander)(target));
                return;

            case 21:
                this.TextBoxSearchOffers = ((System.Windows.Controls.TextBox)(target));
                return;

            case 22:
                this.lbOffers = ((PrintCostCalculator3d.Controls.MultiSelectListBox)(target));
                return;

            case 23:
                this.view3d = ((HelixToolkit.Wpf.SharpDX.Viewport3DX)(target));
                return;

            case 24:
                this.cbGcode = ((System.Windows.Controls.ComboBox)(target));
                return;

            case 25:
                this.view2dGcode = ((HelixToolkit.Wpf.SharpDX.Viewport3DX)(target));
                return;

            case 26:
                this.view3dGcode = ((HelixToolkit.Wpf.SharpDX.Viewport3DX)(target));
                return;

            case 27:
                this.group = ((HelixToolkit.Wpf.SharpDX.GroupModel3D)(target));
                return;
            }
            this._contentLoaded = true;
        }
 public override void Dispose()
 {
     base.Dispose();
     GroupElement.Dispose();
     GroupElement = null;
 }
            public RenderModel3D BuildElement(int lod)
            {
                var model = LodProperties[lod];

                var regions   = new List <RenderModel3D.Region>();
                var instances = new List <RenderModel3D.InstanceGroup>();

                foreach (var region in model.Regions)
                {
                    var instanceMeshIds = new List <int>();
                    var permutations    = new List <RenderModel3D.Permutation>();
                    foreach (var permutation in region.Permutations)
                    {
                        //this permutation is an instance that has already been added
                        if (instanceMeshIds.Contains(permutation.MeshIndex))
                        {
                            continue;
                        }

                        var elements = new List <Helix.GroupElement3D>();
                        for (int i = permutation.MeshIndex; i < permutation.MeshIndex + permutation.MeshCount; i++)
                        {
                            var template = templates[lod][i];

                            if (template.IsEmpty)
                            {
                                continue;
                            }

                            if (template.IsInstancing)
                            {
                                template = template.Copy();
                            }

                            elements.Add(template.GenerateModel((mesh, matIndex) =>
                            {
                                if (matIndex < 0 || matIndex >= model.Materials.Count)
                                {
                                    mesh.IsTransparent = false;
                                    mesh.Material      = ErrorMaterial;
                                    return;
                                }

                                bool isTransparent;
                                var mat = factory.CreateMaterial(model.Materials[matIndex], out isTransparent);

                                mesh.IsTransparent = isTransparent;
                                mesh.Material      = mat;
                            }));

                            if (template.IsInstancing)
                            {
                                instanceMeshIds.Add(i);

                                var allTransforms = region.Permutations
                                                    .Where(p => p.MeshIndex == i)
                                                    .Select(p => new KeyValuePair <string, SharpDX.Matrix>(p.Name, GetTransform(p.TransformScale, p.Transform).ToMatrix()));

                                instances.Add(new RenderModel3D.InstanceGroup(region.Name, elements[0], (InstancedMeshTemplate)template, allTransforms));

                                //can only have one mesh if instancing
                                break;
                            }
                        }

                        //this permutation was found to be an instance
                        if (instanceMeshIds.Contains(permutation.MeshIndex))
                        {
                            continue;
                        }

                        Helix.GroupElement3D permutationRoot;
                        if (elements.Count == 1)
                        {
                            permutationRoot = elements[0];
                        }
                        else
                        {
                            permutationRoot = new Helix.GroupModel3D();
                            foreach (var e in elements)
                            {
                                permutationRoot.Children.Add(e);
                            }
                        }

                        permutationRoot.Transform = GetTransform(permutation.TransformScale, permutation.Transform);
                        permutations.Add(new RenderModel3D.Permutation(permutationRoot, permutation.SourceIndex, permutation.Name));
                    }

                    regions.Add(new RenderModel3D.Region(region.SourceIndex, region.Name, permutations));
                }

                return(new RenderModel3D(model.Name, regions, instances));
            }