mirror of https://github.com/buggins/dlangui.git
#183 : fix OBJ loader
This commit is contained in:
parent
52fbe8a38f
commit
815283e25c
|
@ -137,6 +137,12 @@ class UiWidget : VerticalLayout, CellVisitor {
|
|||
ObjModelImport importer;
|
||||
string src = loadTextResource("suzanne.obj");
|
||||
importer.parse(src);
|
||||
Log.d("suzanne mesh:", importer.mesh.dumpVertexes(20));
|
||||
Material suzanneMaterial = new Material(EffectId("colored.vert", "colored.frag", null), null);
|
||||
Model suzanneDrawable = new Model(suzanneMaterial, importer.mesh);
|
||||
Node3d suzanneNode = new Node3d("suzanne", suzanneDrawable);
|
||||
//suzanneNode.translate(vec3(3, 4, 5));
|
||||
_scene.addChild(suzanneNode);
|
||||
|
||||
|
||||
_minerMesh = new Mesh(VertexFormat(VertexElementType.POSITION, VertexElementType.NORMAL, VertexElementType.COLOR, VertexElementType.TEXCOORD0));
|
||||
|
@ -164,6 +170,10 @@ class UiWidget : VerticalLayout, CellVisitor {
|
|||
Node3d minerNode = new Node3d("miner", minerDrawable);
|
||||
_scene.addChild(minerNode);
|
||||
|
||||
|
||||
//minerNode.visible = false;
|
||||
//cubeNode.visible = false;
|
||||
|
||||
//CellVisitor visitor = new TestVisitor();
|
||||
//Log.d("Testing cell visitor");
|
||||
//long ts = currentTimeMillis;
|
||||
|
|
|
@ -94,7 +94,7 @@ class Effect : GLProgram {
|
|||
vertexLocation = getAttribLocation("vertex");
|
||||
colAttrLocation = getAttribLocation("colAttr");
|
||||
texCoordLocation = getAttribLocation("texCoord");
|
||||
return matrixLocation >= 0 && vertexLocation >= 0 && colAttrLocation >= 0 && texCoordLocation >= 0;
|
||||
return matrixLocation >= 0 && vertexLocation >= 0; // && colAttrLocation >= 0 && texCoordLocation >= 0
|
||||
}
|
||||
|
||||
/// get location for vertex attribute
|
||||
|
|
|
@ -101,19 +101,19 @@ struct VertexElement {
|
|||
struct VertexFormat {
|
||||
private VertexElement[] _elements;
|
||||
private byte[VertexElementType.max + 1] _elementOffset = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1];
|
||||
private int _vertexSize;
|
||||
private int _vertexSize; // vertex size in floats
|
||||
/// make using element list
|
||||
this(inout VertexElement[] elems...) {
|
||||
_elements = elems.dup;
|
||||
foreach(elem; elems) {
|
||||
_elementOffset[elem.type] = cast(byte)(_vertexSize / float.sizeof);
|
||||
_vertexSize += elem.size * float.sizeof;
|
||||
_elementOffset[elem.type] = cast(byte)_vertexSize;
|
||||
_vertexSize += elem.size;
|
||||
}
|
||||
}
|
||||
/// init from vertex element types, using default sizes for types
|
||||
this(inout VertexElementType[] types...) {
|
||||
foreach(t; types) {
|
||||
_elementOffset[t] = cast(byte)(_vertexSize / float.sizeof);
|
||||
_elementOffset[t] = cast(byte)_vertexSize;
|
||||
VertexElement elem = VertexElement(t);
|
||||
_elements ~= elem;
|
||||
_vertexSize += elem.size;
|
||||
|
@ -190,6 +190,16 @@ struct VertexFormat {
|
|||
return false;
|
||||
return true;
|
||||
}
|
||||
string dump(float * data) {
|
||||
import std.conv : to;
|
||||
char[] buf;
|
||||
int pos = 0;
|
||||
foreach(VertexElement e; _elements) {
|
||||
buf ~= data[pos .. pos + e.size].to!string;
|
||||
pos += e.size;
|
||||
}
|
||||
return buf.dup;
|
||||
}
|
||||
}
|
||||
|
||||
struct IndexFragment {
|
||||
|
@ -239,6 +249,18 @@ class Mesh : RefCountedObject {
|
|||
}
|
||||
}
|
||||
|
||||
string dumpVertexes(int maxCount = 30) {
|
||||
char[] buf;
|
||||
int count = 0;
|
||||
for(int i = 0; i < _vertexData.length; i+= _vertexFormat.vertexFloats) {
|
||||
buf ~= "\n";
|
||||
buf ~= _vertexFormat.dump(_vertexData.ptr + i);
|
||||
if (++count >= maxCount)
|
||||
break;
|
||||
}
|
||||
return buf.dup;
|
||||
}
|
||||
|
||||
/// returns vertex count
|
||||
@property int vertexCount() const { return _vertexCount; }
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ class Node3d : Transform {
|
|||
protected Node3d _parent;
|
||||
protected Scene3d _scene;
|
||||
protected string _id;
|
||||
protected bool _visible = true;
|
||||
protected DrawableObjectRef _drawable;
|
||||
|
||||
protected mat4 _worldMatrix;
|
||||
|
@ -29,6 +30,9 @@ class Node3d : Transform {
|
|||
_drawable = drawable;
|
||||
}
|
||||
|
||||
@property bool visible() { return _visible; }
|
||||
@property Node3d visible(bool v) { _visible = v; return this; }
|
||||
|
||||
/// drawable attached to node
|
||||
@property ref DrawableObjectRef drawable() { return _drawable; }
|
||||
|
||||
|
|
|
@ -67,6 +67,8 @@ class Scene3d : Node3d {
|
|||
|
||||
/// depth-first recursive node traversion, stops if visitor returns true
|
||||
bool visit(Node3d node, bool delegate(Node3d node) visitor) {
|
||||
if (!node.visible)
|
||||
return false;
|
||||
bool res = visitor(node);
|
||||
if (res)
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue