Skip to content

Commit

Permalink
Include ObjParser
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Jan 2, 2020
1 parent dee9722 commit 45e1727
Show file tree
Hide file tree
Showing 4 changed files with 794 additions and 8 deletions.
11 changes: 4 additions & 7 deletions mesh_import/Sources/arm/ImportMesh.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import iron.data.MeshData;
import iron.data.MaterialData;
import iron.system.Input;

// Format library should be enabled in `Armory Project - Modules - Format`
import iron.format.obj.ObjParser;

class ImportMesh extends iron.Trait {

var meshData:MeshData;
Expand All @@ -23,13 +20,13 @@ class ImportMesh extends iron.Trait {

// Parse obj file
var mesh = new ObjParser(blob);

// Positions, normals and indices
var pos:TVertexArray = { attrib: "pos", values: mesh.posa };
var nor:TVertexArray = { attrib: "nor", values: mesh.nora };
var ind:TIndexArray = { material: 0, values: mesh.inda };

var rawmeshData:TMeshData = {
var rawmeshData:TMeshData = {
name: "BoxMesh",
vertex_arrays: [pos, nor],
index_arrays: [ind],
Expand All @@ -41,7 +38,7 @@ class ImportMesh extends iron.Trait {
new MeshData(rawmeshData, function(data:MeshData) {
meshData = data;
meshData.geom.calculateAABB();

// Fetch material from scene data
Data.getMaterial("Scene", "Material", function(data:MaterialData) {
// Material loaded
Expand All @@ -58,7 +55,7 @@ class ImportMesh extends iron.Trait {
if (mouse.started()) {
// Create new object in active scene
var object = Scene.active.addMeshObject(meshData, materials);

// Just for testing, add rigid body trait
var aabb = meshData.geom.aabb;
object.transform.loc.set(Math.random() * 8 - 4, Math.random() * 8 - 4, 5);
Expand Down
Loading

0 comments on commit 45e1727

Please sign in to comment.