Esempio n. 1
0
def _createBox(proxy, size, colour, moiScale, withMesh):
    """
    Private function.
    Use createBox() or createArticulatedBox() instead.
    """

    # Mesh and cdps will be set manually
    proxy.meshes = None
    proxy.cdps = None

    # Compute box moi
    size = PyUtils.toVector3d(size)
    proxy.moi = MathLib.Vector3d(
        size.y * size.y + size.z * size.z,
        size.x * size.x + size.z * size.z,
        size.x * size.x + size.y * size.y,
    ) * 1.0 / 12.0 * proxy.mass * moiScale

    box = proxy.createAndFillObject()

    cdp = Physics.BoxCDP()
    halfSize = PyUtils.toVector3d(size) * 0.5

    cdp.setPoint1(MathLib.Point3d(halfSize * -1))
    cdp.setPoint2(MathLib.Point3d(halfSize))

    box.addCollisionDetectionPrimitive(cdp)

    if withMesh:
        mesh = Mesh.createBox(size=size, colour=colour)
        box.addMesh(mesh)

    return box
Esempio n. 2
0
def _createEllipsoid(proxy, radius, colour, moiScale, withMesh):
    """
    Private function.
    Use createEllipsoid() or createArticulatedEllipsoid() instead.
    """
    # Mesh and cdps will be set manually
    proxy.meshes = None
    proxy.cdps = None

    # Compute box moi
    moi = [0, 0, 0]
    for i in range(3):
        j = (i + 1) % 3
        k = (i + 2) % 3
        moi[i] = proxy.mass * (radius[j] * radius[j] +
                               radius[k] * radius[k]) / 5.0
    proxy.moi = PyUtils.toVector3d(moi) * moiScale

    ellipsoid = proxy.createAndFillObject()

    cdp = Physics.SphereCDP()
    cdp.setCenter(Point3d(0, 0, 0))
    cdp.setRadius(min(radius))

    ellipsoid.addCollisionDetectionPrimitive(cdp)

    if withMesh:
        mesh = Mesh.createEllipsoid((0, 0, 0), radius, colour)
        ellipsoid.addMesh(mesh)

    return ellipsoid
Esempio n. 3
0
def createBox(size=(1, 1, 1), position=(0, 0, 0), colour=(0.6, 0.6, 0.6)):
    """
    Creates the mesh for a box having the specified size and a specified position.
    The size should be a 3-tuple (xSize, ySize, zSize).
    The position should be a 3-tuple.
    Colour should be a 3-tuple (R,G,B) or a 4-tuple (R,G,B,A)
    """

    size = PyUtils.toVector3d(size)
    position = PyUtils.toPoint3d(position)
    vertices = []
    delta = MathLib.Vector3d()
    for repeat in range(3):
        for x in (-0.5, 0.5):
            delta.x = size.x * x
            for y in (-0.5, 0.5):
                delta.y = size.y * y
                for z in (-0.5, 0.5):
                    delta.z = size.z * z
                    vertices.append(position + delta)

    faces = [
        (0, 1, 3, 2),
        (5, 4, 6, 7),  # YZ Faces
        (9, 13, 15, 11),
        (12, 8, 10, 14),  # XY Faces
        (18, 19, 23, 22),
        (17, 16, 20, 21)
    ]  # XZ Faces

    return create(vertices, faces, colour)
Esempio n. 4
0
def _createEllipsoid(proxy, radius, colour, moiScale, withMesh):
    """
    Private function.
    Use createEllipsoid() or createArticulatedEllipsoid() instead.
    """
    # Mesh and cdps will be set manually
    proxy.meshes = None
    proxy.cdps = None

    # Compute box moi
    moi = [0, 0, 0]
    for i in range(3):
        j = (i + 1) % 3
        k = (i + 2) % 3
        moi[i] = proxy.mass * (radius[j] * radius[j] + radius[k] * radius[k]) / 5.0
    proxy.moi = PyUtils.toVector3d(moi) * moiScale

    ellipsoid = proxy.createAndFillObject()

    cdp = Physics.SphereCDP()
    cdp.setCenter(Point3d(0, 0, 0))
    cdp.setRadius(min(radius))

    ellipsoid.addCollisionDetectionPrimitive(cdp)

    if withMesh:
        mesh = Mesh.createEllipsoid((0, 0, 0), radius, colour)
        ellipsoid.addMesh(mesh)

    return ellipsoid
def createBox( size=(1,1,1), position=(0,0,0), colour=(0.6,0.6,0.6) ):
    """
    Creates the mesh for a box having the specified size and a specified position.
    The size should be a 3-tuple (xSize, ySize, zSize).
    The position should be a 3-tuple.
    Colour should be a 3-tuple (R,G,B) or a 4-tuple (R,G,B,A)
    """
    
    size     = PyUtils.toVector3d(size)
    position = PyUtils.toPoint3d(position)
    vertices = []
    delta = MathLib.Vector3d()
    for repeat in range(3):
        for x in (-0.5,0.5) :
            delta.x = size.x * x
            for y in (-0.5,0.5) :
                delta.y = size.y * y
                for z in (-0.5,0.5) :
                    delta.z = size.z * z
                    vertices.append( position + delta )
    
    faces = [(0,1,3,2),(5,4,6,7),  # YZ Faces
             (9,13,15,11),(12,8,10,14),  # XY Faces
             (18,19,23,22),(17,16,20,21)]  # XZ Faces
    
    return create( vertices, faces, colour )
