Selaa lähdekoodia

Merge pull request #40 from rsredsq/master

Moved Triangle component into separate file
JoshEngebretson 10 vuotta sitten
vanhempi
sitoutus
ed9014ef0e

+ 28 - 0
CustomGeometry/Resources/Components/Triangle.js

@@ -0,0 +1,28 @@
+'atomic component';
+
+//Triangle component
+exports.component = function(self) {
+    self.start = function() {
+        //Create a CustomGeometry component
+        var customGeometry = self.node.createComponent("CustomGeometry");
+
+        //Set it material to VColUnlit
+        customGeometry.setMaterial(Atomic.cache.getResource("Material", "Materials/VColUnlit.xml"));
+
+        //Begin geometry, set index to 0, and TRIANGLE_LIST mode
+        customGeometry.beginGeometry(0, Atomic.TRIANGLE_LIST);
+
+        //Define a vertex and a color for that
+        customGeometry.defineVertex([0.0, 0.5, 0.0]); //Vertex 1
+        customGeometry.defineColor([1.0, 0.0, 0.0]);
+
+        customGeometry.defineVertex([0.5, -0.5, 0.0]); //Vertex 2
+        customGeometry.defineColor([0.0, 1.0, 0.0]);
+
+        customGeometry.defineVertex([-0.5, -0.5, 0.0]); //Vertex 3
+        customGeometry.defineColor([0.0, 0.0, 1.0]);
+
+        //Save changes
+        customGeometry.commit();
+    }
+}

+ 7 - 0
CustomGeometry/Resources/Components/Triangle.js.asset

@@ -0,0 +1,7 @@
+{
+	"version": 1,
+	"guid": "90df5b2f3313f6cf29c72e83ee906c91",
+	"JavascriptImporter": {
+		"IsComponentFile": true
+	}
+}

+ 16 - 2
CustomGeometry/Resources/Scenes/Scene.scene

@@ -5,8 +5,8 @@
 	<attribute name="Smoothing Constant" value="50" />
 	<attribute name="Snap Threshold" value="5" />
 	<attribute name="Elapsed Time" value="0" />
-	<attribute name="Next Replicated Node ID" value="367" />
-	<attribute name="Next Replicated Component ID" value="1982" />
+	<attribute name="Next Replicated Node ID" value="369" />
+	<attribute name="Next Replicated Component ID" value="1986" />
 	<attribute name="Next Local Node ID" value="16778496" />
 	<attribute name="Next Local Component ID" value="16777216" />
 	<attribute name="Variables" />
@@ -25,4 +25,18 @@
 			<attribute name="Orthographic Size" value="1" />
 		</component>
 	</node>
+	<node id="368">
+		<attribute name="Is Enabled" value="true" />
+		<attribute name="Name" value="Triangle" />
+		<attribute name="Position" value="0 0 0" />
+		<attribute name="Rotation" value="1 0 0 0" />
+		<attribute name="Scale" value="1 1 1" />
+		<attribute name="Variables" />
+		<component type="JSComponent" id="1984">
+			<attribute name="ComponentFile" value="JSComponentFile;Components/Triangle.js" />
+		</component>
+		<component type="JSComponent" id="1985">
+			<attribute name="ComponentFile" value="JSComponentFile;Components/Spinner.js" />
+		</component>
+	</node>
 </scene>

+ 2 - 21
CustomGeometry/Resources/Scripts/main.js

@@ -1,21 +1,2 @@
-//Create a new scene
-var scene = Atomic.player.loadScene("Scenes/Scene.scene");
-//Create a Triangle node
-var triangle = scene.createChild("Triangle");
-//Create CustomGeometry component
-var customGeometry = triangle.createComponent("CustomGeometry");
-//Set its material VColUnlit
-customGeometry.setMaterial(Atomic.cache.getResource("Material", "Materials/VColUnlit.xml"));
-//Begin geometry, set index to 0, and TRIANGLE_LIST mode
-customGeometry.beginGeometry(0, Atomic.TRIANGLE_LIST);
-//Define a vertex and a color for that
-customGeometry.defineVertex([0.0, 0.5, 0.0]); //Vertex 1
-customGeometry.defineColor([1.0, 0.0, 0.0]);
-customGeometry.defineVertex([0.5, -0.5, 0.0]); //Vertex 2
-customGeometry.defineColor([0.0, 1.0, 0.0]);
-customGeometry.defineVertex([-0.5, -0.5, 0.0]);//Vertex 3
-customGeometry.defineColor([0.0, 0.0, 1.0]);
-//Save changes
-customGeometry.commit();
-//Create spinner component
-triangle.createJSComponent("Components/Spinner.js");
+//Load a new scene
+Atomic.player.loadScene("Scenes/Scene.scene");