Sprite Cloud w/No Texture

Any ideas why this renders a cloud of non-textured sprites? I can tell that all of the sprites are correctly placed and oriented as I spin the scene but I have been unsuccessful in adding texture to them.

Thx!
Paul

# Standard imports

import sys
import os
import random

# Panda imports

from direct.gui.OnscreenText import OnscreenText 
from direct.showbase import DirectObject
from direct.showbase.DirectObject import DirectObject
import direct.directbase.DirectStart
from direct.task import Task
from pandac.PandaModules import *

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 

def P3DCreateAxes(lineThickness=1):

	ls = LineSegs()
	ls.setThickness(lineThickness)

	# X axis
	ls.setColor(1.0, 0.0, 0.0, 1.0)
	ls.moveTo(0.0, 0.0, 0.0)
	ls.drawTo(1.0, 0.0, 0.0)

	# Y axis
	ls.setColor(0.0, 1.0, 0.0, 1.0)
	ls.moveTo(0.0,0.0,0.0)
	ls.drawTo(0.0, 1.0, 0.0)

	# Z axis
	ls.setColor(0.0, 0.0, 1.0, 1.0)
	ls.moveTo(0.0,0.0,0.0)
	ls.drawTo(0.0, 0.0, 1.0)

	node = ls.create()
	return NodePath(node)

def CreateTextLabel(\
		text,
		color,
		i,
		xStart=-1.3,
		yStart=0.95,
		yOffset = 0.1,
		tFont=None
	):
	if tFont==None:
		return OnscreenText(\
				text = text,
				pos = (xStart, yStart-yOffset*i),
				fg=color,
				mayChange = True,
				align=TextNode.ALeft
			)
	else:
		return OnscreenText(\
				text = text,
				pos = (xStart, yStart-yOffset*i),
				fg=color,
				mayChange = True,
				align=TextNode.ALeft,
				font=tFont
			)

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 

class World(DirectObject):
	def postStatusMessage(self,msg):
		print msg
		self.mMessageDisplay.setText("> "+msg)
		taskMgr.doMethodLater(
			1.2,
			self.clearStatusDisplay,
			'',extraArgs =[]
		)

	def clearStatusDisplay(self):
		self.mMessageDisplay.setText("> ")

	def __init__(self):
		base.setBackgroundColor(0,0.1,0.6,1)
		self.accept('escape',sys.exit)
		text = 'Sprite Rendering Example'
		color = (1,1,0,1)
		self.mTextDisplay1 = CreateTextLabel(text,color,1)

		worldSize = 40.0

		base.camLens.setFar(9000)
		base.camLens.setFov(55, 75)
		base.cam.setPos(2*worldSize,-3*worldSize,worldSize)
		base.cam.setHpr(30,-10,0)

		axes = P3DCreateAxes(2)
		axes.setScale(worldSize,worldSize,worldSize)
		axes.reparentTo(render)

		# ------------------------------------------------------------
		# Define the vetex data format.
		gvf = GeomVertexFormat.getV3cp()

		# Create the vetex data container.
		vertexData = GeomVertexData('SpriteVertices',gvf,Geom.UHStatic)

		# Create writers
		vtxWriter = GeomVertexWriter(vertexData,'vertex')
		clrWriter = GeomVertexWriter(vertexData,'color')

		# Generate the vertices
		randGen = random.Random(5033)
		spriteCount = 1000
		xMean = 0
		yMean = 0
		zMean = 0
		xSigma = 0.1*worldSize
		ySigma = 0.5*worldSize
		zSigma = 0.2*worldSize
		billboardSize = 0.2
		for i in range(0,spriteCount):
			x = randGen.gauss(xMean,xSigma)
			y = randGen.gauss(yMean,ySigma)
			z = randGen.gauss(zMean,zSigma)
			print "%12.4f %12.4f %12.4f" % (x,y,z)
			vtxWriter.addData3f(x,y,z)
			clrWriter.addData3f(1,1,1)

		# Create a GeomPrimitive object and fill with the vertices.
		geom = Geom(vertexData)
		points = GeomPoints(Geom.UHStatic)
		points.setIndexType(Geom.NTUint32)
		for i in range(0,spriteCount):
			points.addVertex(i)

		points.closePrimitive()
		geom.addPrimitive(points)
		geomNode = GeomNode('Sprites')
		geomNode.addGeom(geom)
		cloud = NodePath(geomNode)
		cloud.reparentTo(render)

		cloudTex = loader.loadTexture('Cloud.png')
		if cloudTex==None:
			print "*** Failed loading cloud texture"
			sys.exit()

		cloud.setRenderModePerspective(True)
#		cloud.setRenderModeThickness(billboardSize)
		cloud.setTexGen(TextureStage.getDefault(), TexGenAttrib.MPointSprite)
		cloud.setTexture(cloudTex)
		# ------------------------------------------------------------

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 

world = World()

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Run the program

run()

if the textur is loaded correctly but not applied you can try to set the overwrite paramter.
change
cloud.setTexture(cloudTex)
to
cloud.setTexture(cloudTex,1)

in case your programm exits because the texture file couldn’t be loaded you should make shure it’s in the current path.

for more information see the manual
http://panda3d.org/manual/index.php/Simple_Texture_Replacement

Thanks but that didn’t fix it. Still looking …

i copy&pasted the code and just changed the texturename to a file i had on my harddisk (same folder as my file) and it worked without problems.
do you get any error messages?

No, I don’t get any error messages. Also, I put that trap in the code to exit out if the texture wasn’t loaded properly.

		cloudTex = loader.loadTexture('Cloud.png')
		if cloudTex==None:
			print "*** Failed loading cloud texture"
			sys.exit()

/Puzzled …

[edit]
It works fine for me also with other textures. For this one, it works when I add the following:

		cloud.setTransparency(TransparencyAttrib.MAlpha)
		cloud.setDepthTest(0)

Thanks for the help :slight_smile:

perhaps your texture is fully transparent (maybe save error from your paint programm?)?
well i uploaded a “small” video… its about 2mb where you can see your code working with the first image that came across my way while looking for a texture :stuck_out_tongue:
http://home.arcor.de/positiveelectron/files/clouds3.avi
it’s xvid coded so you need a propper decoder :stuck_out_tongue:
well if you cant find a player you could try to load the movie as texture for your sprites =) works,too^^, even if its up-side-down^^

Thanks so much for all the effort but unfortunately, I am unable to play the video. I installed xvid and it still doesn’t work on WMP or Nero. Trying to load it as a trexture fails also, message says that it exists but cannot be read.

You are right about the image. Photoshop’s histogram is flat … Guess that’s why the other textures work and it does not :smiley:

strange… really strange… well at lest VLC should be able to play it, if not there is something seriously wrong with your system.

btw gimp’s png’s are working fine with panda (including transparency if you enable alpha for the texture in panda). perhaps you can try with a non-transparent image… like jpeg or something

It’s working fine for the non-flat, transparent textures.

knology.net/~pleopard/images/SmokeSnap.gif