Skip to content

Commit 74ee528

Browse files
committed
Fixes for geometry faces
1 parent 701ceb6 commit 74ee528

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

js/src/_base/Three.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -587,18 +587,35 @@ var ThreeModel = widgets.WidgetModel.extend({
587587

588588
// Faces
589589
convertFaceModelToThree: function(f, propName) {
590+
var normal = f[3];
591+
if (normal !== undefined && normal !== null) {
592+
if (Array.isArray(normal) && normal.length > 0 && Array.isArray(normal[0])) {
593+
normal = normal.map(function (value) {
594+
return this.convertVectorModelToThree(value);
595+
}, this);
596+
} else {
597+
normal = this.convertVectorModelToThree(normal);
598+
}
599+
}
600+
var color = f[4];
601+
if (color !== undefined && color !== null) {
602+
if (Array.isArray(color)) {
603+
color = color.map(function (value) {
604+
return new THREE.Color(value);
605+
}, this);
606+
} else {
607+
color = new THREE.Color(color);
608+
}
609+
}
590610
var result = new THREE.Face3(
591-
f[0], // a
592-
f[1], // b
593-
f[2], // c
594-
this.convertVectorModelToThree(f[3]), // normal
595-
new THREE.Color(f[4]), // color
596-
f[5] // materialIndex
611+
f[0], // a
612+
f[1], // b
613+
f[2], // c
614+
normal, // normal
615+
color, // color
616+
f[5] // materialIndex
597617
);
598618

599-
result.vertexNormals = this.convertVectorArrayModelToThree(f[6]); // vertexNormals
600-
result.vertexColors = this.convertColorArrayModelToThree(f[7]); // vertexColors
601-
602619
return result;
603620
},
604621

pythreejs/traits.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
from traitlets import (
33
Unicode, Int, CInt, Instance, Enum, List, Dict, Float, CFloat,
4-
Bool, Tuple, Undefined, TraitError,
4+
Bool, Tuple, Undefined, TraitError, Union,
55
)
66

77
from ipydatawidgets import DataUnion, NDArrayWidget
@@ -41,7 +41,18 @@ def Matrix4(trait_type=CFloat, default=None, **kwargs):
4141
return List(trait_type, default_value=default, minlen=16, maxlen=16, **kwargs)
4242

4343
def Face3(**kwargs):
44-
return Tuple(CInt(), CInt(), CInt(), Vector3(), Unicode(), CInt(), Tuple(), Tuple())
44+
return Tuple(
45+
CInt(), # a — Vertex A index.
46+
CInt(), # b — Vertex B index.
47+
CInt(), # c — Vertex C index.
48+
Union([ # normal — (optional) Face normal (Vector3) or array of 3 vertex normals.
49+
Vector3(),
50+
List(Vector3(), minlen=3, maxlen=3)]),
51+
Union([ # color — (optional) Face color or array of vertex colors.
52+
Unicode(),
53+
List(Unicode(), minlen=3, maxlen=3)]),
54+
CInt(), # materialIndex — (optional) which index of an array of materials to associate with the face.
55+
)
4556

4657
def Euler(default=None, **kwargs):
4758
if default is None:

0 commit comments

Comments
 (0)