Working on a copy of NMesh

I need to update only the viewable portion of a mesh, since updating the entire mesh is too slow.

I was attempting to do something like


import copy

tempMesh = copy.copy(myMesh)
myMesh.faces = []
myMesh.verts = []

faceList, vertList = createSublist(tempMesh)
myMesh.faces = faceList
myMesh.verts = vertList

def doStuff():
	...
	myMesh.update()
	...

myMesh = tempMesh
myMesh.update()

however copy and deepcopy give me an error.

Can someone suggest and alternative?

Thanks,

LetterRip

copy module does not work on NMesh data.

Yeah I figured that,

here is what I’m trying but now I’m getting an error



scene = Scene.GetCurrent()		# create a new scene
workingObject = Object.New('Mesh')	# create a new mesh object
workingObject.link(workingMesh)		# (*) link data to object first
scene.link(workingObject) 
scene.unlink(myObject)

workingMesh.faces.append(myMesh.faces[0])
for vert in myMesh.faces[0]:
	workingMesh.verts.append(vert)

for vert in workingMesh.verts:
	print vert
	vert.co += vert.no

scene.link(myObject) 
scene.unlink(workingObject)

myMesh.update()
Window.RedrawAll()

The error i get is ‘AttributeError co’

LetterRip

co and no are lists you can 't do an “+=”

for vert in workingMesh.verts:
   print dir(vert)
   for c in [0,1,2]:
        vert.co[c] += vert.no[c]

I feel silly…

thanks, I’ve even used it that way before… just tired I guess…

LetterRip

Actually, co and no are vectors. There seems to be some confusion about that for some reason, even in the python mailing list (comments in the ‘python can do operator overloading’ thread).
In any case, since they are vectors, normally using ‘+=’ would work. However, direct assigment to co is not (yet?) implemented in the current code, so you would still have to do it element by element.

Actually, co and no are vectors. [/quote]

Do you mean that a vector is not a list of 3 floats ?

For co=[1.0,1.0,1.0] and no=[1.0,1.0,1.0]
in python co+=no gives [1.0,1.0,1.0,1.0,1.0,1.0] and not [2.0,2.0,2.0].

No, I mean, they are of type vector (mathutils module), just try:


print type(mesh.verts[0].co)

So the equivalent of your example would be:


from Blender.Mathutils import *
co, no = Vector([1.0, 1.0, 1.0]), Vector([1.0, 1.0, 1.0])
co += no
print co

but as I said, direct assigment for ‘co’ is not implemented yet, so you would still have to assign element by element.

Okay, hopefully my last dumb question <grin>


import Blender
from Blender import Scene, Object, NMesh, Window, Mathutils
from Blender.Mathutils import Vector

myObject = Object.GetSelected()[0]
myMesh = myObject.getData()
workingMesh = NMesh.New('working')

scene = Scene.GetCurrent()		# create a new scene
workingObject = Object.New('Mesh')	# create a new mesh object
workingObject.link(workingMesh)		# (*) link data to object first
scene.link(workingObject) 
scene.unlink(myObject)

workingMesh.faces.append(myMesh.faces[0])
for vert in workingMesh.faces[0]:
	workingMesh.verts.append(vert)

for vert in workingMesh.verts:
	print dir(vert)
	for c in range(0,3):
		vert.co[c] += vert.no[c]

#NMesh.PutRaw(workingMesh, 'working', 1)
#workingMesh.update()
scene.link(myObject) 
scene.unlink(workingObject)

myMesh.update()
Window.RedrawAll()

This gives the expected results, but if I uncomment the two lines, and comment out the three below them, the mesh just dissapears. What I expected was a single face to be drawn.

Is there something elese I need to do?

LetterRip

A quick note,

I do occassionaly get a result that a single face is drawn but 90% of the time I don’t. Repeating the exact same setup it doesn’t work.

LetterRip

Just read a more recent version of the documentation and saw the hint regarding makeDisplaylist… will try that,

LetterRip

module-copy.html in python Library Reference

In order for a class to define its own copy implementation, it can define special methods copy() and deepcopy().