﻿<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ja">
	<id>https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=%E5%88%A9%E7%94%A8%E8%80%85%3AKwk%2FGsoc2010%2FAutoSelectPaintImage</id>
	<title>利用者:Kwk/Gsoc2010/AutoSelectPaintImage - 版の履歴</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=%E5%88%A9%E7%94%A8%E8%80%85%3AKwk%2FGsoc2010%2FAutoSelectPaintImage"/>
	<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=%E5%88%A9%E7%94%A8%E8%80%85:Kwk/Gsoc2010/AutoSelectPaintImage&amp;action=history"/>
	<updated>2026-08-02T04:15:43Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=%E5%88%A9%E7%94%A8%E8%80%85:Kwk/Gsoc2010/AutoSelectPaintImage&amp;diff=98587&amp;oldid=prev</id>
		<title>Yamyam: 1版 をインポートしました</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=%E5%88%A9%E7%94%A8%E8%80%85:Kwk/Gsoc2010/AutoSelectPaintImage&amp;diff=98587&amp;oldid=prev"/>
		<updated>2018-06-28T19:38:04Z</updated>

		<summary type="html">&lt;p&gt;1版 をインポートしました&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ja&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← 古い版&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;2018年6月28日 (木) 19:38時点における版&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ja&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(相違点なし)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Yamyam</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=%E5%88%A9%E7%94%A8%E8%80%85:Kwk/Gsoc2010/AutoSelectPaintImage&amp;diff=98586&amp;oldid=prev</id>
		<title>2010年8月16日 (月) 13:00にwiki&gt;Kwkによる</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=%E5%88%A9%E7%94%A8%E8%80%85:Kwk/Gsoc2010/AutoSelectPaintImage&amp;diff=98586&amp;oldid=prev"/>
		<updated>2010-08-16T13:00:20Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Page/Header|soc-2010-kwk|User:Kwk/GSoC2010/FasterWayToAddMaps|User:Kwk/Gsoc2010/BumpMapPainting}}&lt;br /&gt;
