Skip to content
This repository has been archived by the owner on Dec 26, 2018. It is now read-only.

[3.0] 0: XML scene graph

Yuya Matsuo edited this page Sep 29, 2016 · 9 revisions

Meganekko uses XML to define VR scene. Here is example:

<scene>

    <entity geometry="primitive: globe"
            surface="renderer: @drawable/background"
            id="background"/>

    <entity geometry="primitive: plane; width: 1.6; height: 0.9;"
            surface="renderer: @layout/my_view"
            position="0 0 -5"/>

    <entity geometry="primitive: plane; width: 1; height: 1;"
            surface="renderer: com.my.company.CustomRenderer"
            position="5 1 1"
            scale="1.5 1.25 1"
            rotation="0 -45 0"/>

    <!-- Entities can be nested -->
    <entity position="-5 2 -5"
            id="container">

        <!-- Use view element to render View -->
        <view src="@layout/my_view"/>
        <view src="@layout/my_view" position="0 -1 0"/>

    </entity>

    <!-- Entities in camera are fixed on viewport -->
    <camera>

        <!-- Use img element to render image -->
        <img src="@drawable/cursor"/>

    </camera>
</scene>

Entity & Component

Meganekko (above 3.0.0) is based on an entity-component-system pattern (ECS), a pattern common in game development that emphasizes composability over inheritance:

  • An Entity is a general-purpose object that inherently does and renders nothing.
  • A Component is a reusable module that is plugged into entities in order to provide appearance, behavior, and/or functionality. They are plug-and-play for objects.

ECS lets us build complex entities with rich behavior by plugging different reusable components into the sockets on the entity. Contrast this to traditional inheritance where if we want to extend an object, we would have to manually create a new class to do so.

Components are represented as XML attributes such as geometry, surface.

See also Entity and Component (javadoc)

Primitive

There are some XML elements in Meganekko. These are <entity>, <scene>, <camera>, <img> and <view>. These are called as primitive. (Inspired by a-frame)

<entity>

<entity> is most basic primitive. This creates empty Entity.

<entity geometry="primitive: plane; width: 1.6; height: 0.9;"
        surface="renderer: @layout/my_view" />

Above XML will create Entity which has:

  • Plane geometry which has 1.6 width and 0.9 height.
  • Surface renderer (texture) which draw a View inflated from @layout/my_view.

<scene>

A scene is represented by the <scene> element. The scene is the global root object, and all entities are contained within the scene. Typically, Meganekko scene-graph has <scene> as a root element.

The scene inherits from the Entity class so it inherits all of its properties, its methods, the ability to attach components.

<camera>

Creates Entity which has CameraComponent. This element's children are shown on fixed position because CameraComponent rotates Entity to match to head tracking.

<img>

Creates Entity which renders image on plane geometry. Plane size is calculated by width = image.width * 0.01 and height = image.height * 0.01.

<view>

Creates Entity which renders View on plane geometry. Plane size is calculated by width = view.width * 0.01 and height = view.height * 0.01.

Attributes

Attribute Description
geometry Attach geometry to Entity.
surface Describes how to draw Entity's surface.
visible Set Entity's visibility. If set to false, entity and its children are also not to be rendered. Default is true.
opacity Set Entity's opacity. Opacity is affected entity and its children. Default is 1.0
position Set Entity's position. Valid value is 3 floats separated by space. Example: 0 0 -5, 1.2 1.3 -7.0. Default is 0 0 0.
scale Set Entity's scale. Valid value is 3 floats separated by space. Example: 1.1 1 1, 1.5 1.5 1.5. Default is 1 1 1.
rotation Set Entity's rotation. Valid value is 3 floats separated by space and following rotation order. Example: 45 0 0 XYZ, 0 90 45 YXZ, 30 45 45 ZYX. Rotation order is optional. If omitted, XYZ is used. Default is 0 0 0.
component Attach custom Components. Specify full class names separated by space. Note: From 3.0.8