[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12108] trunk/blender: added an active face for the mesh editmode and normal mesh - this is needed because the TFace flag was not always easy to access from editmode .

Campbell Barton cbarton at metavr.com
Sat Sep 22 19:54:13 CEST 2007


Revision: 12108
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12108
Author:   campbellbarton
Date:     2007-09-22 19:54:13 +0200 (Sat, 22 Sep 2007)

Log Message:
-----------
added an active face for the mesh editmode and normal mesh - this is needed because the TFace flag was not always easy to access from editmode.
using the last selected face was almost good enough however when selecting verts and edges the last selected face would become inactive and the space image would flicker about too much.
The active face is used for getting the space image at the moment and keeps scripts that use this flag working also.

This has 2 commands to get and set, so the variable is not accessed directly.

all "UV Calculate" scripts work now

last commit crashed when in solid draw mode, it seems subsurf modifier is ignoring the displayMask since MTFACE is available. just made it do a null check for now.

uvcalc_follow_active_coords.py - should be done inC and put in the snap menu.

Modified Paths:
--------------
    trunk/blender/release/scripts/uvcalc_follow_active_coords.py
    trunk/blender/release/scripts/uvcalc_lightmap.py
    trunk/blender/release/scripts/uvcalc_quad_clickproj.py
    trunk/blender/release/scripts/uvcalc_smart_project.py
    trunk/blender/source/blender/blenkernel/intern/image.c
    trunk/blender/source/blender/blenkernel/intern/subsurf_ccg.c
    trunk/blender/source/blender/blenlib/BLI_editVert.h
    trunk/blender/source/blender/include/BIF_editmesh.h
    trunk/blender/source/blender/makesdna/DNA_mesh_types.h
    trunk/blender/source/blender/makesdna/DNA_meshdata_types.h
    trunk/blender/source/blender/python/api2_2x/Mesh.c
    trunk/blender/source/blender/python/api2_2x/NMesh.c
    trunk/blender/source/blender/src/drawimage.c
    trunk/blender/source/blender/src/drawmesh.c
    trunk/blender/source/blender/src/editface.c
    trunk/blender/source/blender/src/editmesh.c
    trunk/blender/source/blender/src/editmesh_lib.c
    trunk/blender/source/blender/src/editmesh_mods.c
    trunk/blender/source/blender/src/editsima.c

Removed Paths:
-------------
    trunk/blender/release/scripts/uvcalc_from_adjacent.py

Modified: trunk/blender/release/scripts/uvcalc_follow_active_coords.py
===================================================================
--- trunk/blender/release/scripts/uvcalc_follow_active_coords.py	2007-09-22 15:42:28 UTC (rev 12107)
+++ trunk/blender/release/scripts/uvcalc_follow_active_coords.py	2007-09-22 17:54:13 UTC (rev 12108)
@@ -51,6 +51,11 @@
 		Draw.PupMenu('ERROR: No mesh object.')
 		return
 	
+	# Toggle Edit mode
+	is_editmode = Window.EditMode()
+	if is_editmode:
+		Window.EditMode(0)
+	
 	me = ob.getData(mesh=1)
 	me_verts = me.verts
 	
@@ -233,7 +238,12 @@
 				
 				face_modes[i] = 2 # dont search again
 	print  sys.time() - t
-	me.update()
+	
+	if is_editmode:
+		Window.EditMode(1)
+	else:
+		me.update()
+	
 	Window.RedrawAll()
 	Window.WaitCursor(0)
 

