def __create_vector(self, *vec) -> Vector3: """ Converts a variety of vector types to a flatbuffer Vector3. Supports Flatbuffers Vector3, cTypes Vector3, list/tuple of numbers, or passing x,y,z (z optional) """ import numbers if len(vec) == 1: if hasattr(vec[0], "__getitem__"): # Support all subscriptable types. try: x = float(vec[0][0]) y = float(vec[0][1]) try: z = float(vec[0][2]) except (ValueError, IndexError): z = 0 except ValueError: raise ValueError( f"Unexpected type(s) for creating vector: {type(vec[0][0])}, {type(vec[0][1])}" ) except IndexError: raise IndexError( f"Unexpected IndexError when creating vector from type: {type(vec[0])}" ) elif isinstance(vec[0], Vector3.Vector3): x = vec[0].X() y = vec[0].Y() z = vec[0].Z() elif isinstance(vec[0], GameDataStructVector3): x = vec[0].x y = vec[0].y z = vec[0].z else: raise ValueError( f"Unexpected type for creating vector: {type(vec[0])}") elif len(vec) == 2 or len(vec) == 3: if isinstance(vec[0], numbers.Number) and isinstance( vec[1], numbers.Number): x = vec[0] y = vec[1] if len(vec) == 2: z = 0 else: if isinstance(vec[2], numbers.Number): z = vec[2] else: raise ValueError( f"Unexpected type for creating vector: {type(vec[0])}" ) else: raise ValueError( f"Unexpected type(s) for creating vector: {type(vec[0])}, {type(vec[1])}" ) else: raise ValueError( "Unexpected number of arguments for creating vector") return Vector3.CreateVector3(self.builder, x, y, z)
def __create_vector(self, *vec): import numbers if len(vec) == 1: if isinstance(vec[0], list) or isinstance(vec[0], tuple): if 1 < len(vec[0]) <= 3: if isinstance(vec[0][0], numbers.Number) and isinstance( vec[0][1], numbers.Number): x = vec[0][0] y = vec[0][1] else: raise ValueError( "Unexpected type(s) for creating vector: {0}, {1}". format(type(vec[0][1]), type(vec[0][1]))) if len(vec[0]) == 2: z = 0 else: if isinstance(vec[0][2], numbers.Number): z = vec[0][2] else: raise ValueError( "Unexpected type for creating vector: {0}". format(type(vec[0][2]))) else: raise ValueError( "Unexpected list/tuple length for creating vector: {0}" .format(len(vec))) elif isinstance(vec[0], Vector3.Vector3): x = vec[0].X() y = vec[0].Y() z = vec[0].Z() elif isinstance(vec[0], GameDataStructVector3): x = vec[0].x y = vec[0].y z = vec[0].z else: raise ValueError( "Unexpected type for creating vector: {0}".format( type(vec[0]))) elif len(vec) == 2 or len(vec) == 3: if isinstance(vec[0], numbers.Number) and isinstance( vec[1], numbers.Number): x = vec[0] y = vec[1] if len(vec) == 2: z = 0 else: if isinstance(vec[2], numbers.Number): z = vec[2] else: raise ValueError( "Unexpected type for creating vector: {0}".format( type(vec[0]))) else: raise ValueError( "Unexpected type(s) for creating vector: {0}, {1}".format( type(vec[0]), type(vec[1]))) else: raise ValueError( "Unexpected number of arguments for creating vector") return Vector3.CreateVector3(self.builder, x, y, z)
def copy_v3(self, v3, builder): if self.should_flip_field: return Vector3.CreateVector3(builder, -v3.x, -v3.y, v3.z) return Vector3.CreateVector3(builder, v3.x, v3.y, v3.z)
def copy_v3(self, v3, builder): if self.should_flip_field: return Vector3.CreateVector3(builder, -v3.X(), -v3.Y(), v3.Z()) return Vector3.CreateVector3(builder, v3.X(), v3.Y(), v3.Z())
def __create_vector(self, x, y, z=None): if z is None: z = 0 return Vector3.CreateVector3(self.builder, x, y, z)
def copy_v3(v3, builder): return Vector3.CreateVector3(builder, v3.X(), v3.Y(), v3.Z())
def __create_vector(self, *vec): import numbers if len(vec) == 1: if isinstance(vec[0], list) or isinstance(vec[0], tuple): if 1 < len(vec[0]) <= 3: if isinstance(vec[0][0], numbers.Number) and isinstance( vec[0][1], numbers.Number): x = vec[0][0] y = vec[0][1] else: raise ValueError( "Unexpected type(s) for creating vector: {0}, {1}". format(type(vec[0][0]), type(vec[0][1]))) if len(vec[0]) == 2: z = 0 else: if isinstance(vec[0][2], numbers.Number): z = vec[0][2] else: raise ValueError( "Unexpected type for creating vector: {0}". format(type(vec[0][2]))) else: raise ValueError( "Unexpected list/tuple length for creating vector: {0}" .format(len(vec))) elif isinstance(vec[0], Vector3.Vector3): x = vec[0].X() y = vec[0].Y() z = vec[0].Z() elif isinstance(vec[0], GameDataStructVector3): x = vec[0].x y = vec[0].y z = vec[0].z elif hasattr(vec[0], "__getitem__"): # Support all subscriptable types. try: x = float(vec[0][0]) y = float(vec[0][1]) try: z = float(vec[0][2]) except (ValueError, IndexError): z = 0 except ValueError: raise ValueError( "Unexpected type(s) for creating vector: {0}, {1}, {2}" .format(type(vec[0][0]), type(vec[0][1]), type(vec[0][2]))) except IndexError: raise IndexError( "Unexpected IndexError when creating vector from type: {0}" .format(type(vec[0]))) else: raise ValueError( "Unexpected type for creating vector: {0}".format( type(vec[0]))) elif len(vec) == 2 or len(vec) == 3: if isinstance(vec[0], numbers.Number) and isinstance( vec[1], numbers.Number): x = vec[0] y = vec[1] if len(vec) == 2: z = 0 else: if isinstance(vec[2], numbers.Number): z = vec[2] else: raise ValueError( "Unexpected type for creating vector: {0}".format( type(vec[0]))) else: raise ValueError( "Unexpected type(s) for creating vector: {0}, {1}".format( type(vec[0]), type(vec[1]))) else: raise ValueError( "Unexpected number of arguments for creating vector") return Vector3.CreateVector3(self.builder, x, y, z)