Last active
January 31, 2019 06:16
-
-
Save cortical-iv/b2c4d1d2fae88a5778287adce3f7ba92 to your computer and use it in GitHub Desktop.
Trying to make one texture smaller than card
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Want the sine texture to be a little square inside the card, with noise texture filling the card. | |
""" | |
from direct.showbase.ShowBase import ShowBase | |
from panda3d.core import Texture, CardMaker, TextureStage | |
from direct.gui.OnscreenText import OnscreenText | |
import numpy as np | |
#Create matrices for textures | |
#sin | |
sinSize = 512 | |
def sin3d(X, freq = 1): | |
return np.sin(X*freq) | |
def sin8bit(X, freq = 1): | |
sin_float = sin3d(X, freq=freq) | |
sin_pos = (sin_float+1)*127.5; #from 0-255 | |
return np.asarray(sin_pos, dtype = np.uint8) | |
x = np.linspace(-8, 8, sinSize) | |
y = np.linspace(-8, 8, sinSize) | |
X, Y = np.meshgrid(x,y) | |
sinTex = sin8bit(X, freq = 1); | |
#noise | |
noiseSize = 512 | |
noiseTex = data = np.array(np.random.rand(noiseSize,noiseSize) * 255, dtype=np.uint8) | |
class MyApp(ShowBase): | |
def __init__(self): | |
ShowBase.__init__(self) | |
#CREATE TEXTURE STAGES | |
#Sine | |
self.sinTexture = Texture("sin") | |
self.sinTexture.setup2dTexture(sinSize, sinSize, Texture.T_unsigned_byte, Texture.F_luminance) | |
self.sinTexture.setRamImage(sinTex) | |
self.sinTextureStage = TextureStage('sin') | |
#Noise | |
self.noiseTexture = Texture("noise") | |
self.noiseTexture.setup2dTexture(noiseSize, noiseSize, Texture.T_unsigned_byte, Texture.F_luminance) | |
self.noiseTexture.setRamImage(noiseTex) | |
self.noiseTextureStage = TextureStage('noise') | |
#CREATE CARDS/SCENEGRAPH | |
cm = CardMaker('card1') | |
#Try to make texture smaller | |
#cm.setUvRange(-.2,.2,-.2,.2) | |
self.card1 = self.aspect2d.attachNewNode(cm.generate()) | |
#SET TEXTURE STAGES | |
self.card1.setTexture(self.sinTextureStage, self.sinTexture) #ts, tx | |
self.card1.setTexture(self.noiseTextureStage, self.noiseTexture) | |
#CARD TRANSFORMATIONS | |
self.card1.setPos(-.7,0,-.85) | |
#TEXTURE STAGE TRANSFORMS | |
#Scale | |
self.card1.setTexScale(self.sinTextureStage, 2, 1) | |
self.title = OnscreenText("x", | |
style = 1, | |
fg = (1,1,1,1), | |
bg = (0, 0, 0, 1), | |
pos = (0,0), | |
scale = 0.09) | |
app = MyApp() | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment