소스 검색

Added mesh example

Björn Ritzl 7 달 전
부모
커밋
d1c36600e9

+ 1 - 0
examples/_main/examples.lua

@@ -16,6 +16,7 @@ examples["gui"] = {
 }
 examples["input"] = { "move", "text", "down_duration", "mouse_and_touch" }
 examples["model"] = { { name = "cubemap", nobg = true } }
+examples["mesh"] = { "triangle" }
 examples["material"] = { "vertexcolor", { name = "unlit", nobg = true }, "uvgradient", "noise", { name = "screenspace", nobg = true } }
 examples["particles"] = { "confetti", "particlefx", "modifiers", "fire_and_smoke", "fireworks" }
 examples["sound"] = { "music", "fade_in_out", "panning" }

+ 6 - 0
examples/_main/loader.go

@@ -484,3 +484,9 @@ embedded_components {
   data: "collection: \"/examples/resource/create_atlas/create_atlas.collection\"\n"
   ""
 }
+embedded_components {
+  id: "mesh/triangle"
+  type: "collectionproxy"
+  data: "collection: \"/examples/mesh/triangle/triangle.collection\"\n"
+  ""
+}

+ 6 - 0
examples/mesh/triangle/mesh.fp

@@ -0,0 +1,6 @@
+varying mediump vec4 var_color;
+
+void main()
+{
+	gl_FragColor = var_color;
+}

+ 13 - 0
examples/mesh/triangle/mesh.material

@@ -0,0 +1,13 @@
+name: "mesh"
+tags: "model"
+vertex_program: "/examples/mesh/triangle/mesh.vp"
+fragment_program: "/examples/mesh/triangle/mesh.fp"
+vertex_space: VERTEX_SPACE_LOCAL
+vertex_constants {
+  name: "mtx_proj"
+  type: CONSTANT_TYPE_PROJECTION
+}
+vertex_constants {
+  name: "mtx_worldview"
+  type: CONSTANT_TYPE_WORLDVIEW
+}

+ 13 - 0
examples/mesh/triangle/mesh.vp

@@ -0,0 +1,13 @@
+uniform mediump mat4 mtx_worldview;
+uniform mediump mat4 mtx_proj;
+
+attribute mediump vec4 position;
+attribute mediump vec4 color0;
+
+varying mediump vec4 var_color;
+
+void main()
+{
+	gl_Position = mtx_proj * mtx_worldview * vec4(position.xyz, 1.0);
+	var_color = color0;
+}

+ 22 - 0
examples/mesh/triangle/triangle.buffer

@@ -0,0 +1,22 @@
+[
+    {
+        "name": "position",
+        "type": "float32",
+        "count": 3,
+        "data": [
+            -0.5, -0.5, 0,
+            0.5, -0.5, 0,
+            0.0, 0.5, 0
+        ]
+    },
+    {
+        "name": "color0",
+        "type": "float32",
+        "count": 4,
+        "data": [
+            0, 1, 0, 1,
+            1, 0, 0, 1,
+            0, 0, 1, 1
+        ]
+    }
+]

+ 25 - 0
examples/mesh/triangle/triangle.collection

@@ -0,0 +1,25 @@
+name: "triangle"
+scale_along_z: 0
+embedded_instances {
+  id: "go"
+  data: "embedded_components {\n"
+  "  id: \"mesh\"\n"
+  "  type: \"mesh\"\n"
+  "  data: \"material: \\\"/examples/mesh/triangle/mesh.material\\\"\\n"
+  "vertices: \\\"/examples/mesh/triangle/triangle.buffer\\\"\\n"
+  "textures: \\\"/assets/images/logo.png\\\"\\n"
+  "position_stream: \\\"position\\\"\\n"
+  "normal_stream: \\\"position\\\"\\n"
+  "\"\n"
+  "}\n"
+  ""
+  position {
+    x: 360.0
+    y: 360.0
+  }
+  scale3 {
+    x: 100.0
+    y: 100.0
+    z: 100.0
+  }
+}

+ 32 - 0
examples/mesh/triangle/triangle.md

@@ -0,0 +1,32 @@
+---
+title: Mesh
+brief: This example shows how to create a basic mesh component in the shape of a triangle.
+scripts: mesh.fp, mesh.vp
+---
+
+This example contains a game object with a mesh component in the shape of a triangle. The triangle is defined in `triangle.buffer` as the three points of the triangle in the `position` stream. The triangle also defines the colors at each point. The colors get mixed automatically when the triangle is drawn by the shader.
+
+```
+[
+    {
+        "name": "position",
+        "type": "float32",
+        "count": 3,
+        "data": [
+            -0.5, -0.5, 0,
+            0.5, -0.5, 0,
+            0.0, 0.5, 0
+        ]
+    },
+    {
+        "name": "color0",
+        "type": "float32",
+        "count": 4,
+        "data": [
+            0, 1, 0, 1,
+            1, 0, 0, 1,
+            0, 0, 1, 1
+        ]
+    }
+]
+```