利用者:Koilz/2.56 mess about uv editor mesh draw code

提供: wiki
< 利用者:Koilz
2018年6月29日 (金) 05:53時点におけるYamyam (トーク | 投稿記録)による版 (1版 をインポートしました)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索
These are just notes, some examples of how things work.

I want to mess about with the GUI, ive picked the UV/Image Editor because its basic, kinda.

"UV.PNG"

The root C source code for most of this is in "source\blender\editors\space_image\".

The root source file is space_image.c.

Open it up, scroll to the bottom, you will probably find the setup function.

void ED_spacetype_image(void){
	..
}

This code sets the callback functions for each region for the UV editor.

Header
Main Window
Buttons
Scope
Properties

When they are set, stacked to list, registered to the spacetype:

	/* allocate ARegionType */
	art=MEM_callocN(sizeof(ARegionType), "spacetype image region");
	
	/* region setup */
	art->	regionid	= RGN_TYPE_HEADER;
	art->	prefsizey	= HEADERY;
	art->	keymapflag	= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES|ED_KEYMAP_HEADER;
	art->	listener	= image_header_area_listener;
	art->	init		= image_header_area_init;
	art->	draw		= image_header_area_draw;
	
	/* stack into list */
	BLI_addhead(&st->regiontypes, art);
	
	/* register spacetype */
	BKE_spacetype_register(st);

Blender will process the regions via the list.

Scroll up and you will find some code for the UV editor, callbacks, operators, register stuff.

..

Lets mess about with draw code, Properties region, Display panel buttons, [Outline][Dash][Black][White].

Display.PNG

This draws the uv mesh in different styles based on the active button.

The draw code for the uv mesh is in "source\blender\editors\uvedit\uvedit_draw.c".

static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit){
	..
}

Look for the code that draws the UV mesh edges/lines based on the active button. 2.56 looks like this:

	/* 4. draw edges */

	if(sima->flag & SI_SMOOTH_UV) {
		glEnable(GL_LINE_SMOOTH);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	}
	
	switch(sima->dt_uv) {
 		case SI_UVDT_DASH:
			..
		case SI_UVDT_BLACK: /* black/white */
		case SI_UVDT_WHITE:

			// set gl color, black or white

			if(sima->dt_uv==SI_UVDT_WHITE) glColor3f(1.0f, 1.0f, 1.0f);
			else glColor3f(0.0f, 0.0f, 0.0f);

			// loop list, uv faces

			for(efa= em->faces.first; efa; efa= efa->next) {
				tf= (MTFace *)efa->tmp.p; /* visible faces cached */

				if(tf) {

					// gl line loop, point to point, quad or triangle, black or white.

					glBegin(GL_LINE_LOOP);
						glVertex2fv(tf->uv[0]);
						glVertex2fv(tf->uv[1]);
						glVertex2fv(tf->uv[2]);
						if(efa->v4) glVertex2fv(tf->uv[3]);
					glEnd();
				}
			}
			break;
		case SI_UVDT_OUTLINE:
			..
	}

These keywords were passed to the draw function.

SpaceImage *sima	// data space image
Scene *scene		// data scene
Object *obedit		// data object
sima->dt_uv		// draw type, Outline, Dash, Black, White