Comments (8)
Hi, thanks for the response! I looked through pyglet code and you are right. I tried what you mentioned, but I had to make these changes in viewer.py. I am sure there is a better way than this though.
self._is_active = True
# if self.run_in_thread:
# self._thread = Thread(target=self._init_and_start_app)
# self._thread.start()
# else:
self._init_and_start_app()
self.switch_to()
self.set_caption(self.viewer_flags['window_title'])
# pyglet.app.run()
def start_app(self):
pyglet.app.run()
def _compute_initial_camera_pose(self):
And here is my working test code.
import trimesh
import pyrender
import numpy
import threading
import time
fuze_trimesh = trimesh.load('examples/models/fuze.obj')
mesh = pyrender.Mesh.from_trimesh(fuze_trimesh)
scene = pyrender.Scene()
scene.add(mesh)
v = pyrender.Viewer(scene, run_in_thread=True, use_raymond_lighting=True)
def event_loop():
global v
i = 0
while v.is_active:
pose = numpy.eye(4)
pose[:3,3] = [i, 0, 0]
v.render_lock.acquire()
for n in v.scene.mesh_nodes:
v.scene.set_pose(n, pose)
v.render_lock.release()
i += 0.01
time.sleep(0.1)
t = threading.Thread(target=event_loop)
t.start()
v.start_app()
from pyrender.
Another approach could be to add an animation thread to the viewer.
viewer.py:
def __init__(self, scene, viewport_size=None,
render_flags=None, viewer_flags=None,
registered_keys=None, run_in_thread=False, AnimationThread=None, **kwargs):
...
if AnimationThread is not None:
animation_thread = AnimationThread(self._render_lock)
animation_thread.start()
# add animation logic before starting the app
if self.run_in_thread:
test.py:
import threading
class AnimationThread(threading.Thread):
def __init__(self, render_lock):
threading.Thread.__init__(self)
self._render_lock = render_lock
def run(self):
y, z = 0, 0
while True:
pose = T.euler_matrix(0, y, z)
self._render_lock.acquire()
scene.set_pose(mesh_node, pose)
self._render_lock.release()
y += 0.1
z += 0.01
time.sleep(1./24)
viewer = pyrender.Viewer(scene, viewport_size=(width, height), AnimationThread=AnimationThread)
@mmatl I have seen that you use the lower level _thread module, so maybe you could define an abstract class for this AnimationThread and then just give the user possibility to define the logic. I could do a pull request if you like the concept.
from pyrender.
Hi @wilbown Thanks for the issue! I don't have a windows machine, so I haven't been able to test this behavior yet. It seems like Pyglet explicitly disallows multithreading on windows, so you might be out of luck for the moment until I replace the windowing system with something better than pyglet :( I'll look into why pyglet does that, though.
from pyrender.
Actually, come to think of it, there is another option -- instead of calling the viewer with run_in_thread
set, in your application, start a new thread to run your scene update code and run the viewer in normal mode in the main thread. This should work around your problem, although it's not as easy or clean.
from pyrender.
Maybe the idea would be to make Viewer thread safe in general (by taking out check for render_lock functioning) and a switch to get the object back and manually start the window. This might be useful for anyone who might want to run a separate thread for control, not just making work on Windows. But I could probably subclass as well.
from pyrender.
@wilbown @andreiburov I have pyglet 1.5.0, where I can find viewer.py file to change some code?
from pyrender.
Hello,
I have just tested the suggestion of @wilbown. In fact you just need to run the update code in a thread, you don't need to modify viewer.py.
In short, this code is running:
import trimesh
import pyrender
import numpy
import threading
import time
fuze_trimesh = trimesh.load('examples/models/fuze.obj')
mesh = pyrender.Mesh.from_trimesh(fuze_trimesh)
scene = pyrender.Scene()
scene.add(mesh)
v = pyrender.Viewer(scene, run_in_thread=True, use_raymond_lighting=True)
def event_loop():
global v
i = 0
while v.is_active:
pose = numpy.eye(4)
pose[:3,3] = [i, 0, 0]
v.render_lock.acquire()
for n in v.scene.mesh_nodes:
v.scene.set_pose(n, pose)
v.render_lock.release()
i += 0.01
time.sleep(0.1)
t = threading.Thread(target=event_loop)
t.start()
Nicolas
from pyrender.
On MacOS it's the same error.
It's really some kind of trolling - creating a rendering library without ability to update scene.
from pyrender.
Related Issues (20)
- Setting camera pose in pyrender HOT 2
- pyrender offscreen render with the SKIP_CULL_FACES flag outputs inconsistent results HOT 1
- The `smooth` attribute is not modified for the materials for the from_trimesh() function
- how to use gpu?
- Rendering depth is broken for non-perspective cameras
- PerspectiveCamera: some yfov values causes image to flip HOT 1
- Disabling mipmapping on textures
- How to define a glass/gold/metal Texture?
- Rendering light HOT 2
- error in material.SpecularGlossinessMaterial()
- Request for Assistance: Obtaining Pixel-to-Face Index in Pyrender
- BROKEN LINK: Google colab notebooks HOT 1
- Invalid device ID (0), Pyrender NOT working on Python 3.10 HOT 5
- Inverted triangles?
- How to retrieve intrinsic camera parameters from PerspectiveCamera
- Textures rendering slanted
- Sphere Rendered with Non-reflective Material Not Appearing Black
- offscreen error
- 'Viewer' object has no attribute 'render'. Did you mean: '_render'?
- Interpolation artifacts in segmentation masks.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyrender.