Ejemplo n.º 1
0
class Utils:
    _instance = None

    _texture = core.texture("checker", 512, 512, core.GL_RGB)
    _texture.setCheckeredImage(0, 1, 0)
    shader = core.shaderGenerator()
    shader.setColorTexture(True)
    shader.setNumDirLamp(1)
    shader.setBoneCondition(1, 100)
    _efig = core.editableFigure('bullet')
    _efig.addMaterial("mate", shader)

    def __init__(self):
        None

    def __new__(cls):
        if cls._instance is None:
            cls._instance = super().__new__(cls)
        return cls._instance

    def AddShapeMesh(self, shape: igeBullet.shape):

        meshName = "mesh{}".format(self._efig.numMeshes)
        jointName = "joint{}".format(self._efig.numMeshes)

        pos, nom, uv, idx = shape.getMeshData()
        numElem = len(pos) // 3
        idces = ((self._efig.numMeshes, 0, 0, 0), ) * numElem

        self._efig.addMesh(meshName, "mate")
        self._efig.setVertexElements(meshName, core.ATTRIBUTE_ID_POSITION, pos)
        self._efig.setVertexElements(meshName, core.ATTRIBUTE_ID_NORMAL, nom)
        self._efig.setVertexElements(meshName, core.ATTRIBUTE_ID_UV0, uv)
        self._efig.setVertexElements(meshName, core.ATTRIBUTE_ID_BLENDINDICES,
                                     idces)
        self._efig.setTriangles(meshName, idx)
        self._efig.setMaterialParam("mate", "DiffuseColor",
                                    (1.0, 1.0, 1.0, 1.0))
        self._efig.setMaterialParamTexture("mate",
                                           "ColorSampler",
                                           self._texture,
                                           wrap_s=core.SAMPLERSTATE_BORDER,
                                           wrap_t=core.SAMPLERSTATE_BORDER,
                                           minfilter=core.SAMPLERSTATE_LINEAR,
                                           magfilter=core.SAMPLERSTATE_LINEAR)
        self._efig.addJoint(jointName)

    def GetFigure(self):
        return self._efig

    def Update(self, world):
        for i in range(world.getNumCollisionObjects()):
            body = world.getRigidBody(i)
            self._efig.setJoint(i,
                                position=body.position,
                                rotation=body.rotation)
Ejemplo n.º 2
0
class Utils:
    _instance = None

    _texture = core.texture("checker", 512, 512, core.GL_RGB)
    _texture.setCheckeredImage(0, 1, 0)
    shader = core.shaderGenerator()
    shader.setColorTexture(True)
    shader.setNumDirLamp(1)
    shader.setAmbientType(core.AMBIENT_TYPE_AMBIENT)
    shader.setBoneCondition(1, 100)
    _efig = core.editableFigure('bullet')
    _efig.addMaterial("mate", shader)

    def __init__(self):
        None

    def __new__(cls):
        if cls._instance is None:
            cls._instance = super().__new__(cls)
        return cls._instance

    def AddShapeMesh(self, shape: igeBullet.shape):

        meshName = "mesh{}".format(self._efig.numMeshes)
        jointName = "joint{}".format(self._efig.numMeshes)

        pos, nom, uv, idx = shape.getMeshData()
        numElem = len(pos) // 3
        idces = ((self._efig.numMeshes, 0, 0, 0), ) * numElem

        self._efig.addMesh(meshName, "mate")
        self._efig.setVertexElements(meshName, core.ATTRIBUTE_ID_POSITION, pos)
        self._efig.setVertexElements(meshName, core.ATTRIBUTE_ID_NORMAL, nom)
        self._efig.setVertexElements(meshName, core.ATTRIBUTE_ID_UV0, uv)
        self._efig.setVertexElements(meshName, core.ATTRIBUTE_ID_BLENDINDICES,
                                     idces)
        self._efig.setTriangles(meshName, idx)
        self._efig.setMaterialParam("mate", "DiffuseColor",
                                    (1.0, 1.0, 1.0, 1.0))
        self._efig.setMaterialParamTexture("mate",
                                           "ColorSampler",
                                           self._texture,
                                           wrap_s=core.SAMPLERSTATE_BORDER,
                                           wrap_t=core.SAMPLERSTATE_BORDER,
                                           minfilter=core.SAMPLERSTATE_LINEAR,
                                           magfilter=core.SAMPLERSTATE_LINEAR)
        self._efig.setMaterialRenderState("mate", "cull_face_enable", False)
        self._efig.addJoint(jointName)

    def UpdateShapeMesh(self, shape: igeBullet.shape, meshNo):
        pos, _, _, _ = shape.getMeshData()
        self._efig.setVertexElements(meshNo, core.ATTRIBUTE_ID_POSITION, pos)

    def GetFigure(self):
        return self._efig
