本文整理汇总了Python中panda3d.core.GeomNode.setGeomState方法的典型用法代码示例。如果您正苦于以下问题:Python GeomNode.setGeomState方法的具体用法?Python GeomNode.setGeomState怎么用?Python GeomNode.setGeomState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.GeomNode
的用法示例。
在下文中一共展示了GeomNode.setGeomState方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import setGeomState [as 别名]
def __init__(self, mesh, pm_filebuf):
scene_members = getSceneMembers(mesh)
base = ShowBase()
if len(scene_members) > 1:
print('There is more than one geometry in the scene, so I think this is not a progressive base mesh.')
sys.exit(1)
rotateNode = GeomNode("rotater")
rotatePath = render.attachNewNode(rotateNode)
matrix = numpy.identity(4)
if mesh.assetInfo.upaxis == collada.asset.UP_AXIS.X_UP:
r = collada.scene.RotateTransform(0,1,0,90)
matrix = r.matrix
elif mesh.assetInfo.upaxis == collada.asset.UP_AXIS.Y_UP:
r = collada.scene.RotateTransform(1,0,0,90)
matrix = r.matrix
rotatePath.setMat(Mat4(*matrix.T.flatten().tolist()))
geom, renderstate, mat4 = scene_members[0]
node = GeomNode("primitive")
node.addGeom(geom)
if renderstate is not None:
node.setGeomState(0, renderstate)
self.geomPath = rotatePath.attachNewNode(node)
self.geomPath.setMat(mat4)
wrappedNode = ensureCameraAt(self.geomPath, base.camera)
base.disableMouse()
attachLights(render)
render.setShaderAuto()
render.setTransparency(TransparencyAttrib.MDual, 1)
base.render.analyze()
KeyboardMovement()
MouseDrag(wrappedNode)
MouseScaleZoom(wrappedNode)
ButtonUtils(wrappedNode)
MouseCamera()
print('Loading pm into memory... ', end=' ')
sys.stdout.flush()
self.pm_refinements = readPDAE(pm_filebuf)
self.pm_index = 0
print('Done')
self.slider = DirectSlider(range=(0,len(self.pm_refinements)),
value=0, pageSize=len(self.pm_refinements)/20,
command=self.sliderMoved, pos=(0, 0, -.9), scale=1)
for key, val in uiArgs.items():
self.slider.thumb[key] = val
self.triText = OnscreenText(text="", pos=(-1,0.85), scale = 0.15,
fg=(1, 0.5, 0.5, 1), align=TextNode.ALeft, mayChange=1)
base.run()
示例2: getBam
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import setGeomState [as 别名]
def getBam(mesh, filename):
scene_members = pandacore.getSceneMembers(mesh)
rotateNode = GeomNode("rotater")
rotatePath = NodePath(rotateNode)
matrix = numpy.identity(4)
if mesh.assetInfo.upaxis == collada.asset.UP_AXIS.X_UP:
r = collada.scene.RotateTransform(0,1,0,90)
matrix = r.matrix
elif mesh.assetInfo.upaxis == collada.asset.UP_AXIS.Y_UP:
r = collada.scene.RotateTransform(1,0,0,90)
matrix = r.matrix
rotatePath.setMat(Mat4(*matrix.T.flatten().tolist()))
for geom, renderstate, mat4 in scene_members:
node = GeomNode("primitive")
node.addGeom(geom)
if renderstate is not None:
node.setGeomState(0, renderstate)
geomPath = rotatePath.attachNewNode(node)
geomPath.setMat(mat4)
rotatePath.flattenStrong()
wrappedNode = pandacore.centerAndScale(rotatePath)
model_name = filename.replace('/', '_')
wrappedNode.setName(model_name)
bam_temp = tempfile.mktemp(suffix = model_name + '.bam')
wrappedNode.writeBamFile(bam_temp)
bam_f = open(bam_temp, 'rb')
bam_data = bam_f.read()
bam_f.close()
os.remove(bam_temp)
return bam_data
示例3: setupPandaApp
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import setGeomState [as 别名]
def setupPandaApp(mesh):
scene_members = getSceneMembers(mesh)
p3dApp = ShowBase()
nodePath = getBaseNodePath(render)
rotateNode = GeomNode("rotater")
rotatePath = nodePath.attachNewNode(rotateNode)
matrix = numpy.identity(4)
if mesh.assetInfo.upaxis == collada.asset.UP_AXIS.X_UP:
r = collada.scene.RotateTransform(0,1,0,90)
matrix = r.matrix
elif mesh.assetInfo.upaxis == collada.asset.UP_AXIS.Y_UP:
r = collada.scene.RotateTransform(1,0,0,90)
matrix = r.matrix
rotatePath.setMat(Mat4(*matrix.T.flatten().tolist()))
rbc = RigidBodyCombiner('combiner')
rbcPath = rotatePath.attachNewNode(rbc)
for geom, renderstate, mat4 in scene_members:
node = GeomNode("primitive")
node.addGeom(geom)
if renderstate is not None:
node.setGeomState(0, renderstate)
geomPath = rbcPath.attachNewNode(node)
geomPath.setMat(mat4)
rbc.collect()
ensureCameraAt(nodePath, base.camera)
base.disableMouse()
attachLights(render)
render.setShaderAuto()
render.setTransparency(TransparencyAttrib.MDual, 1)
return p3dApp
示例4: runViewer
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import setGeomState [as 别名]
def runViewer(mesh):
scene_members = getSceneMembers(mesh)
loadPrcFileData('', 'win-size 300 300')
base = ShowBase()
globNode = GeomNode("collada")
nodePath = base.render.attachNewNode(globNode)
rotateNode = GeomNode("rotater")
rotatePath = nodePath.attachNewNode(rotateNode)
matrix = numpy.identity(4)
if mesh.assetInfo.upaxis == collada.asset.UP_AXIS.X_UP:
r = collada.scene.RotateTransform(0,1,0,90)
matrix = r.matrix
elif mesh.assetInfo.upaxis == collada.asset.UP_AXIS.Y_UP:
r = collada.scene.RotateTransform(1,0,0,90)
matrix = r.matrix
rotatePath.setMat(Mat4(*matrix.T.flatten().tolist()))
basecollada = GeomNode("basecollada")
basecolladaNP = rotatePath.attachNewNode(basecollada)
for geom, renderstate, mat4 in scene_members:
node = GeomNode("primitive")
node.addGeom(geom)
if renderstate is not None:
node.setGeomState(0, renderstate)
geomPath = basecolladaNP.attachNewNode(node)
geomPath.setMat(mat4)
for boundlight in mesh.scene.objects('light'):
if len(boundlight.color) == 3:
color = (boundlight.color[0], boundlight.color[1], boundlight.color[2], 1)
else:
color = boundlight.color
if isinstance(boundlight, collada.light.BoundDirectionalLight):
dl = DirectionalLight('dirLight')
dl.setColor(Vec4(color[0], color[1], color[2], color[3]))
lightNP = rotatePath.attachNewNode(dl)
lightNP.lookAt(Point3(boundlight.direction[0],boundlight.direction[1],boundlight.direction[2]))
elif isinstance(boundlight, collada.light.BoundAmbientLight):
ambientLight = AmbientLight('ambientLight')
ambientLight.setColor(Vec4(color[0], color[1], color[2], color[3]))
lightNP = rotatePath.attachNewNode(ambientLight)
elif isinstance(boundlight, collada.light.BoundPointLight):
pointLight = PointLight('pointLight')
pointLight.setColor(Vec4(color[0], color[1], color[2], color[3]))
pointLight.setAttenuation(Vec3(boundlight.constant_att, boundlight.linear_att, boundlight.quad_att))
lightNP = rotatePath.attachNewNode(pointLight)
lightNP.setPos(Vec3(boundlight.position[0], boundlight.position[1], boundlight.position[2]))
elif isinstance(boundlight, collada.light.BoundSpotLight):
spotLight = Spotlight('spotLight')
spotLight.setColor(Vec4(color[0], color[1], color[2], color[3]))
spotLight.setAttenuation(Vec3(boundlight.constant_att, boundlight.linear_att, boundlight.quad_att))
spotLight.setExponent(boundlight.falloff_exp)
lightNP = rotatePath.attachNewNode(spotLight)
lightNP.setPos(Vec3(boundlight.position[0], boundlight.position[1], boundlight.position[2]))
lightNP.lookAt(Point3(boundlight.direction[0], boundlight.direction[1], boundlight.direction[2]),
Vec3(boundlight.up[0], boundlight.up[1], boundlight.up[2]))
else:
print('Unknown light type', boundlight)
continue
base.render.setLight(lightNP)
for boundcam in mesh.scene.objects('camera'):
if isinstance(boundcam, collada.camera.BoundPerspectiveCamera):
base.camera.reparentTo(rotatePath)
base.camLens.setNear(boundcam.znear)
base.camLens.setFar(boundcam.zfar)
if boundcam.xfov is not None and boundcam.yfov is not None:
#xfov + yfov
base.camLens.setFov(boundcam.xfov, boundcam.yfov)
elif boundcam.xfov is not None and boundcam.aspect_ratio is not None:
#xfov + aspect_ratio
base.camLens.setFov(boundcam.xfov)
base.camLens.setAspectRatio(boundcam.aspect_ratio)
elif boundcam.yfov is not None and boundcam.aspect_ratio is not None:
#yfov + aspect_ratio
#aspect_ratio = tan(0.5*xfov) / tan(0.5*yfov)
xfov = math.degrees(2.0 * math.atan(boundcam.aspect_ratio * math.tan(math.radians(0.5 * boundcam.yfov))))
base.camLens.setFov(xfov, boundcam.yfov)
elif boundcam.yfov is not None:
#yfov only
#aspect_ratio = tan(0.5*xfov) / tan(0.5*yfov)
xfov = math.degrees(2.0 * math.atan(base.camLens.getAspectRatio() * math.tan(math.radians(0.5 * boundcam.yfov))))
base.camLens.setFov(xfov, boundcam.yfov)
elif boundcam.xfov is not None:
base.camLens.setFov(boundcam.xfov)
base.camera.setPos(Vec3(boundcam.position[0], boundcam.position[1], boundcam.position[2]))
base.camera.lookAt(Point3(boundcam.direction[0], boundcam.direction[1], boundcam.direction[2]),
Vec3(boundcam.up[0], boundcam.up[1], boundcam.up[2]))
elif isinstance(boundcam, collada.camera.BoundOrthographicCamera):
lens = OrthographicLens()
base.cam.node().setLens(lens)
base.camLens = lens
#.........这里部分代码省略.........
示例5: load_into_bamfile
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import setGeomState [as 别名]
def load_into_bamfile(meshdata, subfiles, model):
"""Uses pycollada and panda3d to load meshdata and subfiles and
write out to a bam file on disk"""
if os.path.isfile(model.bam_file):
print 'returning cached bam file'
return model.bam_file
mesh = load_mesh(meshdata, subfiles)
model_name = model.model_json['full_path'].replace('/', '_')
if model.model_type == 'progressive' and model.model_subtype == 'full':
progressive_stream = model.model_json['metadata']['types']['progressive'].get('progressive_stream')
if progressive_stream is not None:
print 'LOADING PROGRESSIVE STREAM'
data = model.prog_data
try:
mesh = add_back_pm.add_back_pm(mesh, StringIO(data), 100)
print '-----'
print 'SUCCESSFULLY ADDED BACK PM'
print '-----'
except:
f = open(model.bam_file, 'w')
f.close()
raise
print 'loading into bamfile', model_name, mesh
scene_members = pandacore.getSceneMembers(mesh)
print 'got scene members', model_name, mesh
rotateNode = GeomNode("rotater")
rotatePath = NodePath(rotateNode)
matrix = numpy.identity(4)
if mesh.assetInfo.upaxis == collada.asset.UP_AXIS.X_UP:
r = collada.scene.RotateTransform(0,1,0,90)
matrix = r.matrix
elif mesh.assetInfo.upaxis == collada.asset.UP_AXIS.Y_UP:
r = collada.scene.RotateTransform(1,0,0,90)
matrix = r.matrix
rotatePath.setMat(Mat4(*matrix.T.flatten().tolist()))
for geom, renderstate, mat4 in scene_members:
node = GeomNode("primitive")
node.addGeom(geom)
if renderstate is not None:
node.setGeomState(0, renderstate)
geomPath = rotatePath.attachNewNode(node)
geomPath.setMat(mat4)
print 'created np', model_name, mesh
if model.model_type != 'optimized_unflattened' and model.model_type != 'progressive':
print 'ABOUT TO FLATTEN'
rotatePath.flattenStrong()
print 'DONE FLATTENING'
print 'flattened', model_name, mesh
wrappedNode = pandacore.centerAndScale(rotatePath)
wrappedNode.setName(model_name)
wrappedNode.writeBamFile(model.bam_file)
print 'saved', model_name, mesh
wrappedNode = None
return model.bam_file
示例6: __init__
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import setGeomState [as 别名]
def __init__(self, mesh_path, progressive_texture_path):
resolutions = []
f = tarfile.open(progressive_texture_path)
for resolution_name in f.getnames():
toset = {'size': resolution_name[:-4],
'contents': f.extractfile(resolution_name).read()}
texpnm = PNMImage()
texpnm.read(StringStream(toset['contents']), 'something.jpg')
newtex = Texture()
newtex.load(texpnm)
toset['texture'] = newtex
resolutions.append(toset)
self.resolutions = resolutions
def aux_loader(fname):
return resolutions[0]['contents']
mesh = collada.Collada(mesh_path, aux_file_loader=aux_loader)
scene_members = getSceneMembers(mesh)
base = ShowBase()
rotateNode = GeomNode("rotater")
rotatePath = render.attachNewNode(rotateNode)
matrix = numpy.identity(4)
if mesh.assetInfo.upaxis == collada.asset.UP_AXIS.X_UP:
r = collada.scene.RotateTransform(0,1,0,90)
matrix = r.matrix
elif mesh.assetInfo.upaxis == collada.asset.UP_AXIS.Y_UP:
r = collada.scene.RotateTransform(1,0,0,90)
matrix = r.matrix
rotatePath.setMat(Mat4(*matrix.T.flatten().tolist()))
geom, renderstate, mat4 = scene_members[0]
node = GeomNode("primitive")
node.addGeom(geom)
if renderstate is not None:
node.setGeomState(0, renderstate)
self.geomPath = rotatePath.attachNewNode(node)
self.geomPath.setMat(mat4)
wrappedNode = ensureCameraAt(self.geomPath, base.camera)
base.disableMouse()
attachLights(render)
render.setShaderAuto()
render.setTransparency(TransparencyAttrib.MDual, 1)
base.render.analyze()
KeyboardMovement()
MouseDrag(wrappedNode)
MouseScaleZoom(wrappedNode)
MouseCamera()
num_resolutions = len(resolutions) - 1
self.slider = DirectSlider(range=(0, num_resolutions),
value=0, pageSize=1,
command=self.sliderMoved, pos=(0, 0, -.9), scale=1)
for key, val in uiArgs.iteritems():
self.slider.thumb[key] = val
self.triText = OnscreenText(text="", pos=(-1,0.85), scale = 0.15,
fg=(1, 0.5, 0.5, 1), align=TextNode.ALeft, mayChange=1)
base.run()
示例7: getPmPerceptualError
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import setGeomState [as 别名]
def getPmPerceptualError(mesh, pm_filebuf, mipmap_tarfilebuf):
perceptualdiff = which('perceptualdiff')
if perceptualdiff is None:
raise Exception("perceptualdiff exectuable not found on path")
pm_chunks = []
if pm_filebuf is not None:
data = pm_filebuf.read(PM_CHUNK_SIZE)
refinements_read = 0
num_refinements = None
while len(data) > 0:
(refinements_read, num_refinements, pm_refinements, data_left) = pdae_utils.readPDAEPartial(data, refinements_read, num_refinements)
pm_chunks.append(pm_refinements)
data = data_left + pm_filebuf.read(PM_CHUNK_SIZE)
tar = tarfile.TarFile(fileobj=mipmap_tarfilebuf)
texsizes = []
largest_tarinfo = (0, None)
for tarinfo in tar:
tarinfo.xsize = int(tarinfo.name.split('x')[0])
if tarinfo.xsize > largest_tarinfo[0]:
largest_tarinfo = (tarinfo.xsize, tarinfo)
if tarinfo.xsize >= 128:
texsizes.append(tarinfo)
if len(texsizes) == 0:
texsizes.append(largest_tarinfo[1])
texsizes = sorted(texsizes, key=lambda t: t.xsize)
texims = []
first_image_data = None
for tarinfo in texsizes:
f = tar.extractfile(tarinfo)
texdata = f.read()
if first_image_data is None:
first_image_data = texdata
texpnm = PNMImage()
texpnm.read(StringStream(texdata), 'something.jpg')
newtex = Texture()
newtex.load(texpnm)
texims.append(newtex)
mesh.images[0].setData(first_image_data)
scene_members = getSceneMembers(mesh)
# turn off panda3d printing to stdout
nout = MultiplexStream()
Notify.ptr().setOstreamPtr(nout, 0)
nout.addFile(Filename(os.devnull))
base = ShowBase()
rotateNode = GeomNode("rotater")
rotatePath = base.render.attachNewNode(rotateNode)
matrix = numpy.identity(4)
if mesh.assetInfo.upaxis == collada.asset.UP_AXIS.X_UP:
r = collada.scene.RotateTransform(0,1,0,90)
matrix = r.matrix
elif mesh.assetInfo.upaxis == collada.asset.UP_AXIS.Y_UP:
r = collada.scene.RotateTransform(1,0,0,90)
matrix = r.matrix
rotatePath.setMat(Mat4(*matrix.T.flatten().tolist()))
geom, renderstate, mat4 = scene_members[0]
node = GeomNode("primitive")
node.addGeom(geom)
if renderstate is not None:
node.setGeomState(0, renderstate)
geomPath = rotatePath.attachNewNode(node)
geomPath.setMat(mat4)
wrappedNode = ensureCameraAt(geomPath, base.camera)
base.disableMouse()
attachLights(base.render)
base.render.setShaderAuto()
base.render.setTransparency(TransparencyAttrib.MNone)
base.render.setColorScaleOff(9999)
controls.KeyboardMovement()
controls.MouseDrag(wrappedNode)
controls.MouseScaleZoom(wrappedNode)
controls.ButtonUtils(wrappedNode)
controls.MouseCamera()
error_data = []
try:
tempdir = tempfile.mkdtemp(prefix='meshtool-print-pm-perceptual-error')
triangleCounts = []
hprs = [(0, 0, 0),
(0, 90, 0),
(0, 180, 0),
(0, 270, 0),
(90, 0, 0),
(-90, 0, 0)]
for texim in texims:
#.........这里部分代码省略.........