本文整理汇总了Python中panda3d.core.Texture.setRamImage方法的典型用法代码示例。如果您正苦于以下问题:Python Texture.setRamImage方法的具体用法?Python Texture.setRamImage怎么用?Python Texture.setRamImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.Texture
的用法示例。
在下文中一共展示了Texture.setRamImage方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: VideoWall
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setRamImage [as 别名]
class VideoWall(object):
res = 256
def __init__(self, loader, parentNodePath):
w = loader.loadModel("plane")
w.reparentTo(parentNodePath)
size = 6
w.setPos(3.5, 15, size / 2 - 3)
w.setColor(1,0,0)
w.setHpr(0, 180, 0)
w.setScale(size, 1, size / 1.33)
w.setTwoSided(True)
self.tx = Texture("video")
self.tx.setup2dTexture(self.res, self.res, Texture.TUnsignedByte, Texture.FRgb8)
# this makes some important setup call
self.tx.load(PNMImage(self.res, self.res))
w.setTexture(self.tx)
m = Material("vid")
m.setTwoside(True)
m.setEmission(VBase4(1,1,1,1))
w.setMaterial(m)
w.setFogOff()
def updateFromPixbuf(self, pb):
scaled = pb.scale_simple(self.res, self.res, gtk.gdk.INTERP_BILINEAR)
# about 3ms
n = numpy.fromstring(scaled.get_pixels(), dtype=numpy.uint8).reshape((-1,3))
flipped = numpy.fliplr(n).tostring()
self.tx.setRamImage(flipped)
示例2: createMaskedTexture
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setRamImage [as 别名]
def createMaskedTexture(self, name):
name = self.prepTextureName(name)
original_name = name[len('masked-'):]
if self.textures.has_key(original_name):
tc = self.textures[original_name] # get the original texture
bm = tc.image_file
img_type = tc.image_type
if img_type == 'DDS':
mtex = TextureContainer(name, tc.panda_texture, tc.image_file, img_type)
self.textures[name] = mtex
return mtex
if img_type != 'IMG':
print 'ERROR in createMaskedTexture(): cant create masked texture from non IMG type image'
return None
# print type(bm)
# print len(bm)
# FIXME: this just copies the original right now! Need to implement the alpha-mask bit still
m_img = self.maskImg(bm, tc.panda_texture.getXSize() * tc.panda_texture.getYSize())
t = Texture() # create empty texture object
component_type = Texture.TUnsignedByte
format = Texture.FRgba
t.setup2dTexture(tc.panda_texture.getXSize(),tc.panda_texture.getYSize(), component_type, format)
t.setRamImage(m_img)
mtex = TextureContainer(name, t, m_img, img_type)
self.textures[name] = mtex
return mtex
else:
print 'TextureManager::createMaskedTexture() failed, original texture:%s not found' % (original_name)
return None
示例3: createTexture
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setRamImage [as 别名]
def createTexture(self, image):
(width, height) = cv.GetSize(image)
#Panda3D interpreta las imagenes al reves que OpenCV (verticalmente invertidas), por lo que es necesario tener esto en cuenta
cv.Flip(image, image, 0)
#OpenCV permite convertir la representacion interna de las imagenes a un formato descomprimido que puede ser guardado en un archivo.
#Esto puede utilizarse desde Panda3D para tomar la imagen y utilizarla como una textura.
imageString = image.tostring()
#PTAUchar es una clase que permite tomar un bloque de datos y utilizarlo desde componentes de Panda3D (en particular es util para texturas)
imagePointer = PTAUchar.emptyArray(0)
imagePointer.setData(imageString)
try:
self.count += 1
#Crea un nuevo objeto textura
texture = Texture('image' + str(self.count))
#Establece propiedades de la textura, como tamanio, tipo de datos y modelo de color. Las imagenes de OpenCV las estamos manejando
#como RGB, donde cada canal es de 8bits (un numero entero)
texture.setup2dTexture(width, height, Texture.TUnsignedByte, Texture.FRgb)
#Indicamos que utilice el bloque de datos obtenido anteriormente como origen de datos para la textura
texture.setRamImage(CPTAUchar(imagePointer), MovieTexture.CMOff)
except:
texture = None
return texture
示例4: loadTexture
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setRamImage [as 别名]
def loadTexture(self, texname, container):
# Note that we reference the texture files by name. This works under the
# assumption that texture names are unique!
if self.findTexture(texname) == True:
return # texture already loaded before
# print 'loading texture:', texname
t_type = ''
s3dentry = container.s3d_file_obj.getFile(texname)
if s3dentry != None:
texfile = s3dentry.data
(magic,) = struct.unpack('<2s', texfile[0:2])
if magic == 'BM':
t_type = 'IMG' # raw 32 bit rgba (actually argb)
# Generic BMP file
# patch up the sometimes irregular bmp headers
texfile = self.checkBmp(texfile, texname)
if texfile == None:
return
# turn bmp into a 32bit rgba true color image
# returns a tuple of (img, width, height)
img = self.createAlphaBMP(texfile, texname)
texfile = img[0] # so that the addTexture() at the bottom works
t = Texture() # create empty texture object
component_type = Texture.TUnsignedByte
format = Texture.FRgba
t.setup2dTexture(img[1], img[2], component_type, format)
t.setRamImage(img[0])
#t.load(ti) # load texture from pnmimage
elif magic == 'DD':
t_type = 'DDS'
# DDS file
dds = DDSFile(texfile)
dds.patchHeader()
# dds.dumpHeader()
# dds.uncompressToBmp()
# dds.save(texname+'.dds')
ts = StringStream(dds.buf) # turn into an istream
t = Texture() # create texture object
t.readDds(ts) # load texture from dds ram image
else:
print 'Error unsupported texture: %s magic:%s referenced in fragment: %i' % (texname, magic, f.id)
return
else:
print 'Error: texture %s not found in s3d archive' % (texname)
return
# t.setWrapU(Texture.WMClamp)
# t.setWrapV(Texture.WMClamp)
self.addTexture(texname, t, texfile, t_type)
示例5: p3dApp
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setRamImage [as 别名]
class p3dApp(ShowBase):
def __init__(self):
ShowBase.__init__(self);
# setup the environment or model
self.model = \
self.loader.loadModel("/usr/share/panda3d/models/box");
self.model.reparentTo(self.render);
self.model.setTag('Model', '1');
self.model.setScale(1.5, 1.5, 1.5);
# setup camera
self.camera.setPos(5,5,5)
self.camera.lookAt(0,0,0)
# Disable mouse control
self.disableMouse();
# Handle mouse events.
self.accept('mouse1', self.mouse_down);
# convert image from opencv to panda3d texture
# self.taskMgr.add(self.read_image_cv, "cvImageTask");
# Setup collision handler
self.handler = CollisionHandlerQueue()
self.traverser = CollisionTraverser('ColTraverser')
self.traverser.traverse(self.model)
self.ray = CollisionRay()
pickerNode = CollisionNode('MouseRay')
pickerNode.setFromCollideMask(GeomNode.getDefaultCollideMask())
pickerNP = self.camera.attachNewNode(pickerNode)
pickerNode.addSolid(self.ray)
self.traverser.addCollider(pickerNP, self.handler)
self.load_shader();
self.first_frame_loaded = False;
def read_image_cv(self):
"""
Pulls the next frame from the opencv part, and converts to a panda3d
texture and display it on the screen.
"""
cvim = self.cvapp.pull_frame()
w = cvim.shape[1];
h = cvim.shape[0];
cvim = cv2.flip(cvim, 0);
self.im = Texture("cvIm");
self.im.setCompression(Texture.CMOff);
self.im.setup2dTexture(w, h, Texture.TUnsignedByte, Texture.FLuminance);
self.im.setRamImage(cvim);
self.screen_im = OnscreenImage(parent=self.render2d, image=self.im, scale=(1, 1, 1), pos=(0, 0, 0));
self.cam2d.node().getDisplayRegion(0).setSort(-20);
def load_shader(self):
"""
The function loads the vertex and fragment shader.
It provides an example of sending the model-view-projection matrix
to the shader program when it's calculated.
"""
self.shader = Shader.load(Shader.SL_GLSL, "vertex.glsl", "fragment.glsl");
self.model.set_shader(self.shader)
self.model.set_shader_input("my_ModelViewProjectionMatrix", LMatrix4f())
def mouse_down(self):
"""
This function is called as a result of a mouse click.
It gets the vertex that was clicked by the mouse.
It sends the mouse position and the vertex position to the cv app.
"""
if (self.first_frame_loaded == False):
self.first_frame_loaded = True
self.read_image_cv()
return;
xPos = self.mouseWatcherNode.getMouseX()
yPos = self.mouseWatcherNode.getMouseY()
self.ray.setFromLens(self.camNode, xPos, yPos)
self.traverser.traverse(self.model)
self.handler.sortEntries()
if (self.handler.getNumEntries() > 0):
entry = self.handler.getEntry(0) # CollisionEntry
vpos = entry.getSurfacePoint(self.model)
res = self.cvapp.mouse_clicked(LPoint3f(xPos, yPos), vpos)
if (res == 1):
self.read_image_cv()
def set_cv_app(self, cvapp):
self.cvapp = cvapp;