mirror of https://github.com/buggins/dlangui.git
Scene3d SkyBox support, part 1
This commit is contained in:
parent
88f47e0e80
commit
40dd1148dd
|
@ -787,6 +787,7 @@
|
|||
<File path="src\dlangui\graphics\scene\node.d" />
|
||||
<File path="src\dlangui\graphics\scene\objimport.d" />
|
||||
<File path="src\dlangui\graphics\scene\scene3d.d" />
|
||||
<File path="src\dlangui\graphics\scene\skybox.d" />
|
||||
<File path="src\dlangui\graphics\scene\transform.d" />
|
||||
</Folder>
|
||||
<Folder name="xpm">
|
||||
|
|
|
@ -18,12 +18,17 @@ class Camera : Node3d {
|
|||
|
||||
protected bool _enabled;
|
||||
|
||||
protected float _far = 100;
|
||||
|
||||
this(string ID = null) {
|
||||
super(ID);
|
||||
_enabled = true;
|
||||
setPerspective(4.0f, 3.0f, 45.0f, 0.1f, 100.0f);
|
||||
}
|
||||
|
||||
/// returns FAR range of camera
|
||||
@property float farRange() { return _far; }
|
||||
|
||||
/// returns true if camera is active (enabled)
|
||||
@property bool enabled() { return _enabled; }
|
||||
|
||||
|
@ -75,12 +80,14 @@ class Camera : Node3d {
|
|||
|
||||
/// set orthographic projection
|
||||
void setOrtho(float left, float right, float bottom, float top, float near, float far) {
|
||||
_far = far;
|
||||
_projectionMatrix.setOrtho(left, right, bottom, top, near, far);
|
||||
_dirtyViewProjection = true;
|
||||
}
|
||||
|
||||
/// set perspective projection
|
||||
void setPerspective(float width, float height, float fov, float near, float far) {
|
||||
_far = far;
|
||||
_projectionMatrix.setPerspective(fov, width / height, near, far);
|
||||
_dirtyViewProjection = true;
|
||||
}
|
||||
|
|
|
@ -491,7 +491,7 @@ class Mesh : RefCountedObject {
|
|||
}
|
||||
|
||||
|
||||
private void addQuad(ref vec3 v0, ref vec3 v1, ref vec3 v2, ref vec3 v3, ref vec4 color) {
|
||||
void addQuad(ref vec3 v0, ref vec3 v1, ref vec3 v2, ref vec3 v3, ref vec4 color) {
|
||||
ushort startVertex = cast(ushort)vertexCount;
|
||||
if (hasElement(VertexElementType.NORMAL)) {
|
||||
vec3 normal = vec3.crossProduct((v1 - v0), (v3 - v0)).normalized;
|
||||
|
|
|
@ -92,6 +92,27 @@ class Node3d : Transform {
|
|||
destroy(_children.remove(index));
|
||||
}
|
||||
|
||||
/// remove and destroy child node (returns true if child is found and removed)
|
||||
bool removeChild(Node3d child) {
|
||||
int index = findChild(child);
|
||||
if (index >= 0) {
|
||||
removeChild(index);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// find node index, returns -1 if not found
|
||||
int findChild(Node3d node) {
|
||||
if (node is null)
|
||||
return -1;
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
if (child(i) is node)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@property ref ObjectList!Node3d children() { return _children; }
|
||||
|
||||
/// parent node
|
||||
|
|
|
@ -7,6 +7,7 @@ import dlangui.core.types;
|
|||
|
||||
import dlangui.core.math3d;
|
||||
import dlangui.graphics.scene.node;
|
||||
import dlangui.graphics.scene.skybox;
|
||||
|
||||
/// Reference counted Scene3d object
|
||||
alias Scene3dRef = Ref!Scene3d;
|
||||
|
@ -19,12 +20,23 @@ class Scene3d : Node3d {
|
|||
|
||||
protected vec3 _ambientColor;
|
||||
protected Camera _activeCamera;
|
||||
protected SkyBox _skyBox;
|
||||
|
||||
/// ambient light color
|
||||
@property vec3 ambientColor() { return _ambientColor; }
|
||||
/// set ambient light color
|
||||
@property void ambientColor(const ref vec3 v) { _ambientColor = v; }
|
||||
|
||||
this(string id = null) {
|
||||
super(id);
|
||||
_skyBox = new SkyBox(this);
|
||||
}
|
||||
|
||||
~this() {
|
||||
destroy(_skyBox);
|
||||
}
|
||||
|
||||
@property SkyBox skyBox() { return _skyBox; }
|
||||
|
||||
/// active camera
|
||||
override @property Camera activeCamera() {
|
||||
|
@ -53,10 +65,19 @@ class Scene3d : Node3d {
|
|||
void drawScene(bool wireframe) {
|
||||
_wireframe = wireframe;
|
||||
updateAutoboundLights();
|
||||
if (_skyBox.visible) {
|
||||
if (_activeCamera) {
|
||||
_skyBox.translation = _activeCamera.translation;
|
||||
_skyBox.scaling = _activeCamera.farRange * 0.8;
|
||||
}
|
||||
sceneDrawVisitor(_skyBox);
|
||||
}
|
||||
visit(this, &sceneDrawVisitor);
|
||||
}
|
||||
|
||||
protected bool sceneDrawVisitor(Node3d node) {
|
||||
if (!node.visible)
|
||||
return false;
|
||||
if (!node.drawable.isNull)
|
||||
node.drawable.draw(node, _wireframe);
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue