Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions docs/asset_reference.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Asset Reference

This file was generated from asset_schema.wtf and is for version 29 of the asset format.
This file was generated from asset_schema.wtf and is for version 30 of the asset format.

## Index

Expand Down Expand Up @@ -1111,14 +1111,13 @@ No children.
| - | - | - | - | - |
| name | The name of the material being referenced. | String | Yes | RAC/GC/UYA/DL |
| wrap_mode | The UV wrapping mode, stored as an array of two strings. Possible values are ["repeat" "repeat"] (the default), ["repeat" "clamp"], ["clamp" "repeat"] and ["clamp" "clamp"]. | Array | No | RAC/GC/UYA/DL |
| glass | Only for mobies. Make the material shiny, like glass? | Boolean | *Not yet documented.* | *Not yet documented.* |
| chrome | Only for mobies. Make the material shiny, like chrome? | Boolean | *Not yet documented.* | *Not yet documented.* |
| effect_mode | List of effect modifiers, only relevant for mobies. Possible values are [], ["none"], ["chrome"] and ["glass"]. | Array | No | RAC/GC/UYA/DL |

*Children*

| Name | Description | Allowed Types | Required | Games |
| - | - | - | - | - |
| diffuse | The diffuse map (main texture). | Texture | Yes | RAC/GC/UYA/DL |
| diffuse | The diffuse map (main texture). | Texture | No | RAC/GC/UYA/DL |


