本文整理汇总了Python中panda3d.core.GeomVertexWriter.addData3f方法的典型用法代码示例。如果您正苦于以下问题:Python GeomVertexWriter.addData3f方法的具体用法?Python GeomVertexWriter.addData3f怎么用?Python GeomVertexWriter.addData3f使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.GeomVertexWriter
的用法示例。
在下文中一共展示了GeomVertexWriter.addData3f方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_plane
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData3f [as 别名]
def add_plane(map_width, map_height):
# Prepare the vertex format writers
v_fmt = GeomVertexFormat.getV3n3c4()
v_data = GeomVertexData('TerrainData', v_fmt, Geom.UHStatic)
vertex = GeomVertexWriter(v_data, 'vertex')
normal = GeomVertexWriter(v_data, 'normal')
color = GeomVertexWriter(v_data, 'color')
#texcoord = GeomVertexWriter(v_data, 'texcoord')
# Create a primitive
prim = GeomTrifans(Geom.UHStatic)
poly_color = (uniform(0, 0.05), uniform(0, 0.5), uniform(0.5, 1), 0.5, )
for i, point in enumerate([
(-map_width/2, -map_height/2),
(map_width/2, -map_height/2),
(map_width/2, map_height/2),
(-map_width/2, map_height/2), ]):
x, y = point
vertex.addData3f(x, y, 0)
normal.addData3f(0, 0, 1)
color.addData4f(*poly_color)
#texcoord.addData2f(1, 0)
prim.addVertex(i)
prim.addVertex(0)
prim.closePrimitive()
# Add to the scene graph
geom = Geom(v_data)
geom.addPrimitive(prim)
node = GeomNode('gnode')
node.addGeom(geom)
nodePath = render.attachNewNode(node)
nodePath.setTwoSided(True)
nodePath.setAlphaScale(0.5)
示例2: makeSelectRect
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData3f [as 别名]
def makeSelectRect():
ctup = (1,1,1,1)
fmt = GeomVertexFormat.getV3c4()
vertexData = GeomVertexData('points', fmt, Geom.UHDynamic)
points = ( #makes nice for Tristrips
(0,0,0),
(0,0,1),
(1,0,0),
(1,0,1),
)
verts = GeomVertexWriter(vertexData, 'vertex')
color = GeomVertexWriter(vertexData, 'color')
for point in points:
verts.addData3f(*point)
color.addData4f(*ctup)
boxLines = GeomLinestrips(Geom.UHDynamic)
boxLines.addVertices(0,1,3,2)
boxLines.addVertex(0)
boxLines.closePrimitive()
boxTris = GeomTristrips(Geom.UHDynamic)
boxTris.addConsecutiveVertices(0,3)
boxTris.closePrimitive()
box = Geom(vertexData)
box.addPrimitive(boxLines)
#box.addPrimitive(boxTris)
return box
示例3: makePoints
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData3f [as 别名]
def makePoints(n=1000):
""" make a cloud of points that are a single node VS branching and making subnodes to control display """
#points = np.random.uniform(-10,10,(n,4))
points = np.random.randn(n,3)
colors = np.random.rand(n,4)
fmt = GeomVertexFormat.getV3c4() #3 component vertex, w/ 4 comp color
vertexData = GeomVertexData('points', fmt, Geom.UHStatic)
verts = GeomVertexWriter(vertexData, 'vertex')
color = GeomVertexWriter(vertexData, 'color')
for point,clr4 in zip(points,colors):
#for point in points:
verts.addData3f(*point)
#color.addData4f(*point)
color.addData4f(*clr4)
#color.addData4f(.1,.1,.1,1)
#pointCloud = GeomLinestrips(Geom.UHStatic) #this is fucking cool!
pointCloud = GeomTristrips(Geom.UHStatic) #this is fucking cool!
#pointCloud = GeomPoints(Geom.UHStatic)
#pointCloud.addVerticies(*range(n))
pointCloud.addConsecutiveVertices(0,n) #warning may error since n-1?
pointCloud.closePrimitive()
cloud = Geom(vertexData)
cloud.addPrimitive(pointCloud)
return cloud
示例4: __build_Star_Sphere
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData3f [as 别名]
def __build_Star_Sphere(self, bg_stars):
from panda3d.core import GeomVertexWriter, GeomVertexFormat, GeomVertexData
from panda3d.core import Geom, GeomNode, GeomPoints, AmbientLight
self.star_sphere_np.removeNode()
# Fill GeomVertexData.
vformat = GeomVertexFormat.getV3c4()
vdata = GeomVertexData("Data", vformat, Geom.UHStatic)
vertices = GeomVertexWriter(vdata, "vertex")
colours = GeomVertexWriter(vdata, "color")
for coords in bg_stars:
x, y, z = coords
vertices.addData3f(x, y, z)
colours.addData4f(1, 1, 1, 1)
# Render bg stars.
bg_stars = GeomPoints(Geom.UHStatic)
bg_stars.addNextVertices(_env.STAR_COUNT)
bg_stars_geom = Geom(vdata)
bg_stars_geom.addPrimitive(bg_stars)
star_sphere = GeomNode("star_sphere")
star_sphere.addGeom(bg_stars_geom)
star_sphere_np = NodePath(star_sphere)
star_sphere_np.reparentTo(self.NP)
return star_sphere_np
示例5: buildGeom
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData3f [as 别名]
def buildGeom(self, meshData):
prims = meshData["prims"]
vertices = meshData["vertices"]
normals = meshData["normals"]
texcoords = meshData["texcoords"]
vdata = GeomVertexData('mesh', GeomVertexFormat.getV3n3t2(), Geom.UHStatic)
vwriter = GeomVertexWriter(vdata, 'vertex')
nvwriter = GeomVertexWriter(vdata, 'normal')
tvwriter = GeomVertexWriter(vdata, 'texcoord')
for i in range(len(vertices)):
v = vertices[i]
n = normals[i]
t = texcoords[i]
vwriter.addData3f(v)
nvwriter.addData3f(n)
tvwriter.addData2f(t)
prim = GeomTriangles(Geom.UHStatic)
for i in range(len(prims)):
A, B, C = prims[i]
prim.addVertices(A, B, C)
prim.closePrimitive()
geom = Geom(vdata)
geom.addPrimitive(prim)
geomNode = GeomNode('trig')
geomNode.addGeom(geom)
geomNode.unify(1, True)
return geomNode
示例6: __build_Tris
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData3f [as 别名]
def __build_Tris(self, sphere, mode):
vdata = GeomVertexData("Data", self.__vformat[mode], Geom.UHStatic)
_num_rows = len(sphere.pts)
# Vertices.
vertices = GeomVertexWriter(vdata, "vertex")
vertices.reserveNumRows(_num_rows)
for pt in sphere.pts:
vertices.addData3f(*pt)
# Map coords.
if mode == "mid":
mapcoords = GeomVertexWriter(vdata, "mapcoord")
mapcoords.reserveNumRows(_num_rows)
for mc in sphere.coords:
u, v = mc[:2]
mapcoords.addData2f(u,v)
# Tris.
prim = GeomTriangles(Geom.UHStatic)
prim.reserveNumVertices(len(sphere.tris))
for tri in sphere.tris:
prim.addVertices(*tri)
prim.closePrimitive()
# Geom.
geom = Geom(vdata)
geom.addPrimitive(prim)
geom_node = GeomNode("geom")
geom_node.addGeom(geom)
geom_np = NodePath(geom_node)
return geom_np
示例7: makeGeom
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData3f [as 别名]
def makeGeom():
# Vertex data
fmt = GeomVertexFormat.getV3n3t2()
vdata = GeomVertexData('', fmt, Geom.UHStatic)
vertex = GeomVertexWriter(vdata, InternalName.getVertex())
normal = GeomVertexWriter(vdata, InternalName.getNormal())
texcoord = GeomVertexWriter(vdata, InternalName.getTexcoord())
for (x, y, z) in vertices:
vertex.addData3f(x, y, z)
normal.addData3f(0, 0, 0)
# Privitive
prim = GeomTriangles(Geom.UHStatic)
for (i1, i2, i3) in indices:
prim.addVertices(i1, i2, i3)
prim.closePrimitive()
# Geom
geom = Geom(vdata)
geom.addPrimitive(prim)
return geom
示例8: make_geom
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData3f [as 别名]
def make_geom(vertices, normals, colors, texcoords):
if panda3d is None: raise ImportError("Cannot locate Panda3D")
format = "V3"
if normals is not None:
assert len(normals) == len(vertices)
format += "n3"
if colors is not None:
assert len(colors) == len(vertices)
format += "cp"
if texcoords is not None:
assert len(texcoords) == len(vertices)
format += "t2"
format = getattr(GeomVertexFormat, "get" + format)()
vdata = GeomVertexData("", format, Geom.UHStatic)
v_vertex = GeomVertexWriter(vdata, 'vertex')
if normals is not None: v_normals = GeomVertexWriter(vdata, 'normal')
if colors is not None: v_colors = GeomVertexWriter(vdata, 'color')
if texcoords is not None: v_texcoords = GeomVertexWriter(vdata, 'texcoord')
for n in range(len(vertices)):
v_vertex.addData3f(*vertices[n])
if normals is not None: v_normals.addData3f(*normals[n])
if colors is not None: v_colors.addData4f(*colors[n])
if texcoords is not None: v_texcoords.addData2f(*texcoords[n])
return Geom(vdata)
示例9: __build_Patches
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData3f [as 别名]
def __build_Patches(self, sphere):
vdata = GeomVertexData("Data", self.__vformat['high'], Geom.UHStatic)
vertices = GeomVertexWriter(vdata, "vertex")
mapcoords = GeomVertexWriter(vdata, "mapcoord")
texcoords = GeomVertexWriter(vdata, "texcoord")
_num_rows = len(sphere.pts)
vertices.reserveNumRows(_num_rows)
mapcoords.reserveNumRows(_num_rows)
texcoords.reserveNumRows(_num_rows)
# Pts.
for pt, uv, coords, in zip(sphere.pts, sphere.uvs, sphere.coords):
vertices.addData3f(*pt)
mapcoords.addData2f(*coords)
texcoords.addData2f(*uv) ## *.99+.01)
# Patches.
prim = GeomPatches(3, Geom.UHStatic)
prim.reserveNumVertices(len(sphere.tris))
for tri in sphere.tris:
prim.addVertices(*tri)
prim.closePrimitive()
# Geom.
geom = Geom(vdata)
geom.addPrimitive(prim)
geom_node = GeomNode("geom")
geom_node.addGeom(geom)
geom_np = NodePath(geom_node)
return geom_np
示例10: draw
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData3f [as 别名]
def draw(self):
if self.rendered_mesh != None:
self.reset_draw()
format=GeomVertexFormat.getV3n3cp()
vdata=GeomVertexData('tri', format, Geom.UHDynamic)
vertex=GeomVertexWriter(vdata, 'vertex')
normal=GeomVertexWriter(vdata, 'normal')
color=GeomVertexWriter(vdata, 'color')
v_mapping = {}
i=0
for v in self.verts.values():
vertex.addData3f(v.pos.x,v.pos.y,v.pos.z)
normal.addData3f(v.norm.x, v.norm.y, v.norm.z)
color.addData4f(v.color[0],v.color[1],v.color[2],v.color[3])
v_mapping[v.ID] = i
i += 1
mesh = Geom(vdata)
for f in self.faces.values():
tri = GeomTriangles(Geom.UHDynamic)
tri.addVertex(v_mapping[f.v1.ID])
tri.addVertex(v_mapping[f.v2.ID])
tri.addVertex(v_mapping[f.v3.ID])
tri.closePrimitive()
mesh.addPrimitive(tri)
snode = GeomNode(self.name)
snode.addGeom(mesh)
self.rendered_mesh = render.attachNewNode(snode)
self.rendered_mesh.setTwoSided(True)
示例11: create_geom
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData3f [as 别名]
def create_geom(self, sidelength):
# Set up the vertex arrays
vformat = GeomVertexFormat.getV3n3c4()
vdata = GeomVertexData("Data", vformat, Geom.UHDynamic)
vertex = GeomVertexWriter(vdata, 'vertex')
normal = GeomVertexWriter(vdata, 'normal')
color = GeomVertexWriter(vdata, 'color')
geom = Geom(vdata)
# Write vertex data
for x in range(0, sidelength):
for y in range(0, sidelength):
# vertex_number = x * sidelength + y
v_x, v_y, v_z = self.map_b[(x, y)]
n_x, n_y, n_z = 0.0, 0.0, 1.0
c_r, c_g, c_b, c_a = 0.5, 0.5, 0.5, 0.5
vertex.addData3f(v_x, v_y, v_z)
normal.addData3f(n_x, n_y, n_z)
color.addData4f(c_r, c_g, c_b, c_a)
# Add triangles
for x in range(0, sidelength - 1):
for y in range(0, sidelength - 1):
# The vertex arrangement (y up, x right)
# 2 3
# 0 1
v_0 = x * sidelength + y
v_1 = x * sidelength + (y + 1)
v_2 = (x + 1) * sidelength + y
v_3 = (x + 1) * sidelength + (y + 1)
if (x+y)%1 == 0: # An even square
tris = GeomTriangles(Geom.UHStatic)
tris.addVertices(v_0, v_2, v_3)
tris.closePrimitive()
geom.addPrimitive(tris)
tris = GeomTriangles(Geom.UHStatic)
tris.addVertices(v_3, v_1, v_0)
tris.closePrimitive()
geom.addPrimitive(tris)
else: # An odd square
tris = GeomTriangles(Geom.UHStatic)
tris.addVertices(v_1, v_0, v_2)
tris.closePrimitive()
geom.addPrimitive(tris)
tris = GeomTriangles(Geom.UHStatic)
tris.addVertices(v_2, v_3, v_1)
tris.closePrimitive()
geom.addPrimitive(tris)
# Create the actual node
node = GeomNode('geom_node')
node.addGeom(geom)
# Remember GeomVertexWriters to adjust vertex data later
#self.vertex_writer = vertex
#self.color_writer = color
self.vdata = vdata
return node
示例12: update_geometry
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData3f [as 别名]
def update_geometry(self):
# The geosphere itself
vertex = GeomVertexWriter(self.sphere_vdata, 'vertex')
normal = GeomVertexWriter(self.sphere_vdata, 'normal')
# u_map and v_map are in [-pi, pi]
u_map_list = [(float(u) / float(self.res[0]) - 0.5) * 2.0 * pi for u in range(0, self.res[0] + 1)]
v_map_list = [(float(v) / float(self.res[1]) - 0.5) * 2.0 * pi for v in range(0, self.res[1] + 1)]
if self.unwrap_state == 0.0: # Flat map
for v_map in v_map_list:
for u_map in u_map_list:
vertex.addData3f(u_map, 0.0, v_map / 2.0)
normal.addData3f(0.0, -1.0, 0.0)
else: # Non-flat map
sphere_radius = 1.0 / self.unwrap_state
sphere_offset = sphere_radius - self.unwrap_state
for v_map in v_map_list:
for u_map in u_map_list:
u_sphere = u_map / sphere_radius
v_sphere = v_map / sphere_radius
# And this, kids, is why you should pay attention in trigonometry.
v_x, v_y, v_z = sin(u_sphere) * cos(v_sphere/2.0) * sphere_radius, \
-cos(u_sphere) * cos(v_sphere/2.0) * sphere_radius + sphere_offset, \
sin(v_sphere / 2.0) * sphere_radius
n_x_un, n_y_un, n_z_un = v_x, sphere_offset - v_y, v_z # FIXME: This is a lie.
length = sqrt(n_x_un**2 + n_y_un**2 + n_z_un**2)
n_x, n_y, n_z = n_x_un / length, n_y_un / length, n_z_un / length
vertex.addData3f(v_x, v_y, v_z)
normal.addData3f(n_x, n_y, n_z)
# The connections between bases
segs_per_connection = 30
vertex = GeomVertexWriter(self.connections_vdata, 'vertex')
color = GeomVertexWriter(self.connections_vdata, 'color')
for c_1_uv, c_2_uv in self.connections:
# s will be [0.0, 1.0]
for s in [float(c)/float(segs_per_connection+1) for c in range(0, segs_per_connection+2)]:
u = (c_1_uv[0] * s) + (c_2_uv[0] * (1.0 - s))
v = (c_1_uv[1] * s) + (c_2_uv[1] * (1.0 - s))
(v_x, v_y, v_z), (n_x, n_y, n_z) = self.uv_to_xyz(u, v)
min_height = 0.0001 * (1.0 - self.unwrap_state)
max_height = (0.2 - min_height) * self.unwrap_state
seg_height = (1.0 - (abs(s-0.5) * 2.0)**2.0) * max_height + min_height
vertex.addData3f(v_x + n_x*seg_height,
v_y + n_y*seg_height,
v_z + n_z*seg_height)
color.addData4f(1, 1, 1, 1)
for c in range(0, len(self.connections)):
for s in range(0, segs_per_connection+1):
seg = GeomLines(Geom.UHDynamic)
seg.addVertices(c*(segs_per_connection+2) + s, c*(segs_per_connection+2) + s + 1)
seg.closePrimitive()
self.connections_geom.addPrimitive(seg)
示例13: makeAxis
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData3f [as 别名]
def makeAxis(): #FIXME make this scale based on zoom???
"""
x y z
r g b
"""
colors = (
(1,0,0,1),
(0,1,0,1),
(0,0,1,1),
(1,0,0,1),
(0,1,0,1),
(0,0,1,1),
)
points = (
(0,0,0),
(0,0,0),
(0,0,0),
(1,0,0),
(0,1,0),
(0,0,1),
)
fmt = GeomVertexFormat.getV3c4() #3 component vertex, w/ 4 comp color
#fmt = GeomVertexFormat.getV3() #3 component vertex, w/ 4 comp color
vertexData = GeomVertexData('points', fmt, Geom.UHStatic)
verts = GeomVertexWriter(vertexData, 'vertex')
color = GeomVertexWriter(vertexData, 'color')
for p,c in zip(points,colors):
verts.addData3f(*p)
color.addData4f(*c)
axisX = GeomLinestrips(Geom.UHStatic)
axisX.addVertices(0,3)
axisX.closePrimitive()
axisY = GeomLinestrips(Geom.UHStatic)
axisY.addVertices(1,4)
axisY.closePrimitive()
axisZ = GeomLinestrips(Geom.UHStatic)
axisZ.addVertices(2,5)
axisZ.closePrimitive()
axis = Geom(vertexData)
axis.addPrimitive(axisX)
axis.addPrimitive(axisY)
axis.addPrimitive(axisZ)
return axis
示例14: drawBody
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData3f [as 别名]
def drawBody(self, pos, quat, radius=1,UVcoord=(1,1), numVertices=_polySize):
# if isRoot:
# self.bodydata = GeomVertexData("body vertices", GeomVertexFormat.getV3n3t2(), Geom.UHStatic)
vdata = self.bodydata
circleGeom = Geom(vdata) # this was originally a copy of all previous geom in vdata...
vertWriter = GeomVertexWriter(vdata, "vertex")
#colorWriter = GeomVertexWriter(vdata, "color")
normalWriter = GeomVertexWriter(vdata, "normal")
# drawReWriter = GeomVertexRewriter(vdata, "drawFlag")
texReWriter = GeomVertexRewriter(vdata, "texcoord")
startRow = vdata.getNumRows()
vertWriter.setRow(startRow)
#colorWriter.setRow(startRow)
normalWriter.setRow(startRow)
texReWriter.setRow(startRow)
#axisAdj=Mat4.rotateMat(45, axis)*Mat4.scaleMat(radius)*Mat4.translateMat(pos)
perp1 = quat.getRight()
perp2 = quat.getForward()
#TODO: PROPERLY IMPLEMENT RADIAL NOISE
#vertex information is written here
angleSlice = 2 * pi / numVertices
currAngle = 0
for i in xrange(numVertices+1):
adjCircle = pos + (perp1 * cos(currAngle) + perp2 * sin(currAngle)) * radius * (.5+bNodeRadNoise*random.random())
normal = perp1 * cos(currAngle) + perp2 * sin(currAngle)
normalWriter.addData3f(normal)
vertWriter.addData3f(adjCircle)
texReWriter.addData2f(float(UVcoord[0]*i) / numVertices,UVcoord[1]) # UV SCALE HERE!
#colorWriter.addData4f(0.5, 0.5, 0.5, 1)
currAngle += angleSlice
#we cant draw quads directly so we use Tristrips
if (startRow != 0):
lines = GeomTristrips(Geom.UHStatic)
for i in xrange(numVertices+1):
lines.addVertex(i + startRow)
lines.addVertex(i + startRow - numVertices-1)
lines.addVertex(startRow)
lines.addVertex(startRow - numVertices)
lines.closePrimitive()
#lines.decompose()
circleGeom.addPrimitive(lines)
circleGeomNode = GeomNode("Debug")
circleGeomNode.addGeom(circleGeom)
self.numPrimitives += numVertices * 2
self.bodies.attachNewNode(circleGeomNode)
return circleGeomNode
示例15: makeRotationGeomNode
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData3f [as 别名]
def makeRotationGeomNode():
vdata = GeomVertexData('rotHandleData', GeomVertexFormat.getV3(),
Geom.UHStatic)
v = GeomVertexWriter(vdata, 'vertex')
radius = 0.7
width = 0.08
res = 30
innerRad = radius - width
for i in xrange(res):
theta = i*(2*pi/res)
v.addData3f(innerRad*sin(theta), innerRad*cos(theta), width/2.0)
v.addData3f(innerRad*sin(theta), innerRad*cos(theta), -width/2.0)
v.addData3f(radius*sin(theta), radius*cos(theta), width/2.0)
v.addData3f(radius*sin(theta), radius*cos(theta), -width/2.0)
circle = Geom(vdata)
# Make prims for the faces of the torus
faces = [GeomTristrips(Geom.UHStatic) for i in xrange(4)]
for i in xrange(res):
i = i*4
faces[0].addVertices(i + 1, i)
faces[1].addVertices(i + 2, i + 1)
faces[2].addVertices(i + 3, i + 2)
faces[3].addVertices(i, i + 3)
for i in xrange(4):
faces[i].addVertices((i + 1) % 4, i)
faces[i].closePrimitive()
circle.addPrimitive(faces[i])
node = GeomNode('geomnode')
node.addGeom(circle)
return node