本文整理汇总了Python中panda3d.core.GeomVertexFormat.addArray方法的典型用法代码示例。如果您正苦于以下问题:Python GeomVertexFormat.addArray方法的具体用法?Python GeomVertexFormat.addArray怎么用?Python GeomVertexFormat.addArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.GeomVertexFormat
的用法示例。
在下文中一共展示了GeomVertexFormat.addArray方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import addArray [as 别名]
def __init__(self, __occupying_unit = None, __occupiable = True,
x = 0, z = 0, r = 5, tag = 0):
self.__occupying_unit = __occupying_unit
self.__occupiable = __occupiable
self.__r = r
self.__x = x
self.__z = z
self.__tag = tag
#Procedurally creating a hex!
geometry_array = GeomVertexArrayFormat()
geometry_array.addColumn(InternalName.make('vertex'), 3, Geom.NTFloat32, Geom.CPoint)
geometry_array.addColumn(InternalName.make('normal'), 3, Geom.NTFloat32, Geom.CPoint)
format = GeomVertexFormat()
format.addArray(geometry_array)
format = GeomVertexFormat.registerFormat(format)
self.__vdata = GeomVertexData('Hex', format, Geom.UHStatic)
self.__vertex = GeomVertexWriter(self.__vdata, 'vertex')
self.__normal = GeomVertexWriter(self.__vdata, 'normal')
#Vertex 1
self.__vertex.addData3f(self.__x, self.__z+self.__r, 0)
self.__normal.addData3f(1, 0, 0)
#Vertex 2
self.__vertex.addData3f(self.__x+self.__r*sin(pi/3), self.__z+self.__r*cos(pi/3), 0)
self.__normal.addData3f(1, 0, 0)
#Vertex 3
self.__vertex.addData3f(self.__x+self.__r*sin(pi/3), self.__z-self.__r*cos(pi/3), 0)
self.__normal.addData3f(1, 0, 0)
#Vertex 4
self.__vertex.addData3f(self.__x, self.__z-self.__r, 0)
self.__normal.addData3f(1, 0, 0)
#Vertex 5
self.__vertex.addData3f(self.__x-self.__r*sin(pi/3), self.__z-self.__r*cos(pi/3), 0)
self.__normal.addData3f(1, 0, 0)
#Vertex 6
self.__vertex.addData3f(self.__x-self.__r*sin(pi/3), self.__z+self.__r*cos(pi/3), 0)
self.__normal.addData3f(1, 0, 0)
self.__hex_primitive = GeomTrifans(Geom.UHStatic)
self.__hex_primitive.addVertices(5, 4)
self.__hex_primitive.addVertices(3, 2)
self.__hex_primitive.addVertices(1, 0)
self.__hex_primitive.closePrimitive()
self.__hex_geometry = Geom(self.__vdata)
self.__hex_geometry.addPrimitive(self.__hex_primitive)
self.__hex_node = GeomNode('HexNode')
self.__hex_node.addGeom(self.__hex_geometry)
nodePath = render.attachNewNode(self.__hex_node)
nodePath.setTag( "hex", str(tag) )
nodePath.node().setIntoCollideMask(BitMask32.bit(1))
nodePath.hide()
示例2: create_model
# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import addArray [as 别名]
def create_model(self):
# Set up the vertex arrays
vformatArray = GeomVertexArrayFormat()
# Panda3D implicitly generates a bounding volume from a
# column named "vertex", so you either
# * have a column of that name, or
# * add a bounding volume yourself.
vformatArray.addColumn(InternalName.make("vertex"), 3, Geom.NTFloat32, Geom.CPoint)
vformatArray.addColumn(InternalName.make("color"), 4, Geom.NTFloat32, Geom.CColor)
vformat = GeomVertexFormat()
vformat.addArray(vformatArray)
vformat = GeomVertexFormat.registerFormat(vformat)
vdata = GeomVertexData("Data", vformat, Geom.UHStatic)
vertex = GeomVertexWriter(vdata, 'vertex')
color = GeomVertexWriter(vdata, 'color')
geom = Geom(vdata)
# Vertex data
vertex.addData3f(1.5, 0, -1)
color.addData4f(1, 0, 0, 1)
vertex.addData3f(-1.5, 0, -1)
color.addData4f(0, 1, 0, 1)
vertex.addData3f(0, 0, 1)
color.addData4f(0, 0, 1, 1)
# Primitive
tri = GeomPatches(3, Geom.UHStatic)
tri.add_vertex(2)
tri.add_vertex(1)
tri.add_vertex(0)
tri.close_primitive()
geom.addPrimitive(tri)
# Create the actual node
node = GeomNode('geom_node')
node.addGeom(geom)
np = NodePath(node)
# Shader, initial shader vars, number of instances
np.set_shader(Shader.load(Shader.SL_GLSL,
vertex = "shader.vert",
tess_control = "shader.tesc",
tess_evaluation = "shader.tese",
geometry = "shader.geom",
fragment = "shader.frag"))
np.set_shader_input("time", 0.0)
np.set_shader_input("tess_level", 32.0)
np.set_instance_count(num_instances)
np.set_shader_input("numInstances", num_instances)
return np
示例3: __generate_Vformats
# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import addArray [as 别名]
def __generate_Vformats(self):
vformat_dict = {}
# Simple.
array = GeomVertexArrayFormat()
array.addColumn(InternalName.make("vertex"), 3, Geom.NTFloat32, Geom.CPoint)
vformat = GeomVertexFormat()
vformat.addArray(array)
vformat_dict['simp'] = GeomVertexFormat.registerFormat(vformat)
# Low.
array = GeomVertexArrayFormat()
array.addColumn(InternalName.make("vertex"), 3, Geom.NTFloat32, Geom.CPoint)
array.addColumn(InternalName.make("color"), 4, Geom.NTFloat32, Geom.CColor)
vformat = GeomVertexFormat()
vformat.addArray(array)
vformat_dict['low'] = GeomVertexFormat.registerFormat(vformat)
# Mid.
array = GeomVertexArrayFormat()
array.addColumn(InternalName.make("vertex"), 3, Geom.NTFloat32, Geom.CPoint)
array.addColumn(InternalName.make("mapcoord"), 2, Geom.NTFloat32, Geom.CTexcoord)
vformat = GeomVertexFormat()
vformat.addArray(array)
vformat_dict['mid'] = GeomVertexFormat.registerFormat(vformat)
# High (patches).
array = GeomVertexArrayFormat()
array.addColumn(InternalName.make("vertex"), 3, Geom.NTFloat32, Geom.CPoint)
array.addColumn(InternalName.make("mapcoord"), 2, Geom.NTFloat32, Geom.CTexcoord)
array.addColumn(InternalName.make("texcoord"), 2, Geom.NTFloat32, Geom.CTexcoord)
vformat = GeomVertexFormat()
vformat.addArray(array)
vformat_dict['high'] = GeomVertexFormat.registerFormat(vformat)
return vformat_dict
示例4: __build_Writers
# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import addArray [as 别名]
def __build_Writers(self):
# Build Vdata.
array = GeomVertexArrayFormat()
for field_name, field_spec_name in list(self.field_types.items()):
field_specs = self._data_types[field_spec_name][:-1]
array.addColumn(InternalName.make(field_name), *field_specs)
vformat = GeomVertexFormat()
vformat.addArray(array)
vformat = GeomVertexFormat.registerFormat(vformat)
vdata = GeomVertexData("data", vformat, Geom.UHStatic)
# Build GeomVertexWriters.
writers = {}
for field_name in list(self.field_types.keys()):
writers[field_name] = GeomVertexWriter(vdata, field_name)
return vdata, writers
示例5: makeVertexFormat
# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import addArray [as 别名]
def makeVertexFormat(color = True, normal = False, texcoord = False, tan_binorm = False):
myArray = GeomVertexArrayFormat()
myArray.addColumn(InternalName.make('vertex'), 3, Geom.NTFloat32, Geom.CPoint)
if color:
myArray.addColumn(InternalName.make('color'), 4, Geom.NTFloat32, Geom.CColor)
if normal:
myArray.addColumn(InternalName.make('normal'), 3, Geom.NTFloat32, Geom.CVector)
if texcoord:
myArray.addColumn(InternalName.make('texcoord'), 2, Geom.NTFloat32, Geom.CTexcoord)
if tan_binorm:
myArray.addColumn(InternalName.make('tangent'), 3, Geom.NTFloat32, Geom.CVector)
myArray.addColumn(InternalName.make('binormal'), 3, Geom.NTFloat32, Geom.CVector)
myFormat = GeomVertexFormat()
myFormat.addArray(myArray)
myFormat = GeomVertexFormat.registerFormat(myFormat)
return myFormat
示例6: registerObject
# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import addArray [as 别名]
def registerObject(self, obj):
""" Registers a new dynamic object, this will store an index for every
vertex, which can be used to read and store last position data in order
to compute the velocity. This method also assigns the standard animated
shader to the node """
self.debug("Registering dynamic object")
# Find all GeomNodes
for node in obj.findAllMatches("**/+GeomNode"):
geomNode = node.node()
geomCount = geomNode.getNumGeoms()
# Find all Geoms
for i in xrange(geomCount):
# Modify vertex data
geom = geomNode.modifyGeom(i)
geomVertexData = geom.modifyVertexData()
# Add a new column named "dovindex" to the vertex data
formatArray = GeomVertexArrayFormat()
formatArray.addColumn(InternalName.make("dovindex"), 1, GeomEnums.NTUint32, GeomEnums.CIndex)
newArrayFormat = GeomVertexFormat(geomVertexData.getFormat())
newArrayFormat.addArray(formatArray)
newArrayFormat = GeomVertexFormat.registerFormat(newArrayFormat)
# Convert the old vertex data and assign the new vertex data
convertedVertexData = geomVertexData.convertTo(newArrayFormat)
geom.setVertexData(convertedVertexData)
# Write the per-vertex indices the dovindex column
newVertexData = geom.modifyVertexData()
vtxReader = GeomVertexReader(newVertexData, "vertex")
indexWriter = GeomVertexWriter(newVertexData, "dovindex")
while not vtxReader.isAtEnd():
data = vtxReader.getData3f()
indexWriter.setData1i(self.currentIndex)
self.currentIndex += 1
if self.currentIndex > self.maxVertexCount:
self.error("Max dynamic vertex count of", self.maxVertexCount, "reached!")
示例7: __init__
# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import addArray [as 别名]
def __init__(self):
formatArray = GeomVertexArrayFormat()
formatArray.addColumn(
InternalName.make("drawFlag"), 1, Geom.NTUint8, Geom.COther)
format = GeomVertexFormat(GeomVertexFormat.getV3n3cpt2())
format.addArray(formatArray)
self.format = GeomVertexFormat.registerFormat(format)
bodydata = GeomVertexData("body vertices", format, Geom.UHStatic)
self.barkTexture = loader.loadTexture("barkTexture.jpg")
treeNodePath = NodePath("Tree Holder")
makeFractalTree(bodydata, treeNodePath, LVector3(4, 4, 7))
treeNodePath.setTexture(self.barkTexture, 1)
treeNodePath.reparentTo(render)
self.accept("q", self.regenTree)
self.accept("w", self.addTree)
self.accept("arrow_up", self.upIterations)
self.accept("arrow_down", self.downIterations)
self.accept("arrow_right", self.upCopies)
self.accept("arrow_left", self.downCopies)
self.numIterations = 11
self.numCopies = 4
self.upDownEvent = OnscreenText(
text="Up/Down: Increase/Decrease the number of iterations (" + str(
self.numIterations) + ")",
parent=base.a2dTopLeft, align=TextNode.ALeft,
style=1, fg=(1, 1, 1, 1), pos=(0.06, -0.22),
scale=.05, mayChange=True)
self.leftRightEvent = OnscreenText(
text="Left/Right: Increase/Decrease branching (" + str(
self.numCopies) + ")",
parent=base.a2dTopLeft, align=TextNode.ALeft,
style=1, fg=(1, 1, 1, 1), pos=(0.06, -0.28),
scale=.05, mayChange=True)
示例8: getNodeFromController
# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import addArray [as 别名]
def getNodeFromController(controller, controlled_prim):
if type(controlled_prim) is collada.controller.BoundSkinPrimitive:
ch = Character('simplechar')
bundle = ch.getBundle(0)
skeleton = PartGroup(bundle, '<skeleton>')
character_joints = {}
for (name, joint_matrix) in controller.joint_matrices.iteritems():
joint_matrix.shape = (-1)
character_joints[name] = CharacterJoint(ch, bundle, skeleton, name, Mat4(*joint_matrix))
tbtable = TransformBlendTable()
for influence in controller.index:
blend = TransformBlend()
for (joint_index, weight_index) in influence:
char_joint = character_joints[controller.getJoint(joint_index)]
weight = controller.getWeight(weight_index)[0]
blend.addTransform(JointVertexTransform(char_joint), weight)
tbtable.addBlend(blend)
array = GeomVertexArrayFormat()
array.addColumn(InternalName.make('vertex'), 3, Geom.NTFloat32, Geom.CPoint)
array.addColumn(InternalName.make('normal'), 3, Geom.NTFloat32, Geom.CPoint)
array.addColumn(InternalName.make('texcoord'), 2, Geom.NTFloat32, Geom.CTexcoord)
blendarr = GeomVertexArrayFormat()
blendarr.addColumn(InternalName.make('transform_blend'), 1, Geom.NTUint16, Geom.CIndex)
format = GeomVertexFormat()
format.addArray(array)
format.addArray(blendarr)
aspec = GeomVertexAnimationSpec()
aspec.setPanda()
format.setAnimation(aspec)
format = GeomVertexFormat.registerFormat(format)
dataname = controller.id + '-' + controlled_prim.primitive.material.id
vdata = GeomVertexData(dataname, format, Geom.UHStatic)
vertex = GeomVertexWriter(vdata, 'vertex')
normal = GeomVertexWriter(vdata, 'normal')
texcoord = GeomVertexWriter(vdata, 'texcoord')
transform = GeomVertexWriter(vdata, 'transform_blend')
numtris = 0
if type(controlled_prim.primitive) is collada.polylist.BoundPolylist:
for poly in controlled_prim.primitive.polygons():
for tri in poly.triangles():
for tri_pt in range(3):
vertex.addData3f(tri.vertices[tri_pt][0], tri.vertices[tri_pt][1], tri.vertices[tri_pt][2])
normal.addData3f(tri.normals[tri_pt][0], tri.normals[tri_pt][1], tri.normals[tri_pt][2])
if len(controlled_prim.primitive._texcoordset) > 0:
texcoord.addData2f(tri.texcoords[0][tri_pt][0], tri.texcoords[0][tri_pt][1])
transform.addData1i(tri.indices[tri_pt])
numtris+=1
elif type(controlled_prim.primitive) is collada.triangleset.BoundTriangleSet:
for tri in controlled_prim.primitive.triangles():
for tri_pt in range(3):
vertex.addData3f(tri.vertices[tri_pt][0], tri.vertices[tri_pt][1], tri.vertices[tri_pt][2])
normal.addData3f(tri.normals[tri_pt][0], tri.normals[tri_pt][1], tri.normals[tri_pt][2])
if len(controlled_prim.primitive._texcoordset) > 0:
texcoord.addData2f(tri.texcoords[0][tri_pt][0], tri.texcoords[0][tri_pt][1])
transform.addData1i(tri.indices[tri_pt])
numtris+=1
tbtable.setRows(SparseArray.lowerOn(vdata.getNumRows()))
gprim = GeomTriangles(Geom.UHStatic)
for i in range(numtris):
gprim.addVertices(i*3, i*3+1, i*3+2)
gprim.closePrimitive()
pgeom = Geom(vdata)
pgeom.addPrimitive(gprim)
render_state = getStateFromMaterial(controlled_prim.primitive.material)
control_node = GeomNode("ctrlnode")
control_node.addGeom(pgeom, render_state)
ch.addChild(control_node)
bundle = AnimBundle('simplechar', 5.0, 2)
skeleton = AnimGroup(bundle, '<skeleton>')
root = AnimChannelMatrixXfmTable(skeleton, 'root')
#hjoint = AnimChannelMatrixXfmTable(root, 'joint1')
#table = [10, 11, 12, 13, 14, 15, 14, 13, 12, 11]
#data = PTAFloat.emptyArray(len(table))
#for i in range(len(table)):
# data.setElement(i, table[i])
#hjoint.setTable(ord('i'), CPTAFloat(data))
#vjoint = AnimChannelMatrixXfmTable(hjoint, 'joint2')
#table = [10, 9, 8, 7, 6, 5, 6, 7, 8, 9]
#data = PTAFloat.emptyArray(len(table))
#for i in range(len(table)):
# data.setElement(i, table[i])
#vjoint.setTable(ord('j'), CPTAFloat(data))
wiggle = AnimBundleNode('wiggle', bundle)
np = NodePath(ch)
#.........这里部分代码省略.........
示例9: getVertexData
# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import addArray [as 别名]
def getVertexData(vertex, vertex_index, normal=None, normal_index=None,
texcoordset=(), texcoord_indexset=(),
textangentset=(), textangent_indexset=(),
texbinormalset=(), texbinormal_indexset=()):
format = GeomVertexFormat()
formatArray = GeomVertexArrayFormat()
indices2stack = [vertex_index.reshape(-1, 1)]
alldata = [vertex]
formatArray.addColumn(InternalName.make("vertex"), 3, Geom.NTFloat32, Geom.CPoint)
if normal is not None:
indices2stack.append(normal_index.reshape(-1, 1))
alldata.append(collada.util.normalize_v3(numpy.copy(normal)))
formatArray.addColumn(InternalName.make("normal"), 3, Geom.NTFloat32, Geom.CVector)
if len(texcoordset) > 0:
indices2stack.append(texcoord_indexset[0].reshape(-1, 1))
alldata.append(texcoordset[0])
formatArray.addColumn(InternalName.make("texcoord"), 2, Geom.NTFloat32, Geom.CTexcoord)
if len(textangentset) > 0:
indices2stack.append(textangent_indexset[0].reshape(-1, 1))
alldata.append(textangentset[0])
formatArray.addColumn(InternalName.make("tangent"), 3, Geom.NTFloat32, Geom.CVector)
if len(texbinormalset) > 0:
indices2stack.append(texbinormal_indexset[0].reshape(-1, 1))
alldata.append(texbinormalset[0])
formatArray.addColumn(InternalName.make("binormal"), 3, Geom.NTFloat32, Geom.CVector)
#have to flatten and reshape like this so that it's contiguous
stacked_indices = numpy.hstack(indices2stack).flatten().reshape((-1, len(indices2stack)))
#index_map - maps each unique value back to a location in the original array it came from
# eg. stacked_indices[index_map] == unique_stacked_indices
#inverse_map - maps original array locations to their location in the unique array
# e.g. unique_stacked_indices[inverse_map] == stacked_indices
unique_stacked_indices, index_map, inverse_map = numpy.unique(stacked_indices.view([('',stacked_indices.dtype)]*stacked_indices.shape[1]), return_index=True, return_inverse=True)
unique_stacked_indices = unique_stacked_indices.view(stacked_indices.dtype).reshape(-1,stacked_indices.shape[1])
#unique returns as int64, so cast back
index_map = numpy.cast['uint32'](index_map)
inverse_map = numpy.cast['uint32'](inverse_map)
#sort the index map to get a list of the index of the first time each value was encountered
sorted_map = numpy.cast['uint32'](numpy.argsort(index_map))
#since we're sorting the unique values, we have to map the inverse_map to the new index locations
backwards_map = numpy.zeros_like(sorted_map)
backwards_map[sorted_map] = numpy.arange(len(sorted_map), dtype=numpy.uint32)
#now this is the new unique values and their indices
unique_stacked_indices = unique_stacked_indices[sorted_map]
inverse_map = backwards_map[inverse_map]
#combine the unique stacked indices into unique stacked data
data2stack = []
for idx, data in enumerate(alldata):
data2stack.append(data[unique_stacked_indices[:,idx]])
unique_stacked_data = numpy.hstack(data2stack).flatten()
unique_stacked_data.shape = (-1)
all_data = unique_stacked_data.tostring()
format.addArray(formatArray)
format = GeomVertexFormat.registerFormat(format)
vdata = GeomVertexData("dataname", format, Geom.UHStatic)
arr = GeomVertexArrayData(format.getArray(0), GeomEnums.UHStream)
datahandle = arr.modifyHandle()
datahandle.setData(all_data)
all_data = None
vdata.setArray(0, arr)
datahandle = None
arr = None
indexFormat = GeomVertexArrayFormat()
indexFormat.addColumn(InternalName.make("index"), 1, Geom.NTUint32, Geom.CIndex)
indexFormat = GeomVertexArrayFormat.registerFormat(indexFormat)
indexArray = GeomVertexArrayData(indexFormat, GeomEnums.UHStream)
indexHandle = indexArray.modifyHandle()
indexData = inverse_map.tostring()
indexHandle.setData(indexData)
return vdata, indexArray
示例10: GeomVertexArrayFormat
# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import addArray [as 别名]
y = random.randint(sy, ey)
z = self.world.map3d[x, y]
if 0 < z < self.config.low_mount_level[1]:
res[tree].append((x, y, z))
self[item] = res
return res
# Shit for fucking trees
formatArray = GeomVertexArrayFormat()
formatArray.addColumn(InternalName.make("drawFlag"), 1, Geom.NTUint8, Geom.COther)
treeform = GeomVertexFormat(GeomVertexFormat.getV3n3cpt2())
treeform.addArray(formatArray)
treeform = GeomVertexFormat.registerFormat(treeform)
# this draws the body of the tree. This draws a ring of vertices and connects the rings with
# triangles to form the body.
# this keepDrawing paramter tells the function wheter or not we're at an end
# if the vertices before you were an end, dont draw branches to it
def draw_body(nodePath, vdata, pos, vecList, radius=1, keepDrawing=True, numVertices=3):
circleGeom = Geom(vdata)
vertWriter = GeomVertexWriter(vdata, "vertex")
colorWriter = GeomVertexWriter(vdata, "color")
normalWriter = GeomVertexWriter(vdata, "normal")
drawReWriter = GeomVertexRewriter(vdata, "drawFlag")
示例11: build
# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import addArray [as 别名]
def build(self):
# http://www.panda3d.org/forums/viewtopic.php?t=11528
"""Create the geometry from the submitted arrays"""
verts = self.verts
polys = self.polys
self.geomnode = GeomNode('geometry')
self.color_lookup = []
if not self.vnorms:
self.getNormals()
if not self.uvs:
self.getUVMapping()
if self.use_tangents:
self.getTangents()
# Build array for new format.
array = GeomVertexArrayFormat()
array.addColumn(InternalName.make(b'vertex'), 3, Geom.NTFloat32, Geom.CPoint)
array.addColumn(InternalName.make(b'texcoord'), 2, Geom.NTFloat32, Geom.CTexcoord)
array.addColumn(InternalName.make(b'normal'), 3, Geom.NTFloat32, Geom.CVector)
if self.use_tangents:
array.addColumn(InternalName.make(b'binormal'), 3, Geom.NTFloat32, Geom.CVector)
array.addColumn(InternalName.make(b'tangent'), 3, Geom.NTFloat32, Geom.CVector)
# Create and register format.
format = GeomVertexFormat()
format.addArray(array)
format = GeomVertexFormat.registerFormat(format)
geoms = []
for i in range(len(self.colors)):
vdata = GeomVertexData('ngon', format, Geom.UHStatic)
geom = Geom(vdata)
tri = GeomTriangles(Geom.UHStatic)
vertex = GeomVertexWriter(vdata, b'vertex')
normal = GeomVertexWriter(vdata, b'normal')
texcoord = GeomVertexWriter(vdata, b'texcoord')
geoms.append({'geom':geom,
'tri':tri,
'vertex':vertex,
'texcoord':texcoord,
'normal':normal,
'index':0,
'vdata':vdata,
'color':i})
if self.use_tangents:
tangent = GeomVertexWriter(vdata, b'tangent')
binormal = GeomVertexWriter(vdata, b'binormal')
geoms[i]['tangent'] = tangent
geoms[i]['binormal'] = binormal
for poly_index in range(len(polys)):
color_index = self.colors.index(self.mats[poly_index])
vertcount = geoms[color_index]['index']
p = polys[poly_index]
poly = [verts[i] for i in p]
uvs = self.uvs[poly_index]
norm = [self.vnorms[i] for i in p]
if self.use_tangents:
binorm = [self.binorms[i] for i in p]
tan = [self.tans[i] for i in p]
reindexed = [] # New vertex indices per-poly
for v in poly:
geoms[color_index]['vertex'].addData3f(v[0], v[1], v[2])
reindexed.append(vertcount)
vertcount += 1
geoms[color_index]['index'] = vertcount
for i in range(len(poly)):
geoms[color_index]['normal'].addData3f(Vec3(norm[i][0], norm[i][1], norm[i][2]))
if self.use_tangents:
geoms[color_index]['binormal'].addData3f(Vec3(binorm[i][0], binorm[i][1], binorm[i][2]))
geoms[color_index]['tangent'].addData3f(Vec3(tan[i][0], tan[i][1], tan[i][2]))
for tvert in uvs:
geoms[color_index]['texcoord'].addData2f(tvert[0], tvert[1])
triangulated = self.getFanning(reindexed) # Use new vertex indices
for tri_index in range(len(triangulated)):
t = triangulated[tri_index]
tri = geoms[color_index]['tri']
tri.addVertices(t[0], t[1], t[2])
for color_index in range(len(self.colors)):
geom = geoms[color_index]['geom']
tri = geoms[color_index]['tri']
tri.closePrimitive()
geom.addPrimitive(tri)
self.geomnode.addGeom(geom)
self.color_lookup.append(color_index)
示例12: normalize
# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import addArray [as 别名]
def normalize(vec):
vec.normalize()
return vec
# Build array for new format.
array = GeomVertexArrayFormat()
array.addColumn(InternalName.make(b'vertex'), 3, Geom.NTFloat32, Geom.CPoint)
array.addColumn(InternalName.make(b'texcoord'), 2, Geom.NTFloat32, Geom.CTexcoord)
array.addColumn(InternalName.make(b'normal'), 3, Geom.NTFloat32, Geom.CVector)
array.addColumn(InternalName.make(b'binormal'), 3, Geom.NTFloat32, Geom.CVector)
array.addColumn(InternalName.make(b'tangent'), 3, Geom.NTFloat32, Geom.CVector)
# Create and register format.
format = GeomVertexFormat()
format.addArray(array)
format = GeomVertexFormat.registerFormat(format)
def frange(start, stop, step):
r = start
while r < stop:
yield r
r += step
def vector_copy(v):
"""Utility function to coerce a list or tuple into Vec3 format"""
return Vec3(v[0], v[1], v[2])
示例13: add_button
# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import addArray [as 别名]
def add_button(self, text, label_id, pos_x, pos_y, width=0.0, hight=0.1):
if width == 0.0:
for c in range(len(text)/2):
width += 0.08
ls = LineSegs("lines")
ls.setColor(0,1,0,1)
ls.drawTo(-width/2, 0, hight/2)
ls.drawTo(width/2, 0, hight/2)
ls.drawTo(width/2, 0,-hight/2)
ls.drawTo(-width/2, 0,-hight/2)
ls.drawTo(-width/2, 0, hight/2)
border = ls.create(False)
border.setTag('back_ground', '1')
array = GeomVertexArrayFormat()
array.addColumn("vertex", 4, Geom.NTFloat32, Geom.CPoint)
arr_format = GeomVertexFormat()
arr_format.addArray(array)
arr_format = GeomVertexFormat.registerFormat(arr_format)
vdata = GeomVertexData('fill', arr_format, Geom.UHStatic)
vdata.setNumRows(4)
vertex = GeomVertexWriter(vdata, 'vertex')
vertex.addData3f(-width/2, 0, hight/2)
vertex.addData3f(width/2, 0, hight/2)
vertex.addData3f(-width/2, 0,-hight/2)
vertex.addData3f(width/2, 0,-hight/2)
prim = GeomTristrips(Geom.UHStatic)
prim.addVertex(0)
prim.addVertex(1)
prim.addVertex(2)
prim.addVertex(3)
geom = Geom(vdata)
geom.addPrimitive(prim)
node = GeomNode('gnode')
node.addGeom(geom)
nodePath = NodePath("button")
nodePath.attachNewNode(node)
nodePath.setPos(0,0,0)
nodePath.setTag('button', '1')
nodePath.setBin("unsorted", 0)
nodePath.setDepthTest(False)
nodePath.setColor(0,0,0,1)
nodePath.attachNewNode(border)
nodePath1 = NodePath("button")
nodePath1.attachNewNode(node)
nodePath1.setPos(0,0,0)
nodePath1.setTag('button1', '1')
nodePath1.setBin("unsorted", 0)
nodePath1.setDepthTest(False)
nodePath1.setColor(0,1,0,1)
nodePath1.attachNewNode(border)
button=DirectFrame(
enableEdit=1,
text=text,
geom=nodePath,
text_scale=0.05,
text_fg=(0,1,0,1),
borderWidth=(1,1),
relief = None,
text_pos=(0,-0.01,0),
textMayChange=1,
state=DGG.NORMAL,
parent=aspect2d
)
button.setPos(pos_x,0,pos_y)
button.bind(DGG.B1PRESS, button_click, [button])
button.bind(DGG.WITHIN, button_hover, [button])
button.bind(DGG.WITHOUT, button_no_hover, [button])
# button.resetFrameSize()
# self.button.bind(DGG.WITHIN, self.onMouseHoverInFunction, [button, some_value1])
defines.ENTITIES[defines.ENTITY_ID] = {'CATEGORY':'button', 'BUTTON':button, 'NODE':nodePath, 'LABEL':label_id,'STATUS': 0}
defines.ENTITY_ID += 1