Skip to content

Commit 2c7a2ae

Browse files
committed
Fixes to exampels
1 parent 8d5a65d commit 2c7a2ae

File tree

2 files changed

+205
-125
lines changed

2 files changed

+205
-125
lines changed

examples/BufferAttributes and BufferGeometry.ipynb

Lines changed: 85 additions & 35 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,15 +130,48 @@
137130
"metadata": {},
138131
"outputs": [],
139132
"source": [
140-
"vertices.array = np.array([\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",
137+
" \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",
141+
" ])"
142+
]
143+
},
144+
{
145+
"cell_type": "code",
146+
"execution_count": null,
147+
"metadata": {},
148+
"outputs": [],
149+
"source": [
150+
"print(repr(geometry))"
151+
]
152+
},
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=np.array([\n",
141169
" [-1.0, -1.0, 1.0],\n",
142170
" [ 1.0, -1.0, 1.0],\n",
143171
" [ 1.0, 1.0, 1.0],\n",
144-
" \n",
145-
" [ 1.0, 1.0, 1.0],\n",
146172
" [-1.0, 1.0, 1.0],\n",
147-
" [-1.0, -1.0, 1.0],\n",
148-
" ])"
173+
" ], dtype=np.float32),\n",
174+
" normalized=False)"
149175
]
150176
},
151177
{
@@ -154,7 +180,13 @@
154180
"metadata": {},
155181
"outputs": [],
156182
"source": [
157-
"print(repr(geometry))"
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)"
158190
]
159191
},
160192
{
@@ -163,9 +195,27 @@
163195
"metadata": {},
164196
"outputs": [],
165197
"source": [
166-
"#\n",
167-
"# PlainBufferGeometry.from_geometry\n",
168-
"#"
198+
"geometry = PlainBufferGeometry(\n",
199+
" attributes={\n",
200+
" 'position': vertices,\n",
201+
" 'index': index,\n",
202+
" })"
203+
]
204+
},
205+
{
206+
"cell_type": "code",
207+
"execution_count": null,
208+
"metadata": {},
209+
"outputs": [],
210+
"source": [
211+
"geometry"
212+
]
213+
},
214+
{
215+
"cell_type": "markdown",
216+
"metadata": {},
217+
"source": [
218+
"### PlainBufferGeometry.from_geometry"
169219
]
170220
},
171221
{

0 commit comments

Comments
 (0)