### Collision
Expand Down
1 change: 1 addition & 0 deletions docs/asset_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ Each asset type is defined in `asset_schema.wtf` and a code generator, `asset_co

| Format Version | Wrench Version | Description |
| - | - | - |
| 30 | | Added effect_mode attribute to Material assets, removed chrome and glass attributes, and made diffuse children optional. |
| 29 | | Added hero_groups attributes to Collision assets. |
| 28 | | Use glTF (.glb) for the moby models instead of COLLADA. |
| 27 | v0.5 | Use glTF (.glb) for the shrub and sky models instead of COLLADA. The mesh attribute of the SkyShell asset is now of type Mesh instead of Collection. The starting_rotation and angular_velocity attributes now only will only apply for UYA and DL (which is more correct). |
Expand Down
2 changes: 1 addition & 1 deletion docs/instance_reference.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Instance Reference

This file was generated from instance_schema.wtf and is for version 29 of the instance format.
This file was generated from instance_schema.wtf and is for version 30 of the instance format.

## Instances

Expand Down
17 changes: 8 additions & 9 deletions src/assetmgr/asset_schema.wtf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

format_version: 29
format_version: 30

// *****************************************************************************

Expand Down Expand Up @@ -1714,19 +1714,18 @@ AssetType Material {
games: [1 2 3 4]
StringAttribute element {}
}

BooleanAttribute glass {
desc: "Only for mobies. Make the material shiny, like glass?"
}

BooleanAttribute chrome {
desc: "Only for mobies. Make the material shiny, like chrome?"

ArrayAttribute effect_mode {
desc: "List of effect modifiers, only relevant for mobies. Possible values are [], [\"none\"], [\"chrome\"] and [\"glass\"]."
required: false
games: [1 2 3 4]
StringAttribute element {}
}

Child diffuse {
desc: "The diffuse map (main texture)."
allowed_types: ["Texture"]
required: true
required: false
games: [1 2 3 4]
}
}
Expand Down
37 changes: 27 additions & 10 deletions src/assetmgr/material_asset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,21 @@ MaterialSet read_material_assets(const CollectionAsset& src)
src.for_each_logical_child_of_type<MaterialAsset>([&](const MaterialAsset& asset) {
Material& material = materials.emplace_back();
material.name = asset.name();
const TextureAsset& diffuse = asset.get_diffuse();
std::string diffuse_path = asset.get_diffuse().src().path.string();
auto key = std::make_pair(&diffuse.file(), diffuse_path);
auto iter = texture_indices.find(key);
if (iter == texture_indices.end()) {
texture_indices[key] = next_texture_index;
material.surface = MaterialSurface(next_texture_index);
next_texture_index++;
textures.emplace_back(diffuse.file(), asset.get_diffuse().src().path);
if (asset.has_diffuse()) {
const TextureAsset& diffuse = asset.get_diffuse();
std::string diffuse_path = asset.get_diffuse().src().path.string();
auto key = std::make_pair(&diffuse.file(), diffuse_path);
auto iter = texture_indices.find(key);
if (iter == texture_indices.end()) {
texture_indices[key] = next_texture_index;
material.surface = MaterialSurface(next_texture_index);
next_texture_index++;
textures.emplace_back(diffuse.file(), asset.get_diffuse().src().path);
} else {
material.surface = MaterialSurface(iter->second);
}
} else {
material.surface = MaterialSurface(iter->second);
material.surface = MaterialSurface(glm::vec4(1.f, 0.f, 1.f, 1.f));
}
if (asset.has_wrap_mode()) {
std::vector<std::string> wrap_mode = asset.wrap_mode();
Expand All @@ -50,6 +54,19 @@ MaterialSet read_material_assets(const CollectionAsset& src)
}
}
}
if (asset.has_effect_mode()) {
for(std::string effect : asset.effect_mode()) {
if (effect == "none") {
material.effect_mode = MaterialEffectMode::NONE;
}
if (effect == "chrome") {
material.effect_mode = MaterialEffectMode::CHROME;
}
if (effect == "glass") {
material.effect_mode = MaterialEffectMode::GLASS;
}
}
}
});
return {materials, textures};
}
69 changes: 69 additions & 0 deletions src/core/gltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ struct GLTFBuffer
// GLTF, Scenes & Nodes
static ModelFile read_gltf(const Json& src, Buffer bin_chunk);
static Json write_gltf(const ModelFile& src, OutBuffer bin_chunk);
static void validate_gltf(const ModelFile& gltf);
static Asset read_asset(const Json& src);
static Json write_asset(const Asset& src);
static Scene read_scene(const Json& src);
Expand Down Expand Up @@ -256,6 +257,7 @@ ModelFile read_glb(Buffer src)
try {
auto json = Json::parse(src.lo + json_offset, src.lo + json_offset + json_size);
gltf = read_gltf(json, src.subbuf(bin_offset, bin_size));
validate_gltf(gltf);
} catch (Json::exception& e) {
verify_not_reached("%s", e.what());
}
Expand All @@ -265,6 +267,8 @@ ModelFile read_glb(Buffer src)

std::vector<u8> write_glb(const ModelFile& gltf)
{
validate_gltf(gltf);

std::vector<u8> result;
OutBuffer dest(result);

Expand Down Expand Up @@ -590,6 +594,71 @@ static Json write_gltf(const ModelFile& src, OutBuffer bin_chunk)
return dest;
}

static void validate_gltf(const ModelFile& gltf)
{
for (const Scene& scene : gltf.scenes) {
const char* name = scene.name.has_value() ? scene.name->c_str() : "unnamed";

for (NodeIndex node : scene.nodes) {
verify(node >= 0 && node < gltf.nodes.size(),
"Out of bounds node index %d for scene '%s'.", node, name);
}
}

for (const Node& node : gltf.nodes) {
const char* name = node.name.has_value() ? node.name->c_str() : "unnamed";

for (NodeIndex child : node.children) {
verify(child >= 0 && child < gltf.nodes.size(),
"Out of bounds child index %d for node '%s'.", child, name);
}

if (node.mesh.has_value()) {
verify(*node.mesh >= 0 && *node.mesh < gltf.meshes.size(),
"Out of bounds mesh index %d for node '%s'.", *node.mesh, name);
}
}

for (const Animation& animation : gltf.animations) {
const char* name = animation.name.has_value() ? animation.name->c_str() : "unnamed";

for (SamplerIndex sampler : animation.sampler_input) {
verify(sampler >= 0 && sampler < gltf.samplers.size(),
"Out of bounds sampler index %d for animation '%s'.", sampler, name);
}
}

for (const Mesh& mesh : gltf.meshes) {
const char* name = mesh.name.has_value() ? mesh.name->c_str() : "unnamed";

for (const MeshPrimitive& primitive : mesh.primitives) {
if (primitive.material.has_value()) {
verify(*primitive.material >= 0 && *primitive.material < gltf.materials.size(),
"Out of bounds material index %d for mesh '%s'.", *primitive.material, name);
}
}
}

for (const Material& material : gltf.materials) {
const char* name = material.name.has_value() ? material.name->c_str() : "unnamed";

if (material.pbr_metallic_roughness.has_value() && material.pbr_metallic_roughness->base_color_texture.has_value()) {
const TextureInfo& info = *material.pbr_metallic_roughness->base_color_texture;
verify(info.index >= 0 && info.index < gltf.textures.size(),
"Out of bounds texture index %d for material '%s'.", info.index, name);
}
}

for (const Texture& texture : gltf.textures) {
const char* name = texture.name.has_value() ? texture.name->c_str() : "unnamed";

if (texture.sampler.has_value()) {
verify(*texture.sampler >= 0 && *texture.sampler < gltf.samplers.size(),
"Out of bounds sampler index %d for texture '%s'.", *texture.sampler, name);
}
}
}

static Asset read_asset(const Json& src)
{
Asset dest;
Expand Down
26 changes: 18 additions & 8 deletions src/core/gltf.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@

namespace GLTF {

using SceneIndex = s32;
using NodeIndex = s32;
using AnimationIndex = s32;
using MeshIndex = s32;
using MaterialIndex = s32;
using TextureIndex = s32;
using ImageIndex = s32;
using SamplerIndex = s32;
using SkinIndex = s32;

struct Asset
{
Opt<std::string> copyright;
Expand All @@ -35,17 +45,17 @@ struct Asset

struct Scene
{
std::vector<s32> nodes;
std::vector<NodeIndex> nodes;
Opt<std::string> name;
};

struct Node
{
// unimplemented: camera
std::vector<s32> children;
Opt<s32> skin;
std::vector<NodeIndex> children;
Opt<SkinIndex> skin;
Opt<glm::mat4> matrix;
Opt<s32> mesh;
Opt<MeshIndex> mesh;
Opt<glm::vec4> rotation;
Opt<glm::vec3> scale;
Opt<glm::vec3> translation;
Expand All @@ -70,12 +80,12 @@ struct Animation
{
Opt<std::string> name;
std::vector<AnimationChannelGroup> channel_groups;
std::vector<f32> sampler_input;
std::vector<SamplerIndex> sampler_input;
};

struct TextureInfo
{
s32 index;
TextureIndex index;
Opt<s32> tex_coord;
};

Expand Down Expand Up @@ -133,7 +143,7 @@ struct MeshPrimitive
{
u32 attributes_bitfield = 0;
std::vector<s32> indices;
Opt<s32> material;
Opt<MaterialIndex> material;
Opt<MeshPrimitiveMode> mode;
// unimplemented: targets
};
Expand All @@ -148,7 +158,7 @@ struct Mesh

struct Texture
{
Opt<s32> sampler;
Opt<SamplerIndex> sampler;
Opt<s32> source;
Opt<std::string> name;
};
Expand Down
4 changes: 2 additions & 2 deletions src/core/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ EffectiveMaterialsOutput effective_materials(const std::vector<Material>& materi
equal &= materials[i].wrap_mode_s == materials[j].wrap_mode_s;
equal &= materials[i].wrap_mode_t == materials[j].wrap_mode_t;
}
if (attributes & MATERIAL_ATTRIB_METAL_MODE) {
equal &= materials[i].metal_mode == materials[j].metal_mode;
if (attributes & MATERIAL_ATTRIB_EFFECT_MODE) {
equal &= materials[i].effect_mode == materials[j].effect_mode;
}
if (equal) {
effective.materials.emplace_back((s32) j);
Expand Down
8 changes: 4 additions & 4 deletions src/core/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ enum class WrapMode
REPEAT, CLAMP
};

enum class MetalEffectMode
enum class MaterialEffectMode
{
OFF, CHROME, GLASS
OFF, NONE, CHROME, GLASS
};

struct Material
Expand All @@ -66,14 +66,14 @@ struct Material
MaterialSurface surface;
WrapMode wrap_mode_s = WrapMode::REPEAT;
WrapMode wrap_mode_t = WrapMode::REPEAT;
MetalEffectMode metal_mode = MetalEffectMode::OFF;
MaterialEffectMode effect_mode = MaterialEffectMode::OFF;
};

enum MaterialAttribute
{
MATERIAL_ATTRIB_SURFACE = 1 << 1,
MATERIAL_ATTRIB_WRAP_MODE = 1 << 2,
MATERIAL_ATTRIB_METAL_MODE = 1 << 3
MATERIAL_ATTRIB_EFFECT_MODE = 1 << 3
};

// An effective material is a set of materials that for some subset of
Expand Down
4 changes: 2 additions & 2 deletions src/instancemgr/instance_schema.wtf
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

format_version: 29
format_version: 30

InstanceType Moby {
desc: "Moving, interactive, or otherwise dynamic objects with an associated update function."
components: "COM_TRANSFORM | COM_CLASS | COM_PVARS | COM_DRAW_DISTANCE | COM_COLOUR"
transform_mode: "POSITION_ROTATION_SCALE"
variable: "moby_instances"
link_type: "mobylink"

s8 mission {}
s32 uid {}
s32 bolts {}
Expand Down
Loading
Loading