Skip to content

Commit 21a47ad

Browse files
authored
Merge pull request #115 from vidartf/autogen-etc
Autogen changes omnibus
2 parents 701ceb6 + 070804b commit 21a47ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1196
-673
lines changed

examples/BufferAttributes and BufferGeometry.ipynb

Lines changed: 87 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@
1212
]
1313
},
1414
{
15-
"cell_type": "code",
16-
"execution_count": null,
15+
"cell_type": "markdown",
1716
"metadata": {},
18-
"outputs": [],
1917
"source": [
20-
"#\n",
21-
"# BufferAttribute\n",
22-
"#"
18+
"## BufferAttribute"
2319
]
2420
},
2521
{
@@ -64,14 +60,10 @@
6460
]
6561
},
6662
{
67-
"cell_type": "code",
68-
"execution_count": null,
63+
"cell_type": "markdown",
6964
"metadata": {},
70-
"outputs": [],
7165
"source": [
72-
"#\n",
73-
"# BufferGeometry\n",
74-
"#"
66+
"## BufferGeometry"
7567
]
7668
},
7769
{
@@ -80,16 +72,17 @@
8072
"metadata": {},
8173
"outputs": [],
8274
"source": [
75+
"scale_factor = 20\n",
8376
"# Simple square\n",
8477
"vertices = BufferAttribute(\n",
85-
" array=np.array([\n",
86-
" [-1.0, -1.0, 1.0],\n",
87-
" [ 1.0, -1.0, 1.0],\n",
88-
" [ 1.0, 1.0, 1.0],\n",
78+
" array=scale_factor * np.array([\n",
79+
" [-1.0, -1.0, 0.0],\n",
80+
" [ 1.0, -1.0, 0.0],\n",
81+
" [ 1.0, 1.0, 0.0],\n",
8982
" \n",
90-
" [ 1.0, 1.0, 1.0],\n",
91-
" [-1.0, 1.0, 1.0],\n",
92-
" [-1.0, -1.0, 1.0],\n",
83+
" [ 1.0, 1.0, 0.0],\n",
84+
" [-1.0, 1.0, 0.0],\n",
85+
" [-1.0, -1.0, 0.0],\n",
9386
" ], dtype=np.float32),\n",
9487
" normalized=False)"
9588
]
@@ -120,14 +113,14 @@
120113
"metadata": {},
121114
"outputs": [],
122115
"source": [
123-
"vertices.array = np.array([\n",
124-
" [-1.0, -1.0, 1.0],\n",
125-
" [ 2.0, -2.0, 2.0],\n",
126-
" [ 1.0, 1.0, 1.0],\n",
116+
"vertices.array = scale_factor * np.array([\n",
117+
" [-1.0, -1.0, 0.0],\n",
118+
" [ 2.0, -2.0, 1.0],\n",
119+
" [ 1.0, 1.0, 0.0],\n",
127120
" \n",
128-
" [ 1.0, 1.0, 1.0],\n",
129-
" [-1.0, 1.0, 1.0],\n",
130-
" [-1.0, -1.0, 1.0],\n",
121+
" [ 1.0, 1.0, 0.0],\n",
122+
" [-1.0, 1.0, 0.0],\n",
123+
" [-1.0, -1.0, 0.0],\n",
131124
" ])"
132125
]
133126
},
@@ -137,14 +130,14 @@
137130
"metadata": {},
138131
"outputs": [],
139132
"source": [
140-
"vertices.array = np.array([\n",
141-
" [-1.0, -1.0, 1.0],\n",
142-
" [ 1.0, -1.0, 1.0],\n",
143-
" [ 1.0, 1.0, 1.0],\n",
133+
"vertices.array = scale_factor * np.array([\n",
134+
" [-1.0, -1.0, 0.0],\n",
135+
" [ 1.0, -1.0, 0.0],\n",
136+
" [ 1.0, 1.0, 0.0],\n",
144137
" \n",
145-
" [ 1.0, 1.0, 1.0],\n",
146-
" [-1.0, 1.0, 1.0],\n",
147-
" [-1.0, -1.0, 1.0],\n",
138+
" [ 1.0, 1.0, 0.0],\n",
139+
" [-1.0, 1.0, 0.0],\n",
140+
" [-1.0, -1.0, 0.0],\n",
148141
" ])"
149142
]
150143
},
@@ -157,15 +150,72 @@
157150
"print(repr(geometry))"
158151
]
159152
},
153+
{
154+
"cell_type": "markdown",
155+
"metadata": {},
156+
"source": [
157+
"### Index attribute"
158+
]
159+
},
160+
{
161+
"cell_type": "code",
162+
"execution_count": null,
163+
"metadata": {},
164+
"outputs": [],
165+
"source": [
166+
"# Simple square with unique vertices\n",
167+
"vertices = BufferAttribute(\n",
168+
" array=scale_factor * np.array([\n",
169+
" [-1.0, -1.0, 0.0],\n",
170+
" [ 1.0, -1.0, 0.0],\n",
171+
" [ 1.0, 1.0, 0.0],\n",
172+
" [-1.0, 1.0, 0.0],\n",
173+
" ], dtype=np.float32),\n",
174+
" normalized=False)"
175+
]
176+
},
177+
{
178+
"cell_type": "code",
179+
"execution_count": null,
180+
"metadata": {},
181+
"outputs": [],
182+
"source": [
183+
"# Index buffer\n",
184+
"index = BufferAttribute(\n",
185+
" array=np.array([\n",
186+
" [0, 1, 2],\n",
187+
" [2, 3, 0],\n",
188+
" ], dtype=np.uint16).ravel(),\n",
189+
" normalized=False)"
190+
]
191+
},
192+
{
193+
"cell_type": "code",
194+
"execution_count": null,
195+
"metadata": {},
196+
"outputs": [],
197+
"source": [
198+
"geometry = PlainBufferGeometry(\n",
199+
" attributes={\n",
200+
" 'position': vertices,\n",
201+
" 'index': index,\n",
202+
" })"
203+
]
204+
},
160205
{
161206
"cell_type": "code",
162207
"execution_count": null,
163208
"metadata": {},
164209
"outputs": [],
165210
"source": [
166-
"#\n",
167-
"# PlainBufferGeometry.from_geometry\n",
168-
"#"
211+
"geometry"
212+
]
213+
},
214+
{
215+
"cell_type": "markdown",
216+
"metadata": {},
217+
"source": [
218+
"### PlainBufferGeometry.from_geometry"
169219
]
170220
},
171221
{
@@ -266,7 +316,7 @@
266316
"name": "python",
267317
"nbconvert_exporter": "python",
268318
"pygments_lexer": "ipython3",
269-
"version": "3.5.3"
319+
"version": "3.5.4"
270320
}
271321
},
272322
"nbformat": 4,

