Skip to content

Commit

Permalink
add a react three fiber viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Krande committed Jan 2, 2024
1 parent aadf298 commit 95871e1
Show file tree
Hide file tree
Showing 27 changed files with 4,664 additions and 7,124 deletions.
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include src/ada/sections/resources/ProfileDB.json
include src/ada/materials/metals/resources/NLMatParams.json
include src/ada/cadit/gxml/write/resources/xml_blank.xml
include src/ada/fem/results/resources/results.sql
include src/ada/fem/results/resources/results.sql
include src/ada/visit/resources/index.zip
53 changes: 53 additions & 0 deletions examples/experiments/rendering_pygfx/main_qt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import random

# mamba install pyside
from PySide6 import QtWidgets
from wgpu.gui.qt import WgpuCanvas

import pygfx as gfx


class Main(QtWidgets.QWidget):
def __init__(self):
super().__init__(None)
self.resize(640, 480)

# Creat button and hook it up
self._button = QtWidgets.QPushButton("Add a line", self)
self._button.clicked.connect(self._on_button_click)

# Create canvas, renderer and a scene object
self._canvas = WgpuCanvas(parent=self)
self._renderer = gfx.WgpuRenderer(self._canvas)
self._scene = gfx.Scene()
self._camera = gfx.OrthographicCamera(110, 110)

# Hook up the animate callback
self._canvas.request_draw(self.animate)

layout = QtWidgets.QHBoxLayout()
self.setLayout(layout)
layout.addWidget(self._button)
layout.addWidget(self._canvas)

def _on_button_click(self):
positions = [
[random.uniform(-50, 50), random.uniform(-50, 50), 0] for i in range(8)
]
line = gfx.Line(
gfx.Geometry(positions=positions), gfx.LineMaterial(thickness=3)
)
self._scene.add(line)
self._canvas.update()

def animate(self):
self._renderer.render(self._scene, self._camera)


app = QtWidgets.QApplication([])
m = Main()
m.show()


if __name__ == "__main__":
app.exec()
39 changes: 39 additions & 0 deletions examples/experiments/rendering_pygfx/main_wx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# run_example = false

import pygfx as gfx

# mamba install wxpython
import wx
from wgpu.gui.wx import WgpuCanvas


app = wx.App()

canvas = WgpuCanvas()
renderer = gfx.renderers.WgpuRenderer(canvas)
scene = gfx.Scene()

cube = gfx.Mesh(
gfx.box_geometry(200, 200, 200),
gfx.MeshPhongMaterial(color=(0.2, 0.4, 0.6, 1.0)),
)
scene.add(cube)

scene.add(gfx.AmbientLight())
scene.add(gfx.DirectionalLight(position=(0, 0, 1)))

camera = gfx.PerspectiveCamera(70, 16 / 9)
camera.position.z = 400


def animate():
rot = gfx.linalg.Quaternion().set_from_euler(gfx.linalg.Euler(0.005, 0.01))
cube.rotation.multiply(rot)

renderer.render(scene, camera)
canvas.request_draw()


if __name__ == "__main__":
canvas.request_draw(animate)
app.MainLoop()
40 changes: 0 additions & 40 deletions examples/experiments/rendering_react/embed-script.js

This file was deleted.

Loading

0 comments on commit 95871e1

Please sign in to comment.