Deleted: trunk/blender/release/scripts/uvcalc_from_adjacent.py
===================================================================
--- trunk/blender/release/scripts/uvcalc_from_adjacent.py	2007-09-22 15:42:28 UTC (rev 12107)
+++ trunk/blender/release/scripts/uvcalc_from_adjacent.py	2007-09-22 17:54:13 UTC (rev 12108)
@@ -1,129 +0,0 @@
-#!BPY
-"""
-Name: 'UVs from unselected adjacent'
-Blender: 242
-Group: 'UVCalculation'
-Tooltip: 'Assign UVs to selected faces from surrounding unselected faces.'
-"""
-__author__ = "Campbell Barton"
-__url__ = ("blender", "elysiun")
-__version__ = "1.0 2006/02/07"
-
-__bpydoc__ = """\
-This script sets the UV mapping and image of selected faces from adjacent unselected faces.
-
-Use this script in face select mode for texturing between textured faces.
-"""
-
-# ***** BEGIN GPL LICENSE BLOCK *****
-#
-# Script copyright (C) Campbell J Barton
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-#
-# ***** END GPL LICENCE BLOCK *****
-# --------------------------------------------------------------------------
-
-
-from Blender import *
-import bpy
-
-def mostUsedImage(imageList): # Returns the image most used in the list.
-	if not imageList:
-		return None
-	elif len(imageList) < 3:
-		return imageList[0]
-	
-	# 3+ Images, Get the most used image for surrounding faces.
-	imageCount = {}
-	for image in imageList:
-		if image:
-			image_key= image.name
-		else:
-			image_key = None
-		
-		try:
-			imageCount[image_key]['imageCount'] +=1 # an extra user of this image
-		except:
-			imageCount[image_key] = {'imageCount':1, 'blenderImage':image} # start with 1 user.
-	
-	# Now a list of tuples, (imageName, {imageCount, image})
-	imageCount = imageCount.items()
-	
-	try:	imageCount.sort(key=lambda a: a[1])
-	except:	imageCount.sort(lambda a,b: cmp(a[1], b[1]))
-	
-	
-	return imageCount[-1][1]['blenderImage']	
-
-
-def main():
-	scn = bpy.data.scenes.active
-	ob = scn.objects.active
-	if ob == None or ob.type != 'Mesh':
-		Draw.PupMenu('ERROR: No mesh object in face select mode.')
-		return
-	me = ob.getData(mesh=1)
-	
-	if not me.faceUV:
-		Draw.PupMenu('ERROR: No mesh object in face select mode.')
-		return
-	
-	selfaces = [f for f in me.faces if f.sel]
-	unselfaces = [f for f in me.faces if not f.sel if not f.hide]
-	
-	# Gather per Vert UV and Image, store in vertUvAverage
-	vertUvAverage = [[[],[]] for i in xrange(len(me.verts))]
-	
-	for f in unselfaces: # Unselected faces only.
-		fuv = f.uv
-		for i,v in enumerate(f):
-			vertUvAverage[v.index][0].append(fuv[i])
-			vertUvAverage[v.index][1].append(f.image)
-			
-	# Average per vectex UV coords
-	for vertUvData in vertUvAverage:
-		uvList = vertUvData[0]
-		if uvList:
-			# Convert from a list of vectors into 1 vector.
-			vertUvData[0] = reduce(lambda a,b: a+b, uvList, Mathutils.Vector(0,0)) * (1.0/len(uvList))
-		else:
-			vertUvData[0] = None
-	
-	
-	
-	# Assign to selected faces
-	TEX_FLAG = Mesh.FaceModes['TEX']
-	for f in selfaces:
-		uvlist = []
-		imageList = []
-		for i,v in enumerate(f):
-			uv, vImages = vertUvAverage[v.index]
-			uvlist.append( uv )
-			imageList.extend(vImages)
-		
-		if None not in uvlist:			
-			# all the faces images used by this faces vert. some faces will be added twice but thats ok.
-			# Get the most used image and assign to the face.
-			image = mostUsedImage(imageList) 
-			f.uv = uvlist
-			
-			if image:
-				f.image = image
-				f.mode |= TEX_FLAG
-	Window.RedrawAll()
-	
-if __name__ == '__main__':
-	main()
\ No newline at end of file

Modified: trunk/blender/release/scripts/uvcalc_lightmap.py
===================================================================
--- trunk/blender/release/scripts/uvcalc_lightmap.py	2007-09-22 15:42:28 UTC (rev 12107)
+++ trunk/blender/release/scripts/uvcalc_lightmap.py	2007-09-22 17:54:13 UTC (rev 12108)
@@ -544,6 +544,12 @@
 			Draw.PupMenu('Error%t|No mesh objects selected.')
 			return
 	
+	# Toggle Edit mode
+	is_editmode = Window.EditMode()
+	if is_editmode:
+		Window.EditMode(0)
+
+
 	Window.WaitCursor(1)
 	lightmap_uvpack(meshes,\
 			PREF_SEL_ONLY.val,\
@@ -554,6 +560,9 @@
 			PREF_BOX_DIV.val,\
 			int(1/(PREF_MARGIN_DIV.val/100)))
 	
+	if is_editmode:
+		Window.EditMode(1)
+	
 	Window.WaitCursor(0)
 
 if __name__ == '__main__':

Modified: trunk/blender/release/scripts/uvcalc_quad_clickproj.py
===================================================================
--- trunk/blender/release/scripts/uvcalc_quad_clickproj.py	2007-09-22 15:42:28 UTC (rev 12107)
+++ trunk/blender/release/scripts/uvcalc_quad_clickproj.py	2007-09-22 17:54:13 UTC (rev 12108)
@@ -80,6 +80,10 @@
 	if not ob or ob.type!='Mesh':
 		return
 	
+	is_editmode = Window.EditMode()
+	if is_editmode:
+		Window.EditMode(0)
+	
 	mousedown_wait() # so the menu items clicking dosnt trigger the mouseclick
 	
 	Window.DrawProgressBar (0.0, '')
@@ -100,10 +104,8 @@
 		mouse_buttons = Window.GetMouseButtons()
 	
 	
-	
 	Window.DrawProgressBar (0.2, '(2 of 3 ) Click confirms the U coords')
 	
-	
 	mousedown_wait()
 	
 	obmat= ob.matrixWorld
@@ -112,7 +114,7 @@
 	
 	if not mouseInView or not OriginA:
 		return