Esempio n. 6
0
def _createCylinder(proxy, axis, basePos, tipPos, radius, colour, moiScale,
                    withMesh):
    """
    Private function.
    Use createCylinder() or createArticulatedCylinder() instead.
    """
    if axis != 0 and axis != 1 and axis != 2:
        raise ValueError('Axis must be 0 for x, 1 for y or 2 for z.')

    # Mesh and cdps will be set manually
    proxy.meshes = None
    proxy.cdps = None

    # Compute box moi
    moi = [0, 0, 0]
    height = math.fabs(tipPos - basePos)
    for i in range(3):
        if i == axis:
            moi[i] = proxy.mass * radius * radius / 2.0
        else:
            moi[i] = proxy.mass * (3 * radius * radius +
                                   height * height) / 12.0
        ### HACK!
        moi[i] = max(moi[i], 0.01)
    proxy.moi = PyUtils.toVector3d(moi) * moiScale

    cylinder = proxy.createAndFillObject()

    basePoint = [0, 0, 0]
    tipPoint = [0, 0, 0]
    basePoint[axis] = basePos
    tipPoint[axis] = tipPos
    basePoint3d = PyUtils.toPoint3d(basePoint)
    tipPoint3d = PyUtils.toPoint3d(tipPoint)
    baseToTipVector3d = Vector3d(basePoint3d, tipPoint3d)
    if baseToTipVector3d.isZeroVector():
        raise ValueError(
            'Invalid points for cylinder: base and tip are equal!')
    baseToTipUnitVector3d = baseToTipVector3d.unit()

    if height <= radius * 2.0:
        cdp = Physics.SphereCDP()
        cdp.setCenter(basePoint3d + baseToTipVector3d * 0.5)
        cdp.setRadius(height / 2.0)
    else:
        cdp = Physics.CapsuleCDP()
        cdp.setPoint1(basePoint3d + baseToTipUnitVector3d * radius)
        cdp.setPoint2(tipPoint3d + baseToTipUnitVector3d * -radius)
        cdp.setRadius(radius)

    cylinder.addCollisionDetectionPrimitive(cdp)

    if withMesh:
        mesh = Mesh.createCylinder(basePoint, tipPoint, radius, colour)
        cylinder.addMesh(mesh)

    return cylinder
Esempio n. 7
0
def _createCylinder(proxy, axis, basePos, tipPos, radius, colour, moiScale, withMesh):
    """
    Private function.
    Use createCylinder() or createArticulatedCylinder() instead.
    """
    if axis != 0 and axis != 1 and axis != 2:
        raise ValueError("Axis must be 0 for x, 1 for y or 2 for z.")

    # Mesh and cdps will be set manually
    proxy.meshes = None
    proxy.cdps = None

    # Compute box moi
    moi = [0, 0, 0]
    height = math.fabs(tipPos - basePos)
    for i in range(3):
        if i == axis:
            moi[i] = proxy.mass * radius * radius / 2.0
        else:
            moi[i] = proxy.mass * (3 * radius * radius + height * height) / 12.0
        ### HACK!
        moi[i] = max(moi[i], 0.01)
    proxy.moi = PyUtils.toVector3d(moi) * moiScale

    cylinder = proxy.createAndFillObject()

    basePoint = [0, 0, 0]
    tipPoint = [0, 0, 0]
    basePoint[axis] = basePos
    tipPoint[axis] = tipPos
    basePoint3d = PyUtils.toPoint3d(basePoint)
    tipPoint3d = PyUtils.toPoint3d(tipPoint)
    baseToTipVector3d = Vector3d(basePoint3d, tipPoint3d)
    if baseToTipVector3d.isZeroVector():
        raise ValueError("Invalid points for cylinder: base and tip are equal!")
    baseToTipUnitVector3d = baseToTipVector3d.unit()

    if height <= radius * 2.0:
        cdp = Physics.SphereCDP()
        cdp.setCenter(basePoint3d + baseToTipVector3d * 0.5)
        cdp.setRadius(height / 2.0)
    else:
        cdp = Physics.CapsuleCDP()
        cdp.setPoint1(basePoint3d + baseToTipUnitVector3d * radius)
        cdp.setPoint2(tipPoint3d + baseToTipUnitVector3d * -radius)
        cdp.setRadius(radius)

    cylinder.addCollisionDetectionPrimitive(cdp)

    if withMesh:
        mesh = Mesh.createCylinder(basePoint, tipPoint, radius, colour)
        cylinder.addMesh(mesh)

    return cylinder
Esempio n. 8
0
def _createBox(proxy, size, colour, moiScale, withMesh):
    """
    Private function.
    Use createBox() or createArticulatedBox() instead.
    """

    # Mesh and cdps will be set manually
    proxy.meshes = None
    proxy.cdps = None

    # Compute box moi
    size = PyUtils.toVector3d(size)
    proxy.moi = (
        MathLib.Vector3d(
            size.y * size.y + size.z * size.z, size.x * size.x + size.z * size.z, size.x * size.x + size.y * size.y
        )
        * 1.0
        / 12.0
        * proxy.mass
        * moiScale
    )

    box = proxy.createAndFillObject()

    cdp = Physics.BoxCDP()
    halfSize = PyUtils.toVector3d(size) * 0.5

    cdp.setPoint1(MathLib.Point3d(halfSize * -1))
    cdp.setPoint2(MathLib.Point3d(halfSize))

    box.addCollisionDetectionPrimitive(cdp)

    if withMesh:
        mesh = Mesh.createBox(size=size, colour=colour)
        box.addMesh(mesh)

    return box
 def interpret(self, value):
     value = self.basicInterpret(value)
     if isinstance(value, MathLib.Vector3d) : return value
     else : return PyUtils.toVector3d( value )
Esempio n. 10
0
 def interpret(self, value):
     value = self.basicInterpret(value)
     if isinstance(value, MathLib.Vector3d): return value
     else: return PyUtils.toVector3d(value)