mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	Fixed "setting an extruder does not change object's color"
This commit is contained in:
		
							parent
							
								
									94b1183843
								
							
						
					
					
						commit
						a4be8ef6ad
					
				
					 4 changed files with 30 additions and 17 deletions
				
			
		|  | @ -1232,6 +1232,19 @@ void ModelVolume::set_material(t_model_material_id material_id, const ModelMater | |||
|         this->object->get_model()->add_material(material_id, material); | ||||
| } | ||||
| 
 | ||||
| // Extract the current extruder ID based on this ModelVolume's config and the parent ModelObject's config.
 | ||||
| int ModelVolume::extruder_id() const | ||||
| { | ||||
|     int extruder_id = -1; | ||||
|     if (this->is_model_part()) { | ||||
|         const ConfigOption *opt = this->config.option("extruder"); | ||||
|         if (opt == nullptr) | ||||
|             opt = this->object->config.option("extruder"); | ||||
|         extruder_id = (opt == nullptr) ? 0 : opt->getInt(); | ||||
|     } | ||||
|     return extruder_id; | ||||
| } | ||||
| 
 | ||||
| #if ENABLE_MODELVOLUME_TRANSFORM | ||||
| void ModelVolume::center_geometry() | ||||
| { | ||||
|  |  | |||
|  | @ -312,6 +312,10 @@ public: | |||
|     void                set_material_id(t_model_material_id material_id); | ||||
|     ModelMaterial*      material() const; | ||||
|     void                set_material(t_model_material_id material_id, const ModelMaterial &material); | ||||
|     // Extract the current extruder ID based on this ModelVolume's config and the parent ModelObject's config.
 | ||||
|     // Extruder ID is only valid for FFF. Returns -1 for SLA or if the extruder ID is not applicable (support volumes).
 | ||||
|     int                 extruder_id() const; | ||||
| 
 | ||||
|     // Split this volume, append the result to the object owning this volume.
 | ||||
|     // Return the number of volumes created from this one.
 | ||||
|     // This is useful to assign different materials to different volumes of an object.
 | ||||
|  |  | |||
|  | @ -747,18 +747,9 @@ int GLVolumeCollection::load_object_volume( | |||
|         { 0.5f, 0.5f, 1.0f, 1.f } | ||||
|     }; | ||||
| 
 | ||||
|     const ModelVolume *model_volume = model_object->volumes[volume_idx]; | ||||
| 
 | ||||
|     int extruder_id = -1; | ||||
|     if (model_volume->is_model_part()) | ||||
|     { | ||||
|         const ConfigOption *opt = model_volume->config.option("extruder"); | ||||
|         if (opt == nullptr) | ||||
|             opt = model_object->config.option("extruder"); | ||||
|         extruder_id = (opt == nullptr) ? 0 : opt->getInt(); | ||||
|     } | ||||
| 
 | ||||
|     const ModelInstance *instance = model_object->instances[instance_idx]; | ||||
|     const ModelVolume   *model_volume = model_object->volumes[volume_idx]; | ||||
|     const int            extruder_id  = model_volume->extruder_id(); | ||||
|     const ModelInstance *instance     = model_object->instances[instance_idx]; | ||||
| #if ENABLE_MODELVOLUME_TRANSFORM | ||||
|     const TriangleMesh& mesh = model_volume->mesh; | ||||
| #else | ||||
|  |  | |||
|  | @ -3844,12 +3844,13 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re | |||
| 
 | ||||
|     struct ModelVolumeState { | ||||
|         ModelVolumeState(const GLVolume *volume) :  | ||||
| 			geometry_id(volume->geometry_id), volume_idx(-1) {} | ||||
| 		ModelVolumeState(const ModelID &volume_id, const ModelID &instance_id, const GLVolume::CompositeID &composite_id) : | ||||
| 			geometry_id(std::make_pair(volume_id.id, instance_id.id)), composite_id(composite_id), volume_idx(-1) {} | ||||
| 			model_volume(nullptr), geometry_id(volume->geometry_id), volume_idx(-1) {} | ||||
| 		ModelVolumeState(const ModelVolume *model_volume, const ModelID &instance_id, const GLVolume::CompositeID &composite_id) : | ||||
| 			model_volume(model_volume), geometry_id(std::make_pair(model_volume->id().id, instance_id.id)), composite_id(composite_id), volume_idx(-1) {} | ||||
| 		ModelVolumeState(const ModelID &volume_id, const ModelID &instance_id) : | ||||
| 			geometry_id(std::make_pair(volume_id.id, instance_id.id)), volume_idx(-1) {} | ||||
| 			model_volume(nullptr), geometry_id(std::make_pair(volume_id.id, instance_id.id)), volume_idx(-1) {} | ||||
| 		bool new_geometry() const { return this->volume_idx == size_t(-1); } | ||||
| 		const ModelVolume		   *model_volume; | ||||
|         // ModelID of ModelVolume + ModelID of ModelInstance
 | ||||
|         // or timestamp of an SLAPrintObjectStep + ModelID of ModelInstance
 | ||||
|         std::pair<size_t, size_t>   geometry_id; | ||||
|  | @ -3888,7 +3889,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re | |||
|                 const ModelInstance *model_instance = model_object->instances[instance_idx]; | ||||
|                 for (int volume_idx = 0; volume_idx < (int)model_object->volumes.size(); ++ volume_idx) { | ||||
|                     const ModelVolume *model_volume = model_object->volumes[volume_idx]; | ||||
| 					model_volume_state.emplace_back(model_volume->id(), model_instance->id(), GLVolume::CompositeID(object_idx, volume_idx, instance_idx)); | ||||
| 					model_volume_state.emplace_back(model_volume, model_instance->id(), GLVolume::CompositeID(object_idx, volume_idx, instance_idx)); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | @ -3941,6 +3942,10 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re | |||
|                 map_glvolume_old_to_new[volume_id] = glvolumes_new.size(); | ||||
|                 mvs->volume_idx = glvolumes_new.size(); | ||||
|                 glvolumes_new.emplace_back(volume); | ||||
|                 // Update color of the volume based on the current extruder.
 | ||||
|                 int extruder_id = mvs->model_volume->extruder_id(); | ||||
|                 if (extruder_id != -1) | ||||
|                     volume->extruder_id = extruder_id; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 bubnikv
						bubnikv