examples/Combined Camera.ipynb

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Combined Camera\n",
8+
"\n",
9+
"A combined camera allows you to easily switch between a perspective camera and an orthographic camera."
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": null,
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"from pythreejs import *\n",
19+
"from IPython.display import display"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": null,
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"mesh1 = Mesh(SphereBufferGeometry(20, 16, 16), MeshPhysicalMaterial(color='red'), position=[-20, 0, 0])\n",
29+
"mesh2 = Mesh(SphereBufferGeometry(20, 16, 16), MeshPhysicalMaterial(color='green'), position=[20, 0, 0])"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": null,
35+
"metadata": {},
36+
"outputs": [],
37+
"source": [
38+
"view_width = 600\n",
39+
"view_height = 400\n",
40+
"camera = CombinedCamera(position=[0, 0, 60], width=view_width, height=view_height)"
41+
]
42+
},
43+
{
44+
"cell_type": "code",
45+
"execution_count": null,
46+
"metadata": {},
47+
"outputs": [],
48+
"source": [
49+
"key_light = PointLight(position=[-100, 100, 100])\n",
50+
"ambient_light = AmbientLight(intensity=0.4)\n",
51+
"scene = Scene(children=[mesh1, mesh2, key_light, ambient_light, camera])\n",
52+
"renderer = Renderer(scene=scene, camera=camera, controls=[OrbitControls(controlling=camera)],\n",
53+
" width=view_width, height=view_height)\n",
54+
"display(renderer)"
55+
]
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": null,
60+
"metadata": {},
61+
"outputs": [],
62+
"source": [
63+
"camera.mode = 'orthographic'"
64+
]
65+
},
66+
{
67+
"cell_type": "code",
68+
"execution_count": null,
69+
"metadata": {},
70+
"outputs": [],
71+
"source": [
72+
"camera.mode = 'perspective'"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"metadata": {},
79+
"outputs": [],
80+
"source": []
81+
}
82+
],
83+
"metadata": {
84+
"kernelspec": {
85+
"display_name": "Python 3",
86+
"language": "python",
87+
"name": "python3"
88+
},
89+
"language_info": {
90+
"codemirror_mode": {
91+
"name": "ipython",
92+
"version": 3
93+
},
94+
"file_extension": ".py",
95+
"mimetype": "text/x-python",
96+
"name": "python",
97+
"nbconvert_exporter": "python",
98+
"pygments_lexer": "ipython3",
99+
"version": "3.5.4"
100+
}
101+
},
102+
"nbformat": 4,
103+
"nbformat_minor": 2
104+
}

0 commit comments

Comments
 (0)