Skip to content

Commit 223b0bb

Browse files
author
hartsantler
committed
added support for "*" multiply operator
1 parent 71d5664 commit 223b0bb

4 files changed

Lines changed: 54 additions & 0 deletions

File tree

bindings/three.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ def add(self, other):
6464
self.set( self.x+other.x, self.y+other.y, self.z+other.z )
6565
return self
6666

67+
#def __iadd__(self, other):
68+
6769
def addScalar(self, s):
6870
self.set( self.x+s, self.y+s, self.z+s )
6971
return self
@@ -73,6 +75,46 @@ def addVectors(self, a,b):
7375
self.set( a.x+b.x, a.y+b.y, a.z+b.z )
7476
return self
7577

78+
def sub(self, other):
79+
assert isinstance(other, Vector3)
80+
self.set( self.x-other.x, self.y-other.y, self.z-other.z )
81+
return self
82+
83+
def subVectors(self, a,b):
84+
var( a=Vector3, b=Vector3 )
85+
self.set( a.x-b.x, a.y-b.y, a.z-b.z )
86+
return self
87+
88+
def multiply(self, other):
89+
assert isinstance(other, Vector3)
90+
self.set( self.x*other.x, self.y*other.y, self.z*other.z )
91+
return self
92+
93+
def multiplyScalar(self, s):
94+
self.set( self.x*s, self.y*s, self.z*s )
95+
return self
96+
97+
def multiplyVectors(self, a,b):
98+
var( a=Vector3, b=Vector3 )
99+
self.set( a.x*b.x, a.y*b.y, a.z*b.z )
100+
return self
101+
102+
def applyMatrix3(self, m):
103+
vec = self._vec
104+
JS('vec.applyMatrix3(m)')
105+
return self
106+
107+
def applyMatrix4(self, m):
108+
vec = self._vec
109+
JS('vec.applyMatrix4(m)')
110+
return self
111+
112+
def applyProjection(self, m):
113+
vec = self._vec
114+
JS('vec.applyProjection(m)')
115+
return self
116+
117+
76118

77119
class _ObjectBase:
78120
def add(self, child):

pythonscript/python_to_pythonjs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ def visit_NotEq(self, node):
257257
def visit_Is(self, node):
258258
return 'is'
259259

260+
def visit_Mult(self, node):
261+
return '*'
262+
260263
def visit_Add(self, node):
261264
return '+'
262265

pythonscript/pythonjs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ def visit_BinOp(self, node):
158158
right = self.visit(node.right)
159159
return '%s %s %s' % (left, op, right)
160160

161+
def visit_Mult(self, node):
162+
return '*'
163+
161164
def visit_Add(self, node):
162165
return '+'
163166

tests/threejs_vector3.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
print( v1.y )
3737
print( v1.z )
3838

39+
v1.multiply( v4 )
40+
print( v1.x )
41+
print( v1.y )
42+
print( v1.z )
43+
44+
3945
</script>
4046
</head>
4147

0 commit comments

Comments
 (0)