-
Notifications
You must be signed in to change notification settings - Fork 0
/
panda.py
121 lines (91 loc) · 3.51 KB
/
panda.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import sys
import time
from math import cos, pi, sin
import numpy as np
import panda3d.core
import skimage.io
from direct.actor.Actor import Actor
from direct.interval.IntervalGlobal import Sequence
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from panda3d.core import *
from panda3d.physics import ActorNode, ForceNode, LinearVectorForce
import computecolor
from flowgen import *
np.random.seed(123)
u = lambda a=0.0, b=1.0: (b - a) * np.random.rand() + a
CHAIRMODELS = "/home/jdt/Downloads/chairs/chairmodels/"
BACKGROUNDS = "/home/jdt/Downloads/chairs/city/"
CHARACTERS = "/home/jdt/Code/code3d/asset-pack/000-characters-med/Assets/models/"
loadPrcFileData("", "basic-shaders-only #f")
loadPrcFileData("", "hardware-animated-vertices #f")
loadPrcFileData("", "win-size 150 150")
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
# Disable the camera trackball controls.
# self.disableMouse()
self.mybase = NodePath("MyBase")
self.mybase.reparentTo(render)
self.camholder = NodePath("CamHolder")
self.camholder.reparentTo(render)
self.camera.reparentTo(self.camholder)
self.render.setShaderAuto()
# Load the environment model.
# self.environ = self.loader.loadModel("models/environment")
# Reparent the model to render.
# self.environ.reparentTo(self.mybase)
# Apply scale and position transforms on the model.
# self.environ.setScale(0.25, 0.25, 0.25)
# self.environ.setPos(-8, 42, 0)
# Add the spinCameraTask procedure to the task manager.
# self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
self.taskMgr.add(self.spinPandaTask, "SpinPandaTask")
# Load and transform the panda actor.
self.pandaActor = Actor("models/panda-model", {"walk": "models/panda-walk4"})
self.pandaActor.setScale(0.007, 0.005, 0.006)
self.pandaActor.setPos(0, 0, -0.2)
self.pH = 0.0
self.pP = 0.0
self.pR = 0.0
self.pandaActor.setHpr(self.pH, self.pP, self.pR)
self.pandaActor.reparentTo(self.mybase)
self.pandaActor.loop("walk")
self.camholder.setPos(0, -17, 0)
# self.camholder.setHpr(0, 20, 0)
sky = loader.loadModel("smiley.egg")
# sky.setTexture(skytex, 2)
sky.setColor(0, 1, 0)
sky.setTwoSided(True)
sky.reparentTo(self.mybase)
sky.setScale(30)
self.flowgen = FlowGen()
self.flowgen.flow_cam.reparentTo(self.camholder)
setup_flow_shading_on_node(self.mybase)
# Define a procedure to move the camera.
def spinCameraTask(self, task):
tt = globalClock.get_frame_time()
angleDegrees = tt * 6.0
angleRadians = angleDegrees * (pi / 180.0)
self.camholder.setPos(20 * sin(angleRadians), -20.0 * cos(angleRadians), 3)
self.camholder.setHpr(angleDegrees, 5 * sin(tt), 0)
return Task.cont
def spinPandaTask(self, task):
self.pH += u(-10, 10)
self.pP += u(-10, 10)
self.pR += u(-10, 10)
self.pandaActor.setHpr(self.pH, self.pP, self.pR)
return Task.cont
app = MyApp()
# app.run()
# clock = ClockObject()
globalClock.setMode(ClockObject.M_non_real_time)
globalClock.set_dt(0.1)
# taskMgr.setClock(clock)
app.flowgen.store_prev_data(app.mybase)
def generateSequence():
for t in range(50000):
taskMgr.step()
app.flowgen.save_images()
app.flowgen.store_prev_data(app.mybase)
generateSequence()