Compare commits
3 Commits
c904353baf
...
f3d926ff14
Author | SHA1 | Date | |
---|---|---|---|
f3d926ff14 | |||
cbc6c4cf79 | |||
3f62ad3928 |
4790
assets/meshes/teddy.obj
Normal file
4790
assets/meshes/teddy.obj
Normal file
File diff suppressed because it is too large
Load Diff
BIN
assets/meshes/teddy.png
Normal file
BIN
assets/meshes/teddy.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 547 B |
@ -1,7 +1,18 @@
|
|||||||
nodes:
|
nodes:
|
||||||
- type: mesh
|
- type: mesh
|
||||||
translation: [0, 0, 0]
|
translation: [0, 0, 0]
|
||||||
|
rotation:
|
||||||
|
pitch: 45
|
||||||
|
roll: 45
|
||||||
mesh: meshes/cube.obj
|
mesh: meshes/cube.obj
|
||||||
- type: mesh
|
- type: mesh
|
||||||
translation: [1, 0, -10]
|
translation: [1, 0, -10]
|
||||||
mesh: meshes/cube.obj
|
rotation:
|
||||||
|
yaw: 45
|
||||||
|
mesh: meshes/cube.obj
|
||||||
|
- type: mesh
|
||||||
|
translation: [1, 0, -5]
|
||||||
|
rotation:
|
||||||
|
yaw: 90
|
||||||
|
scale: 0.1
|
||||||
|
mesh: meshes/teddy.obj
|
@ -12,6 +12,9 @@ void loadCommonNodeProperties(const YAML::Node& yaml, SceneNode& node)
|
|||||||
{
|
{
|
||||||
const YAML::Node& translationNode = yaml["translation"];
|
const YAML::Node& translationNode = yaml["translation"];
|
||||||
glm::vec3 translation = {0.f, 0.f, 0.f};
|
glm::vec3 translation = {0.f, 0.f, 0.f};
|
||||||
|
glm::vec3 pitchYawRoll = {0.f, 0.f, 0.f};
|
||||||
|
glm::vec3 scale = {1.f, 1.f, 1.f};
|
||||||
|
|
||||||
if (translationNode.IsDefined())
|
if (translationNode.IsDefined())
|
||||||
{
|
{
|
||||||
mijin::ensure(translationNode.IsSequence() && translationNode.size() == 3
|
mijin::ensure(translationNode.IsSequence() && translationNode.size() == 3
|
||||||
@ -22,7 +25,45 @@ void loadCommonNodeProperties(const YAML::Node& yaml, SceneNode& node)
|
|||||||
translation.z = translationNode[2].as<float>();
|
translation.z = translationNode[2].as<float>();
|
||||||
}
|
}
|
||||||
|
|
||||||
node.setTransform(Transform3D::make(translation));
|
if (const YAML::Node& rotationNode = yaml["rotation"]; rotationNode.IsDefined())
|
||||||
|
{
|
||||||
|
mijin::ensure(rotationNode.IsMap(), "Invalid scene YAML: node rotation must be a map.");
|
||||||
|
if (const YAML::Node& pitchNode = rotationNode["pitch"]; pitchNode.IsDefined())
|
||||||
|
{
|
||||||
|
mijin::ensure(pitchNode.IsScalar(), "Invalid scene YAML: node pitch must be a scalar.");
|
||||||
|
pitchYawRoll[0] = pitchNode.as<float>();
|
||||||
|
}
|
||||||
|
if (const YAML::Node& yawNode = rotationNode["yaw"]; yawNode.IsDefined())
|
||||||
|
{
|
||||||
|
mijin::ensure(yawNode.IsScalar(), "Invalid scene YAML: yaw pitch must be a scalar.");
|
||||||
|
pitchYawRoll[1] = yawNode.as<float>();
|
||||||
|
}
|
||||||
|
if (const YAML::Node& rollNode = rotationNode["roll"]; rollNode.IsDefined())
|
||||||
|
{
|
||||||
|
mijin::ensure(rollNode.IsScalar(), "Invalid scene YAML: node roll must be a scalar.");
|
||||||
|
pitchYawRoll[2] = rollNode.as<float>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (const YAML::Node& scaleNode = yaml["scale"]; scaleNode.IsDefined())
|
||||||
|
{
|
||||||
|
if (scaleNode.IsScalar())
|
||||||
|
{
|
||||||
|
scale = glm::vec3(scaleNode.as<float>());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mijin::ensure(scaleNode.IsSequence() && scaleNode.size() == 3
|
||||||
|
&& scaleNode[0].IsScalar() && scaleNode[1].IsScalar() && scaleNode[2].IsScalar(),
|
||||||
|
"Invalid scene YAML: node scale must be scalar or sequence of three scalars.");
|
||||||
|
scale = {
|
||||||
|
scaleNode[0].as<float>(),
|
||||||
|
scaleNode[1].as<float>(),
|
||||||
|
scaleNode[2].as<float>()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
node.setTransform(Transform3D::make(translation, glm::quat(glm::radians(pitchYawRoll)), scale));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<MeshNode> loadMeshNode(const YAML::Node& yaml)
|
std::unique_ptr<MeshNode> loadMeshNode(const YAML::Node& yaml)
|
||||||
|
@ -88,7 +88,7 @@ void SceneRenderer::render(const SceneRendererRenderArgs& args)
|
|||||||
-args.camera.position
|
-args.camera.position
|
||||||
),
|
),
|
||||||
.viewToClip = glm::perspectiveFov(
|
.viewToClip = glm::perspectiveFov(
|
||||||
/* fov = */ glm::radians(90.f),
|
/* fov = */ args.camera.fovh,
|
||||||
/* width = */ static_cast<float>(args.targetTextureWidth),
|
/* width = */ static_cast<float>(args.targetTextureWidth),
|
||||||
/* height = */ static_cast<float>(args.targetTextureHeight),
|
/* height = */ static_cast<float>(args.targetTextureHeight),
|
||||||
/* zNear = */ args.camera.zNear,
|
/* zNear = */ args.camera.zNear,
|
||||||
|
@ -33,7 +33,7 @@ struct CameraOptions
|
|||||||
float pitch = 0.f;
|
float pitch = 0.f;
|
||||||
float yaw = 0.f;
|
float yaw = 0.f;
|
||||||
float fovh = glm::radians(90.f);
|
float fovh = glm::radians(90.f);
|
||||||
float zNear = 0.f;
|
float zNear = 0.1f;
|
||||||
float zFar = 100.f;
|
float zFar = 100.f;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -68,7 +68,10 @@ struct Transform3D
|
|||||||
|
|
||||||
inline Transform3D Transform3D::make(const glm::vec3& translation, const glm::quat& rotation, const glm::vec3& scale)
|
inline Transform3D Transform3D::make(const glm::vec3& translation, const glm::quat& rotation, const glm::vec3& scale)
|
||||||
{
|
{
|
||||||
return Transform3D{glm::translate(glm::mat4_cast(rotation) * glm::scale(glm::mat4(1), scale), translation)};
|
// return Transform3D{glm::translate(glm::mat4_cast(rotation) * glm::scale(scale), translation)};
|
||||||
|
return Transform3D{
|
||||||
|
glm::translate(translation) * glm::mat4_cast(rotation) * glm::scale(scale)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transform3D::setTranslation(const glm::vec3& translation)
|
void Transform3D::setTranslation(const glm::vec3& translation)
|
||||||
|
@ -44,21 +44,33 @@ Mesh loadMesh(const mijin::PathReference& path)
|
|||||||
for (int vertexIdx = 0; vertexIdx < 3; ++vertexIdx)
|
for (int vertexIdx = 0; vertexIdx < 3; ++vertexIdx)
|
||||||
{
|
{
|
||||||
const tinyobj::index_t& index = shape.mesh.indices[indexOffset + vertexIdx];
|
const tinyobj::index_t& index = shape.mesh.indices[indexOffset + vertexIdx];
|
||||||
|
glm::vec3 normal;
|
||||||
|
glm::vec2 texcoord;
|
||||||
|
|
||||||
|
if (index.normal_index > -1)
|
||||||
|
{
|
||||||
|
normal = {
|
||||||
|
attrib.normals[3 * index.normal_index + 0],
|
||||||
|
attrib.normals[3 * index.normal_index + 1],
|
||||||
|
attrib.normals[3 * index.normal_index + 2]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (index.texcoord_index > -1)
|
||||||
|
{
|
||||||
|
texcoord = {
|
||||||
|
attrib.texcoords[2 * index.texcoord_index + 0],
|
||||||
|
1.f - attrib.texcoords[2 * index.texcoord_index + 1] // obj UV is weird
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
mesh.vertices.push_back({
|
mesh.vertices.push_back({
|
||||||
.pos = {
|
.pos = {
|
||||||
attrib.vertices[3 * index.vertex_index + 0],
|
attrib.vertices[3 * index.vertex_index + 0],
|
||||||
attrib.vertices[3 * index.vertex_index + 1],
|
attrib.vertices[3 * index.vertex_index + 1],
|
||||||
attrib.vertices[3 * index.vertex_index + 2]
|
attrib.vertices[3 * index.vertex_index + 2]
|
||||||
},
|
},
|
||||||
.normal = {
|
.normal = normal,
|
||||||
attrib.normals[3 * index.normal_index + 0],
|
.texcoord = texcoord,
|
||||||
attrib.normals[3 * index.normal_index + 1],
|
|
||||||
attrib.normals[3 * index.normal_index + 2]
|
|
||||||
},
|
|
||||||
.texcoord = {
|
|
||||||
attrib.texcoords[2 * index.texcoord_index + 0],
|
|
||||||
1.f - attrib.texcoords[2 * index.texcoord_index + 1] // obj UV is weird
|
|
||||||
},
|
|
||||||
.color = {
|
.color = {
|
||||||
attrib.colors[3 * index.vertex_index + 0],
|
attrib.colors[3 * index.vertex_index + 0],
|
||||||
attrib.colors[3 * index.vertex_index + 1],
|
attrib.colors[3 * index.vertex_index + 1],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user