Beispiel #1
0
 def position3(self):
     p1 = self.position
     z = self.line.events.get(self.line.events.size() - 1).z_v
     if (isinstance(z, Vector3)):
         return Vector3(p1.x, p1.y, z.z)
     else:
         return Vector3(p1.x, p1.y, z)
Beispiel #2
0
    def __iadd__(self, translation):
        if (isinstance(translation, Vector2)):
            self.__dict__["line"] = (LineUtils().transformLine(
                self.line, Vector2(translation.x, translation.y), None, None,
                None))
        if (isinstance(translation, Vector3)):
            self.__dict__["line"] = (LineUtils().transformLine(
                self.line, Vector2(translation.x, translation.y), None, None,
                None))
        if (isinstance(translation, Quaternion)):
            self.__dict__["line"] = (LineUtils().transformLine(
                self.line, None, translation, None, None))
        if (isinstance(translation, rotation)):
            tx = None
            if (translation.around):
                try:
                    tx = translation.around(self) * -1.0
                    tx = Vector2(tx[0], tx[1])
                except:
                    tx = Vector2(-translation.around[0],
                                 -translation.around[1])
            else:
                tx = self.bounds().midpoint2().scale(-1)
            self.__dict__["line"] = (LineUtils().transformLine(
                self.line, tx, None,
                Quaternion().set(Vector3(0, 0, 1), translation.angle),
                Vector2(tx).scale(-1)))
        if (isinstance(translation, CoordinateFrame)):
            self.__dict__["line"] = (LineUtils().transformLine3(
                self.line, translation))

        return self
Beispiel #3
0
    def __imul__(self, scaleBy):
        translation = scaleBy
        if (isinstance(translation, Vector2)):
            tx = self.bounds().midpoint2().scale(-1)
            self.__dict__["line"] = (LineUtils().transformLine(
                self.line, tx, Vector2(translation.x, translation.y), None,
                Vector2(tx).scale(-1)))
        if (isinstance(translation, scale)):
            if (translation.around):
                try:
                    tx = translation.around(self) * -1.0
                    if (len(tx) == 2):
                        tx = Vector3(tx[0], tx[1], self.averageDepth())
                    else:
                        tx = Vector3(tx[0], tx[1], tx[2])
                except:
                    if (len(translation.around) == 2):
                        tx = Vector3(translation.around[0],
                                     translation.around[1],
                                     self.averageDepth())
                    else:
                        tx = Vector3(translation.around[0],
                                     translation.around[1],
                                     translation.around[2])
            else:
                tx = self.bounds().midpoint2().scale(-1)
                tx = Vector3(tx[0], tx[1], -self.averageDepth())
                self.__dict__["line"] = (LineUtils().transformLine3(
                    self.line, tx,
                    Vector3(1, 1, 1) * translation.amount, None,
                    Vector3(-tx[0], -tx[1], -tx[2])))

        if (isinstance(translation, Vector3)):
            tx = self.bounds().midpoint2().scale(-1)
            tx = Vector3(tx[0], tx[1], -self.averageDepth())
            self.__dict__["line"] = (LineUtils().transformLine3(
                self.line, tx, translation, None,
                Vector3(tx).scale(-1)))
        if (isinstance(translation, CoordinateFrame)):
            self.__dict__["line"] = (LineUtils().transformLine3(
                self.line, translation))

        return self
Beispiel #4
0
def setControl2(self, *p):
	"""Sets the control2 of this (cubic) node"""
	if (len(p)==2):
		self.setAt(1, Vector2(p[0], p[1]))
	elif(len(p)==3):
		self.setAt(1, Vector2(p[0], p[1]))
		if (len(self.args)==6):
			if(self.z_v):
				self.z_v.y = p[2]
			else:
				self.z_v = Vector3(p[2], p[2], p[2])
		else:
			self.z_v = p[2]
	return self
Beispiel #5
0
def setPosition(self, *p):
	"""Sets the position of this node"""
	if (len(p)==2):
		self.setAt(-1, Vector2(p[0], p[1]))
	elif(len(p)==3):
		self.setAt(-1, Vector2(p[0], p[1]))
		if (len(self.args)==6):
			if(self.z_v):
				self.z_v.z = p[2]
			else:
				self.z_v = Vector3(p[2], p[2], p[2])
		else:
			self.z_v = p[2]
	return self
Beispiel #6
0
def CFrame(r=Quaternion(), s=Vector3(1,1,1), t=Vector3(0,0,0), center=None):
	"""Constructs a Coordinate frame transformation with rotation 'r', scale 's', translation 't' around a center.

	all parmaters are optional, and a wide variety of types are understood (Vector2, Vector3, Quaternion, FLine, FLine Nodes, Tuples and lists)"""
	if (isinstance(center, (CachedLine, ))):
		a,b = center.bounds()
		center = (a+b)*0.5
	if (isinstance(t, (CachedLine, ))):
		a,b = t.bounds()
		t = (a+b)*0.5
	if (isinstance(r, (float,int,long))):
		r = Quaternion(r)
	if (isinstance(r, (Quaternion, ))):
		pass
	else:
		r = Quaternion(*r)
	if (isinstance(s, (float,int,long))):
		s = Vector3(s,s,s)
	if (isinstance(t, Event)):
		t = t.position()
	if (isinstance(t, Vector2)):
		t = Vector3(t.x, t.y,0)
	if (isinstance(s, Vector2)):
		s = Vector3(t.x, t.y,1)
	if (isinstance(s, (tuple, list))):
		if (len(s)==2):
			s = Vector3(s[0], s[1], 1)
		else:
			s = Vector3(s[0], s[1], s[2])
	if (isinstance(t, (tuple, list))):
		if (len(t)==2):
			t = Vector3(t[0], t[1], 1)
		else:
			t = Vector3(t[0], t[1], t[2])

	zz = CoordinateFrame(r, t, s)
	if (isinstance(center, (Event, ))):
		center = center.position()

	if (center):
		return CFrame(t=center)*zz*CFrame(t=-1.0*center)
	return zz
Beispiel #7
0
def __iadd__(self, translation):
	if (isinstance(translation, Vector2)):
		f = LineUtils().transformLine3(self, Vector3(translation.x, translation.y, 0), None, None, None)
		f.remapProperties(self)
		self.replaceContents(f)
	elif (isinstance(translation, Vector3)):
		f = (LineUtils().transformLine3(self, translation, None, None, None))
		f.remapProperties(self)
		self.replaceContents(f)
	elif (isinstance(translation, Quaternion)):
		f = (LineUtils().transformLine3(self, None, None, translation, None))
		f.remapProperties(self)
		self.replaceContents(f)
	elif (isinstance(translation, CoordinateFrame)):
		f = (LineUtils().transformLine3(self, translation));
		f.remapProperties(self)
		self.replaceContents(f)
	return self
Beispiel #8
0
def cubicTo(self, *x):
	"""Draws a curved segment.
for cubicTo(c1x,c1y, c2x, c2y, x, y) the curve moves to x,y by inflecting first towards c1x, c1y and then c2x, c2y. 
Likewise, but in 3d, for cubicTo(c1x,c1y,c1z,c2x,c2y,c2z,x,y,z)
	"""
	if (len(x)!=6 and len(x)!=9): raise AttributeError("cubicTo() takes 6 or 9 parameters")
	if (self.breakNext__):
		if (len(x)==6):
			self.getInput().moveTo(x[-2], x[-1])
		else:
			self.getInput().moveTo(x[-3], x[-2], x[-1])
	else:
		if (len(x)==6):
			self.getInput().cubicTo(*x)
		else:
			self.getInput().cubicTo(x[0], x[1], x[3], x[4], x[6], x[7])
			self.z_v = Vector3(x[2], x[5], x[8])
			self.containsDepth=1
	self.breakNext__=0
	return self
Beispiel #9
0
def vector234_idiv(self, other):
	if (isinstance(other, (Vector2, Vector3, Vector4, list, tuple))):
		for n in range(0, min(len(self), len(other))):
			self[n]/=other[n]
	elif (isinstance(other, Quaternion)):
		other = other.inverse()
		other.rotateVector(self)
		other = other.inverse()
	elif (isinstance(other, rotation)):
		if (other.around):
			self-=other.around
		if (isinstance(other.angle, Quaternion)):
			self/=other.angle
		else:
			self*=Quaternion().set(Vector3(0,0,1), -other.angle)
		if (other.around):
			self+=other.around
	else:
		for n in range(0, len(self)):
			self[n]/=other
	return self
Beispiel #10
0
def vector234_imul(self, other):
	if (isinstance(other, (Vector2, Vector3, Vector4, list, tuple))):
		for n in range(0, min(len(self), len(other))):
			self[n]*=other[n]
	elif (isinstance(other,CoordinateFrame)):
		other.transformPosition(self)
	elif (isinstance(other, Quaternion)):
		other.rotateVector(self)
	elif (isinstance(other, rotation)):
		if (other.around):
			self-=other.around
		if (isinstance(other.angle, Quaternion)):
			self*=other.angle
		else:
			self*=Quaternion().set(Vector3(0,0,1), other.angle)
		if (other.around):
			self+=other.around
	else:
		for n in range(0, len(self)):
			self[n]*=other
	return self
Beispiel #11
0
def cl__getattr__(self, att):
		if (att.startswith("__")): return object.__getattribute__(self,att)
		if (att=="nodes"):
			return self.events
		if (att=="position3"): 
			return self.events.get(self.events.size()-1).getDestination(None)
		if (att=="position"): 
			v2 = self.events.get(self.events.size()-1).getDestination(None)
			d = self.z_v
			if (d!=None):
				return Vector3(v2.x, v2.y, d)
			else:
				return v2

		if (att=="current"): return self.events.get(self.events.size()-1)

		if (att.endswith("_v")):
			return getattr(self.events[-1].getAttributes(), att)
		else:
			return getattr(self.getProperties(), att)

		return None
Beispiel #12
0
	def around(line):
                b = line.bounds()
                #print "bounds are %s " % b                                                                                                                  
                a = b.convertFromNDC(Vector3(x,y,0))
                #print "  aroudn is %s " % a                                                                                                                 
                return a
Beispiel #13
0
 def cubicTo(self, c1x, c1y, c1z, c2x, c2y, c2z, x, y, z):
     PLine.cubicTo(self, c1x, c1y, c2x, c2y, x, y)
     self.z_v = Vector3(c1z, c2z, z)
     return self
Beispiel #14
0
 def setBounds(self, bounds):
     """Rescale this line to fit in the Rect 'bounds'"""
     bb = self.bounds()
     return self.visitPositions(lambda x, y: bounds.convertFromNDC(
         bb.convertToNDC(Vector3(x, y, 0))))
Beispiel #15
0
def __add__(self, other):
	if (isinstance(other, CoordinateFrame)):
		return CoordinateFrame().multiply(self, other)
	if (isinstance(other, Vector3)):
		return self.transformDirection(Vector3(other))
Beispiel #16
0
def __mul__(self, other):
	print "cf mull self : %s other %s " % (self, other)
	if (isinstance(other, CoordinateFrame)):
		return CoordinateFrame().multiply(self, other)
	if (isinstance(other, Vector3)):
		return self.transformPosition(Vector3(other))