コード例 #1
0
        private void btnExportAll_Click(object sender, RoutedEventArgs e)
        {
            using (var model = renderGeometry.ReadGeometry(SelectedLod))
            {
                var writeModelFile = Substrate.GetSharedFunction <WriteModelFile>("Reclaimer.Plugins.ModelViewerPlugin.WriteModelFile");

                string fileName, formatId;
                if (!PromptFileSave(model, out fileName, out formatId))
                {
                    return;
                }

                writeModelFile(model, fileName, formatId);
            }
        }
コード例 #2
0
        private bool SaveModel(IRenderGeometry geometry, string baseDir)
        {
            var fileName = MakePath(geometry.Class, geometry.Name, baseDir);
            var ext      = getModelExtensionFunc?.Value(Settings.ModelFormat);

            if (!Settings.OverwriteExisting && File.Exists($"{fileName}.{ext}"))
            {
                return(false);
            }

            writeModelFileFunc?.Invoke(geometry.ReadGeometry(0), fileName, Settings.ModelFormat);
            return(true);
        }
コード例 #3
0
        private bool LoadRenderGeometry(IRenderGeometry geom, bool lods)
        {
            if (geometryCache.ContainsKey(geom.Id))
            {
                return(true);
            }

            try
            {
                var lodCount  = lods ? geom.LodCount : 1;
                var lodModels = Enumerable.Repeat(0, lodCount).Select(i => geom.ReadGeometry(i)).ToList();
                var col       = new TemplateCollection(this, lodModels);

                if (!geometryCache.TryAdd(geom.Id, col))
                {
                    return(true); //looks like another thread is already working on this model
                }
                foreach (var lod in lodModels)
                {
                    //cache all referenced textures
                    var matIndexes = lod.Meshes.SelectMany(m => m.Submeshes)
                                     .Select(m => m.MaterialIndex)
                                     .Where(i => i >= 0)
                                     .Distinct();

                    foreach (var index in matIndexes)
                    {
                        ReadTexture(lod.Materials[index]);
                    }
                }

                foreach (var lod in lodModels)
                {
                    lod.Dispose();
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
コード例 #4
0
        private void SetLod(int index)
        {
            model = geometry.ReadGeometry(index);
            var meshes = GetMeshes(model).ToList();

            TreeViewItems.Clear();
            InvalidRegions.Clear();
            InvalidPermutations.Clear();
            modelGroup.Children.Clear();
            foreach (var region in model.Regions)
            {
                var regNode = new TreeItemModel {
                    Header = region.Name, IsChecked = true
                };

                foreach (var perm in region.Permutations)
                {
                    var mesh = meshes[perm.MeshIndex];
                    if (mesh == null)
                    {
                        InvalidPermutations.Add(perm);
                        continue;
                    }

                    var permNode = new TreeItemModel {
                        Header = perm.Name, IsChecked = true
                    };
                    regNode.Items.Add(permNode);

                    var tGroup = new Transform3DGroup();

                    if (perm.TransformScale != 1)
                    {
                        var tform = new ScaleTransform3D(perm.TransformScale, perm.TransformScale, perm.TransformScale);

                        tform.Freeze();
                        tGroup.Children.Add(tform);
                    }

                    if (!perm.Transform.IsIdentity)
                    {
                        var tform = new MatrixTransform3D(new Matrix3D
                        {
                            M11 = perm.Transform.M11,
                            M12 = perm.Transform.M12,
                            M13 = perm.Transform.M13,

                            M21 = perm.Transform.M21,
                            M22 = perm.Transform.M22,
                            M23 = perm.Transform.M23,

                            M31 = perm.Transform.M31,
                            M32 = perm.Transform.M32,
                            M33 = perm.Transform.M33,

                            OffsetX = perm.Transform.M41,
                            OffsetY = perm.Transform.M42,
                            OffsetZ = perm.Transform.M43
                        });

                        tform.Freeze();
                        tGroup.Children.Add(tform);
                    }

                    Model3DGroup permGroup;
                    if (tGroup.Children.Count == 0 && perm.MeshCount == 1)
                    {
                        permGroup = meshes[perm.MeshIndex];
                    }
                    else
                    {
                        permGroup = new Model3DGroup();
                        for (int i = 0; i < perm.MeshCount; i++)
                        {
                            if (tGroup.Children.Count > 0)
                            {
                                (permGroup.Transform = tGroup).Freeze();

                                permGroup.Children.Add(meshes[perm.MeshIndex + i]);
                                permGroup.Freeze();
                            }
                            else
                            {
                                permGroup.Children.Add(meshes[perm.MeshIndex + i]);
                            }
                        }
                    }

                    permNode.Tag = permGroup;
                    modelGroup.Children.Add(permGroup);
                }

                if (regNode.HasItems)
                {
                    TreeViewItems.Add(regNode);
                }
                else
                {
                    InvalidRegions.Add(region);
                }
            }

            renderer.ScaleToContent(new[] { modelGroup });
        }