public List <string> GetGenericCatalogFinishCodeAndName() { List <string> finishesList = new List <string>(); _sceneAnalysis = new SceneAnalysis(this.GetArticleWithModel()); if (_sceneAnalysis.Article != null) { bool IsGenerik = _sceneAnalysis.GetGenericFinishes(out string[] generikFinishTypes, out string[] generikFinishes); if (IsGenerik) { for (int fin = 0; fin < generikFinishTypes.Length; fin++) { int.TryParse(generikFinishTypes[fin], out int generikFinishType); int.TryParse(generikFinishes[fin], out int generikFinish); int type = _sceneAnalysis.GetFinishTypeNumber(generikFinishType); string codeAndName = _sceneAnalysis.GetCatalogFinishCodeAndName(generikFinishType, generikFinish); finishesList.Add(codeAndName + KD.StringTools.Const.SemiColon + type); } return(finishesList); } } return(null); }
public OrderInformations(AppliComponent appli, int callParamsBlock, Articles articles) { _currentAppli = appli; _callParamsBlock = callParamsBlock; _articles = articles; _sceneAnalysis = new SceneAnalysis(this.GetArticleWithModel()); }
public BScene OptimizeScene(BScene bScene) { List <BInstance> newInstances = new List <BInstance>(); // Create collections of meshes with similar materials using (SceneAnalysis analysis = new SceneAnalysis(bScene)) { int lastInstanceCount = newInstances.Count; if (ConvOAR.Globals.parms.P <bool>("SeparateInstancedMeshes")) { newInstances.AddRange(SeparateMeshInstances(bScene, analysis)); } // Any shared meshes have been gathered into instances in 'newInstances' // and the meshes have been removed from the shared materials in the analysis. int instancesAdded = newInstances.Count - lastInstanceCount; ConvOAR.Globals.log.DebugFormat("{0} OptimizeScene: BInstances added by mesh instances = {1}", _logHeader, instancesAdded); lastInstanceCount = newInstances.Count; if (ConvOAR.Globals.parms.P <bool>("MergeSharedMaterialMeshes")) { newInstances.AddRange(MergeSharedMaterialMeshes(bScene, analysis)); } instancesAdded = newInstances.Count - lastInstanceCount; ConvOAR.Globals.log.DebugFormat("{0} OptimizeScene: BInstances added by material sharing = {1}", _logHeader, instancesAdded); } return(bScene); }
// Return a new scene whos instances have been created by combining meshes that share // materials. public BScene RebuildSceneBasedOnSharedMeshes(BScene bScene) { List <BInstance> newInstances = new List <BInstance>(); // Create collections of meshes with similar materials using (SceneAnalysis analysis = new SceneAnalysis(bScene)) { newInstances.AddRange(MergeSharedMaterialMeshes(bScene, analysis)); } BScene newScene = new BScene(bScene); newScene.instances = newInstances; return(newScene); }
private List <BInstance> SeparateMeshInstances(BScene bScene, SceneAnalysis analysis) { List <BInstance> ret = new List <BInstance>(); try { // If there are lots of instances of the same mesh, it is better to have multiple instances // that point to the same mesh. If a mesh is not shared, consolidating the meshes // into a single instance is best. It's a balance of transferring vertices vs fewer draws. // Any meshes that are used more than 'MeshShareThreshold' will be sent out with their // instances rather than being combined. // The GLTF output code will not send out duplicate meshes and combining the meshes to // share materials destroys the duplicatable mesh shapes. // The duplicated meshes usually share a material so pull them together into meshes // in one instance. // Note: the 'SelectMany' is used to flatten the list of lists int meshShareThreshold = ConvOAR.Globals.parms.P <int>("MeshShareThreshold"); ConvOAR.Globals.log.DebugFormat("{0} SeparateMeshes: Separating instanced meshes. threshold={1}", _logHeader, meshShareThreshold); /* * foreach (BHash key in analysis.sharedMeshes.Keys) { // DEBUG DEBUG * ConvOAR.Globals.log.DebugFormat("{0} SeparateMeshes: mesh hash {1} . meshes={2}", // DEBUG DEBUG * _logHeader, key, analysis.sharedMeshes[key].Count); // DEBUG DEBUG * }; // DEBUG DEBUG */ ret.AddRange(analysis.sharedMeshes.Values.Where(val => val.Count > meshShareThreshold).SelectMany(meshList => { // Creates Instances for the shared messes in this list and also takes the meshes out of 'meshByMaterial' ConvOAR.Globals.log.DebugFormat("{0} MergeSharedMaterialMeshes: shared mesh hash: {1}/{2}, cnt={3}", _logHeader, meshList.First().renderableMesh.mesh.GetBHash(), meshList.First().renderableMesh.material.GetBHash(), meshList.Count); // Since mesh will be in this group, remove it from the meshes with shared materials analysis.MeshUsed(meshList); return(CreateInstancesForSharedMeshes(meshList)); }).ToList()); } catch (Exception e) { ConvOAR.Globals.log.DebugFormat("{0} SeparateMeshInstances: exception: {1}", _logHeader, e); } return(ret); }
public List <string> GetFinishCodeAndName()//Article article) { List <string> finishesList = new List <string>(); _sceneAnalysis = new SceneAnalysis(this.Article); bool IsGenerik = _sceneAnalysis.GetFinishes(out string[] finishTypes, out string[] finishes); if (IsGenerik) { for (int fin = 0; fin < finishTypes.Length; fin++) { int.TryParse(finishTypes[fin], out int finishType); int.TryParse(finishes[fin], out int finish); int type = _sceneAnalysis.GetFinishTypeNumber(finishType); finishesList.Add(_sceneAnalysis.GetFinishCodeAndName(finishType, finish) + KD.StringTools.Const.SemiColon + type); } return(finishesList); } return(null); }
private List <BInstance> MergeSharedMaterialMeshes(BScene bScene, SceneAnalysis analysis) { List <BInstance> ret = new List <BInstance>(); try { // 'analysis.meshByMaterial' has all meshes/instances grouped by material used // 'analysis.sharedMeshes' has all meshes grouped by the mesh ConvOAR.Globals.log.DebugFormat("{0} MergeShareMaterialHashes: number of materials = {1}", _logHeader, analysis.meshByMaterial.Count); // Merge the meshes and create an Instance containing the new mesh set ret.AddRange(analysis.meshByMaterial.Keys.SelectMany(materialHash => { ConvOAR.Globals.log.DebugFormat("{0} MergeShareMaterialHashes: material hash {1} . meshes={2}", _logHeader, materialHash, analysis.meshByMaterial[materialHash].Count); return(CreateInstancesFromSharedMaterialMeshes(materialHash, analysis.meshByMaterial[materialHash])); }).ToList()); } catch (Exception e) { ConvOAR.Globals.log.DebugFormat("{0} MergeShareMaterialHashes: exception: {1}", _logHeader, e); } return(ret); }