本文整理汇总了Python中panda3d.core.GeomVertexWriter.setRow方法的典型用法代码示例。如果您正苦于以下问题:Python GeomVertexWriter.setRow方法的具体用法?Python GeomVertexWriter.setRow怎么用?Python GeomVertexWriter.setRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.GeomVertexWriter
的用法示例。
在下文中一共展示了GeomVertexWriter.setRow方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: drawBody
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import setRow [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
示例2: makeCircle
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import setRow [as 别名]
def makeCircle(vdata, numVertices=40,offset=Vec3(0,0,0), direction=1):
circleGeom=Geom(vdata)
vertWriter=GeomVertexWriter(vdata, "vertex")
normalWriter=GeomVertexWriter(vdata, "normal")
colorWriter=GeomVertexWriter(vdata, "color")
uvWriter=GeomVertexWriter(vdata, "texcoord")
drawWriter=GeomVertexWriter(vdata, "drawFlag")
#make sure we start at the end of the GeomVertexData so we dont overwrite anything
#that might be there already
startRow=vdata.getNumRows()
vertWriter.setRow(startRow)
colorWriter.setRow(startRow)
uvWriter.setRow(startRow)
normalWriter.setRow(startRow)
drawWriter.setRow(startRow)
angle=2*math.pi/numVertices
currAngle=angle
for i in range(numVertices):
position=Vec3(math.cos(currAngle)+offset.getX(), math.sin(currAngle)+offset.getY(),offset.getZ())
vertWriter.addData3f(position)
uvWriter.addData2f(position.getX()/2.0+0.5,position.getY()/2.0+0.5)
colorWriter.addData4f(1.0, 1.0, 1.0, 1.0)
position.setZ(position.getZ()*direction)
position.normalize()
normalWriter.addData3f(position)
#at default Opengl only draws "front faces" (all shapes whose vertices are arranged CCW). We
#need direction so we can specify which side we want to be the front face
currAngle+=angle*direction
circle=GeomTrifans(Geom.UHStatic)
circle.addConsecutiveVertices(startRow, numVertices)
circle.closePrimitive()
circleGeom.addPrimitive(circle)
return circleGeom
示例3: update_nodepath
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import setRow [as 别名]
def update_nodepath(pandaNode, refinements):
geom = pandaNode.modifyGeom(0)
vertdata = geom.modifyVertexData()
prim = geom.modifyPrimitive(0)
indexdata = prim.modifyVertices()
indexwriter = GeomVertexWriter(indexdata)
indexwriter.setColumn(0)
nextTriangleIndex = indexdata.getNumRows()
vertwriter = GeomVertexWriter(vertdata, 'vertex')
numverts = vertdata.getNumRows()
vertwriter.setRow(numverts)
normalwriter = GeomVertexWriter(vertdata, 'normal')
normalwriter.setRow(numverts)
uvwriter = GeomVertexWriter(vertdata, 'texcoord')
uvwriter.setRow(numverts)
for refinement in refinements:
for op_index in range(len(refinement)):
vals = refinement[op_index]
op = vals[0]
if op == PM_OP.TRIANGLE_ADDITION:
indexwriter.setRow(nextTriangleIndex)
nextTriangleIndex += 3
indexwriter.addData1i(vals[1])
indexwriter.addData1i(vals[2])
indexwriter.addData1i(vals[3])
elif op == PM_OP.INDEX_UPDATE:
indexwriter.setRow(vals[1])
indexwriter.setData1i(vals[2])
elif op == PM_OP.VERTEX_ADDITION:
numverts += 1
vertwriter.addData3f(vals[1], vals[2], vals[3])
normalwriter.addData3f(vals[4], vals[5], vals[6])
uvwriter.addData2f(vals[7], vals[8])
示例4: movePmTo
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import setRow [as 别名]
def movePmTo(self, dest_index):
geom = self.geomPath.node().modifyGeom(0)
vertdata = geom.modifyVertexData()
prim = geom.modifyPrimitive(0)
indexdata = prim.modifyVertices()
indexrewriter = GeomVertexRewriter(indexdata)
indexrewriter.setColumn(0)
nextTriangleIndex = indexdata.getNumRows()
vertwriter = GeomVertexWriter(vertdata, 'vertex')
numverts = vertdata.getNumRows()
vertwriter.setRow(numverts)
normalwriter = GeomVertexWriter(vertdata, 'normal')
normalwriter.setRow(numverts)
uvwriter = GeomVertexWriter(vertdata, 'texcoord')
uvwriter.setRow(numverts)
while self.pm_index < dest_index:
for op_index in range(len(self.pm_refinements[self.pm_index])):
vals = self.pm_refinements[self.pm_index][op_index]
op = vals[0]
if op == PM_OP.TRIANGLE_ADDITION:
indexrewriter.setRow(nextTriangleIndex)
nextTriangleIndex += 3
indexrewriter.addData1i(vals[1])
indexrewriter.addData1i(vals[2])
indexrewriter.addData1i(vals[3])
elif op == PM_OP.INDEX_UPDATE:
#TODO: ugly workaround for p3d 1.7 bug, change to below for 1.8
indexreader = GeomVertexReader(indexdata)
indexreader.setColumn(0)
indexreader.setRow(vals[1])
oldval = indexreader.getData1i()
del indexreader
#indexrewriter.setRow(vals[1])
#oldval = indexrewriter.getData1i()
indexrewriter.setRow(vals[1])
indexrewriter.setData1i(vals[2])
self.pm_refinements[self.pm_index][op_index] = (op, vals[1], oldval)
elif op == PM_OP.VERTEX_ADDITION:
numverts += 1
vertwriter.addData3f(vals[1], vals[2], vals[3])
normalwriter.addData3f(vals[4], vals[5], vals[6])
uvwriter.addData2f(vals[7], vals[8])
self.pm_index += 1
while self.pm_index > dest_index:
self.pm_index -= 1
for op_index in range(len(self.pm_refinements[self.pm_index])):
vals = self.pm_refinements[self.pm_index][op_index]
op = vals[0]
if op == PM_OP.TRIANGLE_ADDITION:
nextTriangleIndex -= 3
elif op == PM_OP.INDEX_UPDATE:
#TODO: ugly workaround for p3d 1.7 bug, change to below for 1.8
indexreader = GeomVertexReader(indexdata)
indexreader.setColumn(0)
indexreader.setRow(vals[1])
oldval = indexreader.getData1i()
del indexreader
#indexrewriter.setRow(vals[1])
#oldval = indexrewriter.getData1i()
indexrewriter.setRow(vals[1])
indexrewriter.setData1i(vals[2])
self.pm_refinements[self.pm_index][op_index] = (op, vals[1], oldval)
elif op == PM_OP.VERTEX_ADDITION:
numverts -= 1
if nextTriangleIndex < indexdata.getNumRows():
indexdata.setNumRows(nextTriangleIndex)
if numverts < vertdata.getNumRows():
vertdata.setNumRows(numverts)
示例5: drawBody
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import setRow [as 别名]
def drawBody(nodePath, vdata, pos, vecList, radius=1, keepDrawing=True, numVertices=8):
circleGeom = Geom(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)
sCoord = 0
if (startRow != 0):
texReWriter.setRow(startRow - numVertices)
sCoord = texReWriter.getData2f().getX() + 1
drawReWriter.setRow(startRow - numVertices)
if(drawReWriter.getData1f() == False):
sCoord -= 1
drawReWriter.setRow(startRow)
texReWriter.setRow(startRow)
angleSlice = 2 * math.pi / numVertices
currAngle = 0
#axisAdj=LMatrix4.rotateMat(45, axis)*LMatrix4.scaleMat(radius)*LMatrix4.translateMat(pos)
perp1 = vecList[1]
perp2 = vecList[2]
# vertex information is written here
for i in range(numVertices):
adjCircle = pos + \
(perp1 * math.cos(currAngle) + perp2 * math.sin(currAngle)) * \
radius
normal = perp1 * math.cos(currAngle) + perp2 * math.sin(currAngle)
normalWriter.addData3f(normal)
vertWriter.addData3f(adjCircle)
texReWriter.addData2f(sCoord, (i + 0.001) / (numVertices - 1))
colorWriter.addData4f(0.5, 0.5, 0.5, 1)
drawReWriter.addData1f(keepDrawing)
currAngle += angleSlice
drawReader = GeomVertexReader(vdata, "drawFlag")
drawReader.setRow(startRow - numVertices)
# we cant draw quads directly so we use Tristrips
if (startRow != 0) & (drawReader.getData1f() != False):
lines = GeomTristrips(Geom.UHStatic)
half = int(numVertices * 0.5)
for i in range(numVertices):
lines.addVertex(i + startRow)
if i < half:
lines.addVertex(i + startRow - half)
else:
lines.addVertex(i + startRow - half - numVertices)
lines.addVertex(startRow)
lines.addVertex(startRow - half)
lines.closePrimitive()
lines.decompose()
circleGeom.addPrimitive(lines)
circleGeomNode = GeomNode("Debug")
circleGeomNode.addGeom(circleGeom)
# I accidentally made the front-face face inwards. Make reverse makes the tree render properly and
# should cause any surprises to any poor programmer that tries to use
# this code
circleGeomNode.setAttrib(CullFaceAttrib.makeReverse(), 1)
global numPrimitives
numPrimitives += numVertices * 2
nodePath.attachNewNode(circleGeomNode)