Ejemplo n.º 3
0
def f_texture_loader(name, type):
    print('f_texture_loader - ' + name)
    tex = core.texture(name)
    textures[name] = tex
    return (tex.width, tex.height, tex.id, tex.numMips > 1)
Ejemplo n.º 4
0
controller = Controller()

ground = graphicsHelper.createSprite(20.0,
                                     20.0,
                                     texture='images/Dirt-2290',
                                     normal=(0, 1, 0))
#add shadow shader
for i in range(ground.numMaterials):
    shaderGen = ground.getShaderGenerator(i)
    shaderGen.setShadow(False, True, True)
    ground.setShaderGenerator(i, shaderGen)

#create shadow buffer
shadowBuffer = core.texture('Shadow',
                            1024,
                            1024,
                            format=core.GL_RED,
                            depth=True,
                            float=True)

efig = graphicsHelper.createSprite(100, 100, shadowBuffer)
efig.position = vmath.vec3(-100, 200, 0)

# what you want to draw should be registered in showcase
showcase2D = core.showcase('2dcase')
showcase3D = core.showcase("3dcase")

showcase3D.add(ground)
showcase3D.add(char.figure)

showcase2D.add(efig)
showcase2D.add(controller.frame)
Ejemplo n.º 5
0
# devtool module can not be used in the app
# this process should be completed in advance, not at runtime
devtool.convertAssets('.', '.', core.TARGET_PLATFORM_PC)

# open or resize window (This function is valid only on PC,Ignored in smartphone apps)
core.window(True, 480, 640)

char = Character()
cam = TargetCamera()
controller = Controller()
ground = graphicsHelper.createSprite(20.0,
                                     20.0,
                                     texture='images/Dirt-2290',
                                     normal=(0, 1, 0))

tex = core.texture("offscreen", 256, 256, depth=True)
efig = graphicsHelper.createSprite(100, 100, tex)
efig.position = vmath.vec3(-100, 200, 0)

# what you want to draw should be registered in showcase
showcase2D = core.showcase('2dcase')
showcase3D = core.showcase("3dcase")

showcase3D.add(ground)
showcase3D.add(char.figure)

showcase2D.add(efig)
showcase2D.add(controller.frame)
showcase2D.add(controller.button)

cam2D = core.camera('2dcam')
Ejemplo n.º 6
0
        y = 72 + 24 * idx
        cv2.putText(frame, '{} - {:0.4f}'.format(labels[_id], score), (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0), 1)

    cam_texture.setImage(cv2.resize(cv2.cvtColor(cv2.flip(frame, 0), cv2.COLOR_BGR2RGB), (CAMERA_TEXTURE_SIZE, CAMERA_TEXTURE_SIZE)))

if __name__ == "__main__":
    model_path = 'mobilenet_v1_1.0_224_quant.tflite'
    label_path = 'mobilenet_v1_1.0_224_labels.txt'

    cap = cv2.VideoCapture(0)
    cap.set(cv2.CAP_PROP_FRAME_WIDTH, CAMERA_WIDTH)
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, CAMERA_HEIGHT)
    cap.set(cv2.CAP_PROP_FPS, 30)

    core.window(True, CAMERA_WIDTH, CAMERA_HEIGHT)
    cam_texture = core.texture("camera", CAMERA_TEXTURE_SIZE, CAMERA_TEXTURE_SIZE, format=core.GL_RGB)
    cam_sprite = graphicsHelper.createSprite(CAMERA_WIDTH, CAMERA_HEIGHT, cam_texture)

    camera = core.camera("cam01")
    camera.orthographicProjection = True
    camera.position = (0, 0, 100)

    showcase = core.showcase("showcase01")
    showcase.add(cam_sprite)

    interpreter = load_model(model_path)
    labels = load_labels(label_path)

    input_details = interpreter.get_input_details()

    # Get Width and Height
Ejemplo n.º 7
0
from igeCore.apputil import graphicsHelper
import igeVmath as vmath
import cv2

core.window(True, 480, 640)

showcase = core.showcase("case01")

cam = core.camera('maincam')
cam.position = vmath.vec3(0, 0, 1.5)

capture = cv2.VideoCapture(0)
width = capture.get(3)  # width
height = capture.get(4)  # height

tex = core.texture("photo", int(width), int(height), core.GL_RGB)   #RGB format
efig = graphicsHelper.createSprite(width*0.001, height*0.001, tex)
efig.position = vmath.vec3(-0.15, 0.3, 0)
showcase.add(efig)

while(True):
    core.update()
    ret, frame = capture.read()
    frame = cv2.flip(frame,-1)
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    tex.setImage(frame)

    core.update()
    cam.shoot(showcase)
    core.swap()