-		
+	
 	me = ob.getData(mesh=1)
 	
 	# Get the face under the mouse
@@ -255,6 +257,9 @@
 		Window.Redraw(Window.Types.VIEW3D)
 	
 	Window.SetCursorPos(*orig_cursor)
+	if is_editmode:
+		Window.EditMode(1)
+	
 	Window.RedrawAll()
 	
 if __name__=='__main__':

Modified: trunk/blender/release/scripts/uvcalc_smart_project.py
===================================================================
--- trunk/blender/release/scripts/uvcalc_smart_project.py	2007-09-22 15:42:28 UTC (rev 12107)
+++ trunk/blender/release/scripts/uvcalc_smart_project.py	2007-09-22 17:54:13 UTC (rev 12108)
@@ -1121,6 +1121,9 @@
 	print "Smart Projection time: %.2f" % (sys.time() - time1)
 	# Window.DrawProgressBar(0.9, "Smart Projections done, time: %.2f sec." % (sys.time() - time1))
 	
+	if is_editmode:
+		Window.EditMode(1)
+	
 	Window.DrawProgressBar(1.0, "")
 	Window.WaitCursor(0)
 	Window.RedrawAll()

Modified: trunk/blender/source/blender/blenkernel/intern/image.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image.c	2007-09-22 15:42:28 UTC (rev 12107)
+++ trunk/blender/source/blender/blenkernel/intern/image.c	2007-09-22 17:54:13 UTC (rev 12108)
@@ -243,6 +243,7 @@
 		ima->ok= IMA_OK;
 		
 		ima->xrep= ima->yrep= 1;
+		ima->aspx= ima->aspy= 1.0;
 		ima->gen_x= 256; ima->gen_y= 256;
 		ima->gen_type= 1;	/* no defines yet? */
 		

Modified: trunk/blender/source/blender/blenkernel/intern/subsurf_ccg.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/subsurf_ccg.c	2007-09-22 15:42:28 UTC (rev 12107)
+++ trunk/blender/source/blender/blenkernel/intern/subsurf_ccg.c	2007-09-22 17:54:13 UTC (rev 12108)
@@ -1881,28 +1881,30 @@
 	MTFace *tf = DM_get_face_data_layer(dm, CD_MTFACE);
 	int i;
 	
-	glBegin(GL_LINES);
-	for(i = 0; i < dm->numFaceData; i++, mf++, tf++) {
-		if(!(mf->flag&ME_HIDE)) {
-			glVertex2fv(tf->uv[0]);
-			glVertex2fv(tf->uv[1]);
-
-			glVertex2fv(tf->uv[1]);
-			glVertex2fv(tf->uv[2]);
-
-			if(!mf->v4) {
-				glVertex2fv(tf->uv[2]);
+	if (tf) {
+		glBegin(GL_LINES);
+		for(i = 0; i < dm->numFaceData; i++, mf++, tf++) {
+			if(!(mf->flag&ME_HIDE)) {
 				glVertex2fv(tf->uv[0]);
-			} else {
+				glVertex2fv(tf->uv[1]);
+	
+				glVertex2fv(tf->uv[1]);
 				glVertex2fv(tf->uv[2]);
-				glVertex2fv(tf->uv[3]);
-
-				glVertex2fv(tf->uv[3]);
-				glVertex2fv(tf->uv[0]);
+	
+				if(!mf->v4) {
+					glVertex2fv(tf->uv[2]);
+					glVertex2fv(tf->uv[0]);
+				} else {
+					glVertex2fv(tf->uv[2]);
+					glVertex2fv(tf->uv[3]);
+	
+					glVertex2fv(tf->uv[3]);
+					glVertex2fv(tf->uv[0]);
+				}
 			}
 		}
+		glEnd();
 	}
-	glEnd();
 }
 
 static void ccgDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *userData, int index, int *drawSmooth_r), void *userData, int useColors) {

Modified: trunk/blender/source/blender/blenlib/BLI_editVert.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_editVert.h	2007-09-22 15:42:28 UTC (rev 12107)
+++ trunk/blender/source/blender/blenlib/BLI_editVert.h	2007-09-22 17:54:13 UTC (rev 12108)
@@ -164,6 +164,13 @@
 		/* DerivedMesh caches... note that derived cage can be equivalent
 		 * to derived final, care should be taken on release.
 		 */
+	
+	/* used for keeping track of the last clicked on face - so the space image
+	 * when using the last selected face - (EditSelection) the space image flickered too much
+	 * 
+	 * never access this directly, use EM_set_actFace and EM_get_actFace */
+	EditFace *act_face; 
+	
 	struct DerivedMesh *derivedCage, *derivedFinal;
 	/* the custom data layer mask that was last used to calculate
 	 * derivedCage and derivedFinal

Modified: trunk/blender/source/blender/include/BIF_editmesh.h
===================================================================
--- trunk/blender/source/blender/include/BIF_editmesh.h	2007-09-22 15:42:28 UTC (rev 12107)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list