&lt;br /&gt;
=About=&lt;br /&gt;
&lt;br /&gt;
I use this page to bring my ideas to paper and to clarify what I am doing.&lt;br /&gt;
&lt;br /&gt;
=Scenario=&lt;br /&gt;
&lt;br /&gt;
Consider having multiple objects, each with its own set of materials and textures. Let's say, a few of the textures are actually image textures and you want to paint onto them in the UV/Image editor.&lt;br /&gt;
&lt;br /&gt;
=Problem=&lt;br /&gt;
&lt;br /&gt;
Up until now the UV/Image Editor doesn't care which object is selected nor does it care which texture in the active material's texture slot is active. This makes quick switching of paint textures more complicated than it needs to be.&lt;br /&gt;
&lt;br /&gt;
=Idea=&lt;br /&gt;
&lt;br /&gt;
Whenever the another texture in the active material's texture slot changes, the image in the UV/Image Editor shall reflect these changes with respect to a setting that indicates if this behavior is wanted or not.&lt;br /&gt;
&lt;br /&gt;
=Use Cases=&lt;br /&gt;
&lt;br /&gt;
If &amp;quot;Auto Select Image&amp;quot; it toggled on, when will the UV/Image Editor update it's image?&lt;br /&gt;
&lt;br /&gt;
If the user...&lt;br /&gt;
&lt;br /&gt;
# explicitly selects another texture slot,&lt;br /&gt;
# selects another object with a different material&lt;br /&gt;
associated with it (implicit material change).&lt;br /&gt;
# explicitly selects another material.&lt;br /&gt;
# toggles the &amp;quot;Auto Select Image&amp;quot; option on.&lt;br /&gt;
&lt;br /&gt;
=Video=&lt;br /&gt;
&lt;br /&gt;
[[Image:Auto-select-image-feature.png|thumb|Shows how to enable the &amp;quot;Auto Select Image&amp;quot; feature in the UV/Image Editor.]] A video with a feature demonstration can be found here: http://vimeo.com/13215410&lt;br /&gt;
&lt;br /&gt;
=Solution=&lt;br /&gt;
&lt;br /&gt;
==How to change the default behavior of the UV/Image Editor?==&lt;br /&gt;
&lt;br /&gt;
The easiest part is to add the state that reflects, if the changes to the UV/Image Editor behavior are wanted or not.&lt;br /&gt;
&lt;br /&gt;
Therefore I've added a boolean RNA property called '''auto_select_image''' and connected if to the flag '''SpaceImage-&amp;gt;flag''' in my branch (soc-2010-kwk).&lt;br /&gt;
&lt;br /&gt;
I chose this location for the '''SI_AUTO_SELECT_IMAGE''' flag but it can be moved to a different location if requested by other developers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*  selecting the active paint image by active textures in texture stack */&lt;br /&gt;
prop= RNA_def_property(srna, &amp;quot;auto_select_image&amp;quot;, PROP_BOOLEAN, PROP_NONE);&lt;br /&gt;
RNA_def_property_boolean_sdna(prop, NULL, &amp;quot;flag&amp;quot;, SI_AUTO_SELECT_IMAGE);&lt;br /&gt;
RNA_def_property_ui_text(prop, &amp;quot;Auto Select Image&amp;quot;, &amp;quot;Automatically select image by active texture in the texture stack&amp;quot;);&lt;br /&gt;
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_IMAGE, &amp;quot;rna_SpaceImageEditor_auto_select_image_update&amp;quot;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, the '''SI_AUTO_SELECT_IMAGE''' RNA property calls this new function on every update:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
static void rna_SpaceImageEditor_auto_select_image_update(Main *bmain, Scene *scene, PointerRNA *ptr)&lt;br /&gt;
{	&lt;br /&gt;
	/* (kwk) Inform image spaces to update their view if they want to. */&lt;br /&gt;
	WM_main_add_notifier(NC_TEXTURE|ND_DATACHANGED, NULL);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '''rna_SpaceImageEditor_auto_select_image_update''' function only enqueues a notifier. Now the type of notifier is probably not the best choice since, we didn't actually change the texture but the boolean RNA property. With this update function the fourth use case is fully covered.&lt;br /&gt;
&lt;br /&gt;
==How to redraw the image in the image space?==&lt;br /&gt;
&lt;br /&gt;
The redraw or update of the image in the image space (UV/Image Editor) is initialized by it's listener function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
static void image_listener(ScrArea *sa, wmNotifier *wmn)&lt;br /&gt;
{&lt;br /&gt;
	SpaceImage *sima= (SpaceImage *)sa-&amp;gt;spacedata.first;&lt;br /&gt;
	&lt;br /&gt;
	/* context changes */&lt;br /&gt;
	switch(wmn-&amp;gt;category) {&lt;br /&gt;
		case NC_SCENE:&lt;br /&gt;
			switch(wmn-&amp;gt;data) {&lt;br /&gt;
				// ...&lt;br /&gt;
				// ...&lt;br /&gt;
				// ...&lt;br /&gt;
				/* (kwk) Redraw image if another object was selected. */&lt;br /&gt;
				case ND_OB_SELECT:&lt;br /&gt;
					if(sima-&amp;gt;lock &amp;amp;&amp;amp; (sima-&amp;gt;flag &amp;amp; SI_AUTO_SELECT_IMAGE)) {&lt;br /&gt;
						ED_area_tag_refresh(sa);&lt;br /&gt;
						ED_area_tag_redraw(sa);&lt;br /&gt;
					}&lt;br /&gt;
					break;					&lt;br /&gt;
			}&lt;br /&gt;
			break;&lt;br /&gt;
		// ...&lt;br /&gt;
		// ...&lt;br /&gt;
		// ...&lt;br /&gt;
		/* (kwk) Redraw image if active texture index changed. */&lt;br /&gt;
		case NC_TEXTURE:&lt;br /&gt;
		case NC_MATERIAL:&lt;br /&gt;
			switch(wmn-&amp;gt;data) {&lt;br /&gt;
				default:						&lt;br /&gt;
					if(sima-&amp;gt;lock &amp;amp;&amp;amp; (sima-&amp;gt;flag &amp;amp; SI_AUTO_SELECT_IMAGE)) {&lt;br /&gt;
						ED_area_tag_refresh(sa);&lt;br /&gt;
						ED_area_tag_redraw(sa);&lt;br /&gt;
					}&lt;br /&gt;
					break;&lt;br /&gt;
			}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code automatically refreshes and redraws the image space area in case there were any changes to the texture or the material or if another object was selected.&lt;br /&gt;
&lt;br /&gt;
The cool thing about the listener function is, that every instance of an image space uses the same listener and voila, we have auto-dispatching.&lt;br /&gt;
&lt;br /&gt;
==How to map use cases to the workflow?==&lt;br /&gt;
&lt;br /&gt;
It's a bit tricky to map the use cases from above to this workflow. &lt;br /&gt;
&lt;br /&gt;
Use case &amp;quot;1. explicitly selects another texture slot&amp;quot; required some changes to the update callback of the texture slot in '''rna_material.c'''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//...&lt;br /&gt;
//...&lt;br /&gt;
//...&lt;br /&gt;
&lt;br /&gt;
static void rna_Material_update(Main *bmain, Scene *scene, PointerRNA *ptr)&lt;br /&gt;
{&lt;br /&gt;
	Material *ma= ptr-&amp;gt;id.data;&lt;br /&gt;
&lt;br /&gt;
	DAG_id_flush_update(&amp;amp;ma-&amp;gt;id, 0);&lt;br /&gt;
	if(scene-&amp;gt;gm.matmode == GAME_MAT_GLSL)&lt;br /&gt;
		WM_main_add_notifier(NC_MATERIAL|ND_SHADING_DRAW, ma);&lt;br /&gt;
	else&lt;br /&gt;
		WM_main_add_notifier(NC_MATERIAL|ND_SHADING, ma);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static void rna_Material_active_texture_update(Main *bmain, Scene *scene, PointerRNA *ptr)&lt;br /&gt;
{&lt;br /&gt;
	/* XXX: (kwk) This is a hack to process changes to the active texture index. */&lt;br /&gt;
	WM_main_add_notifier(NC_TEXTURE|ND_DATACHANGED, NULL);&lt;br /&gt;
	&lt;br /&gt;
	rna_Material_update(bmain, scene, ptr);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//...&lt;br /&gt;
//...&lt;br /&gt;
//...&lt;br /&gt;
&lt;br /&gt;
void RNA_def_material(BlenderRNA *brna)&lt;br /&gt;
{&lt;br /&gt;
	StructRNA *srna;&lt;br /&gt;
	PropertyRNA *prop;&lt;br /&gt;
&lt;br /&gt;
	// ...&lt;br /&gt;
	// ...&lt;br /&gt;
	// ...&lt;br /&gt;
&lt;br /&gt;
	srna= RNA_def_struct(brna, &amp;quot;Material&amp;quot;, &amp;quot;ID&amp;quot;);&lt;br /&gt;
	RNA_def_struct_ui_text(srna, &amp;quot;Material&amp;quot;, &amp;quot;Material datablock to defined the appearance of geometric objects for rendering&amp;quot;);&lt;br /&gt;
	RNA_def_struct_ui_icon(srna, ICON_MATERIAL_DATA);&lt;br /&gt;
&lt;br /&gt;
	// ...&lt;br /&gt;
	// ...&lt;br /&gt;
	// ...&lt;br /&gt;
&lt;br /&gt;
	/* common */&lt;br /&gt;
	rna_def_animdata_common(srna);&lt;br /&gt;
	rna_def_mtex_common(srna, &amp;quot;rna_Material_mtex_begin&amp;quot;, &amp;quot;rna_Material_active_texture_get&amp;quot;, &amp;quot;rna_Material_active_texture_set&amp;quot;, &amp;quot;MaterialTextureSlot&amp;quot;, &amp;quot;rna_Material_active_texture_update&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//...&lt;br /&gt;
//...&lt;br /&gt;
//...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The I introduced a new update callback called '''rna_Material_active_texture_update''. Normally most of the material RNA properties (including the texture slot) use '''rna_Material_update''' as their update function. My update function is solely for the texture slot and after informing about a change to the texture, it calls the regular '''rna_Material_update''' function. &lt;br /&gt;
&lt;br /&gt;
The second and the third use case, required no changes any RNA property. Ony the image space listener needed to be changed to listen to '''NC_MATERIAL''' and '''NC_SCENE|ND_OB_SELECT'''.&lt;br /&gt;
&lt;br /&gt;
The fourth use case has been covered earlier.&lt;br /&gt;
&lt;br /&gt;
==How to select the new image for the image space?==&lt;br /&gt;
&lt;br /&gt;
You might wonder that until now the image space hasn't been told to display another image. Well, this is done in the '''image_refresh''' function which is called by '''ED_area_tag_refresh'''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
static void image_refresh(const bContext *C, ScrArea *sa)&lt;br /&gt;
{&lt;br /&gt;
	SpaceImage *sima= CTX_wm_space_image(C);&lt;br /&gt;
&lt;br /&gt;
	// ...&lt;br /&gt;
	// ...&lt;br /&gt;
	// ...&lt;br /&gt;
	&lt;br /&gt;
	/* (kwk) Now auto select image to display. */	&lt;br /&gt;
	if (sima-&amp;gt;flag &amp;amp; SI_AUTO_SELECT_IMAGE) {				&lt;br /&gt;
		/* Get current object. */&lt;br /&gt;
		Object *ob = CTX_data_active_object(C);	&lt;br /&gt;
		&lt;br /&gt;
		if (ob &amp;amp;&amp;amp; ob-&amp;gt;type == OB_MESH) {&lt;br /&gt;
			/* Get current texture. */&lt;br /&gt;
			Tex *tex = give_current_object_texture(ob);			&lt;br /&gt;
			&lt;br /&gt;
			if (tex &amp;amp;&amp;amp; tex-&amp;gt;type == TEX_IMAGE &amp;amp;&amp;amp; tex-&amp;gt;ima) {&lt;br /&gt;
				ED_space_image_set(C, sima, CTX_data_scene(C), obedit, tex-&amp;gt;ima);	&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We first check if for this very image space the auto select image option is enabled. Then we get the current object and the texture currently active in the object's material. If the texture is an image texture, we make the image space display the image associated with this texture.&lt;br /&gt;
&lt;br /&gt;
{{Page/Footer|User:Kwk/GSoC2010/FasterWayToAddMaps|User:Kwk/Gsoc2010/BumpMapPainting}}&lt;/div&gt;</summary>
		<author><name>wiki&gt;Kwk</name></author>
		
	</entry>
</feed>