Ejemplo n.º 1
0
    def generate_coordinates(self, vertices, normals):
        # ignore the normals

        # create an empty texture coord array
        # dot product expects contiguous memory
        # so we have 2xN shape instead of Nx2 shape
        # we reshape after the dot product
        texture_coords = numpy.empty((2, len(vertices)), dtype=float)

        # extract our rows
        tu = texture_coords[0, ...]
        tv = texture_coords[1, ...]

        # take our vertices and flatten them against the plane
        plane_vertices = matrix.apply_direction_scale(vertices,
                                                      self.plane[plane.normal],
                                                      0.0)

        right = vector.cross(self.plane[plane.normal], self.plane[plane.up])

        # get the tu / tv values from our up and right vectors
        numpy.dot(plane_vertices, right, out=tu)
        numpy.dot(plane_vertices, self.plane[plane.up], out=tv)

        # apply our scaling
        tu /= self.size[0]
        tv /= self.size[1]

        # reshape back into our normal Nx2 shape
        texture_coords = numpy.transpose(texture_coords)

        return texture_coords
Ejemplo n.º 2
0
        def apply():
            # squash in the Z direction
            vec = numpy.array( [ 2.0, 1.0, 25.0 ] )
            direction = numpy.array( [ 0.0, 0.0, 1.0 ] )

            result = matrix.apply_direction_scale(
                vec,
                direction,
                0.0
                )

            self.assertTrue(
                numpy.array_equal( result, [ vec[ 0 ], vec[ 1 ], 0.0 ] ),
                "Scale incorrectly applied"
                )
Ejemplo n.º 3
0
 def generate_coordinates( self, vertices, normals ):
     # ignore the normals
     
     # create an empty texture coord array
     # dot product expects contiguous memory
     # so we have 2xN shape instead of Nx2 shape
     # we reshape after the dot product
     texture_coords = numpy.empty( (2, len(vertices)), dtype = float )
     
     # extract our rows
     tu = texture_coords[0,...]
     tv = texture_coords[1,...]
     
     # take our vertices and flatten them against the plane
     plane_vertices = matrix.apply_direction_scale(
         vertices,
         self.plane[ plane.normal ],
         0.0
         )
     
     right = vector.cross(
         self.plane[ plane.normal ],
         self.plane[ plane.up ]
         )
     
     # get the tu / tv values from our up and right vectors
     numpy.dot(
         plane_vertices,
         right,
         out = tu
         )
     numpy.dot(
         plane_vertices,
         self.plane[ plane.up ],
         out = tv
         )
     
     # apply our scaling
     tu /= self.size[ 0 ]
     tv /= self.size[ 1 ]
     
     # reshape back into our normal Nx2 shape
     texture_coords = numpy.transpose( texture_coords )
     
     return texture_coords
Ejemplo n.º 4
0
        def batch_apply():
            vecs = numpy.array(
                [
                    [ 0.0, 0.0, 0.0 ],
                    [ 0.0, 0.0, 1.0 ],
                    [ 1.0, 1.0, 1.0 ],
                    [ 2.0, 1.0, 25.0 ]
                    ]
                )
            direction = numpy.array( [ 0.0, 0.0, 1.0 ] )

            result = matrix.apply_direction_scale( vecs, direction, 0.0 )

            expected = numpy.array( vecs )
            expected[ :,-1 ] = 0.0

            self.assertTrue(
                numpy.array_equal( result, expected ),
                "Batch scale incorrectly applied"
                )