Triangle.js 985 B

12345678910111213141516171819202122232425262728
  1. 'atomic component';
  2. //Triangle component
  3. exports.component = function(self) {
  4. self.start = function() {
  5. //Create a CustomGeometry component
  6. var customGeometry = self.node.createComponent("CustomGeometry");
  7. //Set it material to VColUnlit
  8. customGeometry.setMaterial(Atomic.cache.getResource("Material", "Materials/VColUnlit.xml"));
  9. //Begin geometry, set index to 0, and TRIANGLE_LIST mode
  10. customGeometry.beginGeometry(0, Atomic.PrimitiveType.TRIANGLE_LIST);
  11. //Define a vertex and a color for that
  12. customGeometry.defineVertex([0.0, 0.5, 0.0]); //Vertex 1
  13. customGeometry.defineColor([1.0, 0.0, 0.0]);
  14. customGeometry.defineVertex([0.5, -0.5, 0.0]); //Vertex 2
  15. customGeometry.defineColor([0.0, 1.0, 0.0]);
  16. customGeometry.defineVertex([-0.5, -0.5, 0.0]); //Vertex 3
  17. customGeometry.defineColor([0.0, 0.0, 1.0]);
  18. //Save changes
  19. customGeometry.commit();
  20. };
  21. };