Exemplo n.º 1
0
from igeCore import devtool
devtool.convertAssets('.', '.', core.TARGET_PLATFORM_ANDROID, 0.1)

core.window(True, 480, 640)

shader = core.shaderGenerator()
shader.setColorTexture(True)  #use color texture
shader.setDistortion(True)  #add distortion effect
shader.setUVScroll(1, True)  #start uv scroll at uv channel 1
shader.setNormalTextureUVSet(1, 1)  #change normal texture uv channel to 1
shader.setProjectionMapping(1, True)  #projection mapping mode at uv channel 1

print(shader)  #print shader program

shadowSprite = graphicsHelper.createSprite(200, 200, "fire", shader=shader)

#set uv scroll speed for uv set 1
shadowSprite.setMaterialParam("mate", "ScrollSpeedSet1", (0.0, -0.08))

#set distortion strength
shadowSprite.setMaterialParam("mate", "DistortionStrength", (0.02, ))

#set normal texture for distortion
shadowSprite.setMaterialParamTexture("mate",
                                     "NormalSampler",
                                     "NormalMap",
                                     wrap_s=core.SAMPLERSTATE_WRAP,
                                     wrap_t=core.SAMPLERSTATE_WRAP,
                                     minfilter=core.SAMPLERSTATE_LINEAR,
                                     magfilter=core.SAMPLERSTATE_LINEAR)
Exemplo n.º 2
0
from igeCore import devtool
from igeCore.apputil import graphicsHelper
import igeVmath as vmath
import os.path

# convert png to the format suitable for the platform (ship.png -> ship.pyxi)
# devtool module can not be used in the app
# this process should be completed in advance, not at runtime
if not os.path.exists('ship.pyxi'):
    devtool.convertTextureToPlatform('ship.png', 'ship',
                                     core.TARGET_PLATFORM_PC, False, False)

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

ship = graphicsHelper.createSprite(100, 100, "ship")

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

# what you want to draw should be registered in showcase
showcase = core.showcase("case01")
showcase.add(ship)

goal = vmath.vec2(0, 0)
pos = vmath.vec2(0, 0)
dir = vmath.vec2(0, 1)

loop = True
while loop:
Exemplo n.º 3
0
 def __init__(self):
     self.frame = graphicsHelper.createSprite(50, 50, 'images/ctrl01')
     self.button = graphicsHelper.createSprite(50, 50, 'images/ctrl02')
