From: Bruce S. <Bru...@nc...> - 2008-09-28 20:48:39
|
You ought to be able to specify a list of normals in the constructor for faces, but as you found, you can't; it's a bug. The only workaround is to do something like this: triangle1=faces(color=c) triangle1.append(pos=v1,normal=n1) triangle1.append(pos=v2,normal=n2) triangle1.append(pos=v3,normal=n3) Please be specific about your difficulty with copy; best would be a short example. Note from the Visual documentation that there are issues with copying objects that are in frames: __copy()__ Makes a copy of an object. There are two underscores before and after the copy(). Without any arguments, this results in creating a second object in the exact same position as the first, which is probably not what you want. The __copy__() function takes a list of keyword=value argument pairs which are applied to the new object before making it visible. For example, to clone an object from one display to another, you would execute: new_object = old_object.__copy__( display=new_display). Restriction: If the original object is within a frame, and the new object is on a different display, you must supply both a new display and a new frame for the new object (the new frame may be None). This is due to the restriction that an object may not be located within a frame that is in a separate display. The attribute __members__ used to give a list of all the object's attributes but is no longer available in VPython. Its main use was in copying objects. Poul Riis wrote: > I still can't see in the manual how two to specify different normals at > different vertices in the faces object. > I tried > triangle=faces(pos=[v1,v2,v3],normal=[n1,n2,n3],color=c) > but it didn't work. On the other hand, replacing color=c with > color=[c1,c2,c1] works fine. > > The example below works, but not if I replace normal=n12 with > normal=[n1,n12,n12] > > One further question: How can I make a copy of ny adjacent triangles > before rotating them? I tried __copy__() but couldn't make it work. > > Poul Riis > > > > > from visual import * > > def triangle3d(v1,v2,v3,trianglecolor): > c = color.hsv_to_rgb(trianglecolor) > n = norm(cross(v2-v1,v3-v1)) > triangle1=faces(pos=[v1,v2,v3],normal=n,color=c) > triangle2=faces(pos=[v2,v1,v3],normal=-n,color=c) > > def > adjacenttriangles3d(v1,v2,v3,v4,trianglecolor1,trianglecolor2,rotateang): > c1 = color.hsv_to_rgb(trianglecolor1) > c2 = color.hsv_to_rgb(trianglecolor2) > > backsidecolor1=(1-trianglecolor1[0],trianglecolor1[1],trianglecolor1[2]) > > backsidecolor2=(1-trianglecolor2[0],trianglecolor2[1],trianglecolor2[2]) > > bsc1 = color.hsv_to_rgb(backsidecolor1) > bsc2 = color.hsv_to_rgb(backsidecolor2) > n1 = norm(cross(v2-v1,v4-v1)) > n2 = norm(cross(v3-v2,v4-v3)) > n12 = norm((n1+n2)/2) > twotriangles=frame() > faces(frame=twotriangles,pos=[v1,v2,v4],normal=n12,color=[c1,c2,c1]) > faces(frame=twotriangles,pos=[v2,v3,v4],normal=n12,color=[c2,c1,c2]) > faces(frame=twotriangles,pos=[v2,v1,v4],normal=-n12,color=bsc1) > faces(frame=twotriangles,pos=[v3,v2,v4],normal=-n12,color=bsc2) > twotriangles.rotate(angle=rotateang, axis=(1,0,0), origin=(0,0,0)) > > scene=display(title="Two adjacent > triangles",width=600,height=600,forward=(-2,-1,-0.5),up=(0,0,1),background=(1,1,1)) > > # Grid in xy-plane: > for i in range(-10,11,1): > gridlinesx=curve(pos=[(i,-10,0),(i,10,0)],color=crayola.black) > gridlinesy=curve(pos=[(-10,i,0),(10,i,0)],color=crayola.black) > > # Axes: > xaxis=arrow(pos=(-10,0,0),axis=(20,0,0),shaftwidth=0.02,color=crayola.green) > yaxis=arrow(pos=(0,-10,0),axis=(0,20,0),shaftwidth=0.02,color=crayola.green) > zaxis=arrow(pos=(0,0,-10),axis=(0,0,20),shaftwidth=0.02,color=color.hsv_to_rgb((0.8,0.7,0.9))) > > # Four points, A, B, C, and D: > A=vector(5,0,0) > B=vector(8,10,0) > C=vector(0,7,0) > D=vector(0,0,15) > > # Objects: > > adjacenttriangles3d(A,B,C,D,(0.5,1,0.95),(0.75,1,0.95),pi/4.) > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users |