Exemplo n.º 4
0
    def __init__(self):
        if USE_IGE_CORE:
            core.window(True, 540, 960)
            input.registerEventListener(self.on_event)

            super(TestApp, self).__init__()
            super(TestApp, self).initialize(core.getWindow(), False)
        else:
            super(TestApp, self).__init__((540, 960), "NanoGUI")

        window = Window(self, "Button demo")
        window.set_position((15, 15))
        window.set_layout(GroupLayout())

        Label(window, "Push buttons", "sans-bold")
        b = Button(window, "Plain button")

        def cb():
            print("pushed!")

        b.set_callback(cb)

        b = Button(window, "Styled", icons.FA_ROCKET)
        b.set_background_color(Color(0, 0, 1.0, 0.1))
        b.set_callback(cb)

        Label(window, "Toggle buttons", "sans-bold")
        b = Button(window, "Toggle me")
        b.set_flags(Button.Flags.ToggleButton)

        def change_cb(state):
            print("Toggle button state: %s" % str(state))

        b.set_change_callback(change_cb)

        Label(window, "Radio buttons", "sans-bold")
        b = Button(window, "Radio button 1")
        b.set_flags(Button.Flags.RadioButton)
        b = Button(window, "Radio button 2")
        b.set_flags(Button.Flags.RadioButton)

        Label(window, "A tool palette", "sans-bold")
        tools = Widget(window)
        tools.set_layout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 6))

        ToolButton(tools, icons.FA_CLOUD)
        ToolButton(tools, icons.FA_FAST_FORWARD)
        ToolButton(tools, icons.FA_COMPASS)
        ToolButton(tools, icons.FA_UTENSILS)

        Label(window, "Popup buttons", "sans-bold")
        popup_btn = PopupButton(window, "Popup", icons.FA_FLASK)
        popup = popup_btn.popup()
        popup.set_layout(GroupLayout())
        Label(popup, "Arbitrary widgets can be placed here")
        CheckBox(popup, "A check box")
        # popup right
        popup_btn = PopupButton(popup, "Recursive popup", icons.FA_CHART_PIE)
        popup_right = popup_btn.popup()
        popup_right.set_layout(GroupLayout())
        CheckBox(popup_right, "Another check box")
        # popup left
        popup_btn = PopupButton(popup, "Recursive popup", icons.FA_DNA)
        popup_btn.set_side(Popup.Side.Left)
        popup_left = popup_btn.popup()
        popup_left.set_layout(GroupLayout())
        CheckBox(popup_left, "Another check box")

        window = Window(self, "Basic widgets")
        window.set_position((200, 15))
        window.set_layout(GroupLayout())

        Label(window, "Message dialog", "sans-bold")
        tools = Widget(window)
        tools.set_layout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 6))

        def cb2(result):
            print("Dialog result: %i" % result)

        b = Button(tools, "Info")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Information, "Title",
                                "This is an information message")
            dlg.set_callback(cb2)

        b.set_callback(cb)

        b = Button(tools, "Warn")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Warning, "Title",
                                "This is a warning message")
            dlg.set_callback(cb2)

        b.set_callback(cb)

        b = Button(tools, "Ask")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Warning, "Title",
                                "This is a question message", "Yes", "No",
                                True)
            dlg.set_callback(cb2)

        b.set_callback(cb)
        icons_data = nanogui.load_image_directory(self.nvg_context(),
                                                  "./resources/icons")

        Label(window, "Image panel & scroll panel", "sans-bold")
        image_panel_btn = PopupButton(window, "Image Panel")
        image_panel_btn.set_icon(icons.FA_IMAGES)
        popup = image_panel_btn.popup()
        vscroll = VScrollPanel(popup)
        img_panel = ImagePanel(vscroll)
        img_panel.set_images(icons_data)
        popup.set_fixed_size((245, 150))

        img_window = Window(self, "Selected image")
        img_window.set_position((710, 15))
        img_window.set_layout(GroupLayout())

        img_view = ImageView(img_window)
        img_view.set_image(
            Texture(icons_data[0][1] + ".png",
                    Texture.InterpolationMode.Trilinear,
                    Texture.InterpolationMode.Nearest))
        img_view.center()

        def cb(i):
            print("Selected item %i" % i)
            img_view.set_image(
                Texture(icons_data[i][1] + ".png",
                        Texture.InterpolationMode.Trilinear,
                        Texture.InterpolationMode.Nearest))

        img_panel.set_callback(cb)

        Label(window, "File dialog", "sans-bold")
        tools = Widget(window)
        tools.set_layout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 6))
        b = Button(tools, "Open")
        valid = [("png", "Portable Network Graphics"), ("txt", "Text file")]

        def cb():
            result = nanogui.file_dialog(valid, False)
            print("File dialog result = %s" % result)

        b.set_callback(cb)
        b = Button(tools, "Save")

        def cb():
            result = nanogui.file_dialog(valid, True)
            print("File dialog result = %s" % result)

        b.set_callback(cb)

        Label(window, "Combo box", "sans-bold")
        ComboBox(window,
                 ["Combo box item 1", "Combo box item 2", "Combo box item 3"])
        Label(window, "Check box", "sans-bold")

        def cb(state):
            print("Check box 1 state: %s" % state)

        chb = CheckBox(window, "Flag 1", cb)
        chb.set_checked(True)

        def cb(state):
            print("Check box 2 state: %s" % state)

        CheckBox(window, "Flag 2", cb)

        Label(window, "Progress bar", "sans-bold")
        self.progress = ProgressBar(window)

        Label(window, "Slider and text box", "sans-bold")

        panel = Widget(window)
        panel.set_layout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 20))

        slider = Slider(panel)
        slider.set_value(0.5)
        slider.set_fixed_width(80)

        text_box = TextBox(panel)
        text_box.set_fixed_size((60, 25))
        text_box.set_value("50")
        text_box.set_units("%")
        text_box.set_font_size(20)
        text_box.set_alignment(TextBox.Alignment.Right)

        def cb(value):
            text_box.set_value("%i" % int(value * 100))

        slider.set_callback(cb)

        def cb(value):
            print("Final slider value: %i" % int(value * 100))

        slider.set_final_callback(cb)

        window = Window(self, "Misc. widgets")
        window.set_position((425, 15))
        window.set_layout(GroupLayout())

        tab_widget = TabWidget(window)
        layer = Widget(tab_widget)
        layer.set_layout(GroupLayout())
        tab_widget.append_tab("Color Wheel", layer)

        Label(layer, "Color wheel widget", "sans-bold")
        ColorWheel(layer)

        layer = Widget(tab_widget)
        layer.set_layout(GroupLayout())
        tab_widget.append_tab("Function Graph", layer)
        Label(layer, "Function graph widget", "sans-bold")

        graph = Graph(layer, "Some function")
        graph.set_header("E = 2.35e-3")
        graph.set_footer("Iteration 89")
        values = [
            0.5 * (0.5 * math.sin(i / 10.0) + 0.5 * math.cos(i / 23.0) + 1)
            for i in range(100)
        ]
        graph.set_values(values)

        plus_id = tab_widget.append_tab("+", Widget(tab_widget))

        def tab_cb(index):
            if index == plus_id:
                global counter
                # When the "+" tab has been clicked, simply add a new tab.
                tab_name = "Dynamic {0}".format(counter)
                layer_dyn = Widget(tab_widget)
                layer_dyn.set_layout(GroupLayout())
                new_id = tab_widget.insert_tab(tab_widget.tab_count() - 1,
                                               tab_name, layer_dyn)
                Label(layer_dyn, "Function graph widget", "sans-bold")
                graph_dyn = Graph(layer_dyn, "Dynamic function")

                graph_dyn.set_header("E = 2.35e-3")
                graph_dyn.set_footer("Iteration {0}".format(index * counter))
                values_dyn = [
                    0.5 * abs((0.5 * math.sin(i / 10.0 + counter)) +
                              (0.5 * math.cos(i / 23.0 + 1 + counter)))
                    for i in range(100)
                ]
                graph_dyn.set_values(values_dyn)
                counter += 1
                # We must invoke the layout manager after adding tabs dynamically
                self.perform_layout()
                tab_widget.set_selected_id(new_id)

        tab_widget.set_callback(tab_cb)

        window = Window(self, "Grid of small widgets")
        window.set_position((425, 300))
        layout = GridLayout(Orientation.Horizontal, 2, Alignment.Middle, 15, 5)
        layout.set_col_alignment([Alignment.Maximum, Alignment.Fill])
        layout.set_spacing(0, 10)
        window.set_layout(layout)

        Label(window, "Floating point :", "sans-bold")
        float_box = TextBox(window)
        float_box.set_editable(True)
        float_box.set_fixed_size((100, 20))
        float_box.set_value("50")
        float_box.set_units("GiB")
        float_box.set_default_value("0.0")
        float_box.set_font_size(16)
        float_box.set_format("[-]?[0-9]*\\.?[0-9]+")

        Label(window, "Positive integer :", "sans-bold")
        int_box = IntBox(window)
        int_box.set_editable(True)
        int_box.set_fixed_size((100, 20))
        int_box.set_value(50)
        int_box.set_units("Mhz")
        int_box.set_default_value("0")
        int_box.set_font_size(16)
        int_box.set_format("[1-9][0-9]*")
        int_box.set_spinnable(True)
        int_box.set_min_value(1)
        int_box.set_value_increment(2)

        Label(window, "Checkbox :", "sans-bold")

        cb = CheckBox(window, "Check me")
        cb.set_font_size(16)
        cb.set_checked(True)

        Label(window, "Combo box :", "sans-bold")
        cobo = ComboBox(window, ["Item 1", "Item 2", "Item 3"])
        cobo.set_font_size(16)
        cobo.set_fixed_size((100, 20))

        Label(window, "Color picker :", "sans-bold")
        cp = ColorPicker(window, Color(255, 120, 0, 255))
        cp.set_fixed_size((100, 20))

        def cp_final_cb(color):
            print("ColorPicker Final Callback: [{0}, {1}, {2}, {3}]".format(
                color.r, color.g, color.b, color.w))

        cp.set_final_callback(cp_final_cb)

        window = Window(self, "Color Picker Fast Callback")
        window.set_position((425, 300))
        layout = GridLayout(Orientation.Horizontal, 2, Alignment.Middle, 15, 5)
        layout.set_col_alignment([Alignment.Maximum, Alignment.Fill])
        layout.set_spacing(0, 10)
        window.set_layout(layout)
        window.set_position((425, 500))
        Label(window, "Combined: ")
        b = Button(window, "ColorWheel", icons.FA_INFINITY)
        Label(window, "Red: ")
        red_int_box = IntBox(window)
        red_int_box.set_editable(False)
        Label(window, "Green: ")
        green_int_box = IntBox(window)
        green_int_box.set_editable(False)
        Label(window, "Blue: ")
        blue_int_box = IntBox(window)
        blue_int_box.set_editable(False)
        Label(window, "Alpha: ")
        alpha_int_box = IntBox(window)

        def cp_fast_cb(color):
            b.set_background_color(color)
            b.set_text_color(color.contrasting_color())
            red = int(color.r * 255.0)
            red_int_box.set_value(red)
            green = int(color.g * 255.0)
            green_int_box.set_value(green)
            blue = int(color.b * 255.0)
            blue_int_box.set_value(blue)
            alpha = int(color.w * 255.0)
            alpha_int_box.set_value(alpha)

        cp.set_callback(cp_fast_cb)

        self.perform_layout()

        if USE_IGE_CORE:
            self.ship = graphicsHelper.createSprite(100, 100, "ship")
            self.ship.setMaterialRenderState("mate", "blend_enable", True)

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

            self.showcase = core.showcase("case01")
            self.showcase.add(self.ship)

            self.goal = vmath.vec2(0, 0)
            self.pos = vmath.vec2(0, 0)
            self.dir = vmath.vec2(0, 1)

            input.getKeyboard().registerKeyPressedCallback(self.onKeyPressed)
            input.getTouch().registerTouchBeganCallback(self.onTouchBegan)
Exemplo n.º 5
0
devtool.convertAssets('.', '.', core.TARGET_PLATFORM_MOBILE)
core.window(True, 480, 640)

core.shaderGenerator().globalShadowBias = 0.001

#core.autoSaveShader('shaders')

#The character shadow is specified to be set at the time of conversion by figure.conf.
#See Sapphiart/figure.conf
char = Character()

cam = TargetCamera()
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)
Exemplo n.º 6
0
#The smaller the area, the higher the shadow resolution.
env.shadowWideness = 500.0

env.ambientColor = (0.2, 0.2, 0.2)

showcase = core.showcase("case")
showcase.add(ground, 1.0)
showcase.add(box, 1.0)

showcase.add(env)

#The shadow buffer needs to be set to Showcase
showcase.addShadowBuffer(shadowBuffer)

#For viewing the shadow buffer
shadowSprite = graphicsHelper.createSprite(100, 100, shadowBuffer)
shadowSprite.position = (-100, 0, 0)
cam2D = core.camera("cam2D")
cam2D.position = (0, 0, 100)
cam2D.orthographicProjection = True
showcase2D = core.showcase('case2D')
showcase2D.add(shadowSprite)

rotX = 0
rotY = 0

while True:
    core.update()

    box.step()
    touch = core.singleTouch()
Exemplo n.º 7
0
        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
    input_shape = input_details[0]['shape']
Exemplo n.º 8
0
import os.path
from char import Character
from cam import TargetCamera
from controller import Controller
import igeBullet
from utils import Utils

utl = Utils()

devtool.convertAssets('.', '.', core.TARGET_PLATFORM_PC)
core.window(True, 480, 640)

world = igeBullet.world(True)

ground = graphicsHelper.createSprite(20.0,
                                     20.0,
                                     texture='images/Dirt-2290',
                                     normal=(0, 1, 0))
ground_shape = igeBullet.shape(igeBullet.STATIC_PLANE_PROXYTYPE,
                               normal=(0, 1, 0),
                               constant=0)
ground_body = igeBullet.rigidBody(ground_shape, 0, (0, 0, 0), (0, 0, 0, 1))
world.add(ground_body)

efig = utl.GetFigure()
efig.clearMesh()
shape = igeBullet.shape(igeBullet.SPHERE_SHAPE_PROXYTYPE, radius=1)
body2 = igeBullet.rigidBody(shape, 5, (0, 10, 0), (0, 0, 0, 1))
world.add(body2)
utl.AddShapeMesh(shape)

char = Character(world)
Exemplo n.º 9
0
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()

capture.release()