small fixes (although gui on next scene transition breaks)

This commit is contained in:
mrq 2025-05-30 21:32:55 -05:00 committed by ecker
parent 1ef5798017
commit 91cf9665fe
20 changed files with 324 additions and 60 deletions

View File

@ -102,7 +102,7 @@
"batch queue submissions": true,
"dedicated thread": false,
"memory budget": false,
"register render modes": false
"register render modes": true
},
"invariant": {
"default stage buffers": true,

View File

@ -10,7 +10,8 @@
"CraetureBehavior"
],
"transform": {
"position": [ 0, 1.5, 21 ],
//"position": [ 0, 1.5, 21 ],
"position": [ 16.3489, 1.37972, -68.1571 ],
"rotation": {
"axis": [ 0, 1, 0 ],
"angle": 0

View File

@ -0,0 +1,44 @@
{
"type": "Object",
"name": "Craeture2",
"ignore": false,
"assets": [
"./craetureModel2.json",
"./scripts/craeture.lua"
],
"behaviors": [
"CraetureBehavior"
],
"transform": {
//"position": [ 0, 1.5, 21 ],
"position": [ 0.595603, 2.63543, -68.4572 ],
"rotation": {
"axis": [ 0, 1, 0 ],
"angle": 0
},
"scale": [ 1, 1, 1 ]
},
"system": {
"hot reload": {
"enabled": true
}
},
"metadata": {
"name": "Craeture",
"physics": {
"gravity": [ 0, -9.81, 0 ],
"inertia": [ 0, 0, 0 ],
"type": "capsule",
"radius": 2,
"height": 1.0,
"mass": 100,
"friction": 0.95,
"restitution": 0.0,
"shared": false
}
}
}

View File

@ -11,14 +11,14 @@
"CraetureBehavior"
],
"transform": {
"position": [ 0, -2.0, 0 ],
"position": [ 0, -2.5, 0 ],
// "position": [ 12.5715, 3.53811, 7.6238 ],
// "position": [ 1.635, -0.384, -20.409 ], // -0.384
"rotation": {
"axis": [ 0, 1, 0 ],
"angle": 0
},
"scale": [ 0.16, 0.16, 0.16 ],
"scale": [ 0.35, 0.35, 0.35 ],
"reference": "parent"
},
"system": {

View File

@ -0,0 +1,63 @@
{
"type": "Object",
"name": "Craeture Model",
"ignore": false,
"import": "/model.json",
"assets": [
// "/player/ben.glb"
{ "filename": "/player/ben/graph.json" }
],
"behaviors": [
"CraetureBehavior"
],
"transform": {
"position": [ 0, -2.5, 0 ],
// "position": [ 12.5715, 3.53811, 7.6238 ],
// "position": [ 1.635, -0.384, -20.409 ], // -0.384
"rotation": {
"axis": [ 0, 1, 0 ],
"angle": 0
},
"scale": [ 0.5, 0.5, 0.5 ],
"reference": "parent"
},
"system": {
"hot reload": {
"enabled": true
}
},
"metadata": {
"graph": {
"key": "Craeture",
"debug": {
"print": {
"animations": true
}
},
"exporter": {
"enabled": true,
"unwrap": false,
"optimize": false
},
"baking": {
"enabled": false
},
"lights": {
"lightmap": false
},
"sanitizer": {
"winding order": false
},
"renderer": {
"cull mode": "front",
"filter": "linear",
"flip textures": false,
"invert": false,
"skinned": false
},
"animations": {
"animation": "idle"
}
}
}
}

View File

@ -68,7 +68,7 @@
"invert": true,
"skinned": false,
"render": true,
"separate": true
"separate": false
},
"lights": {
"lightmap": "auto",

View File

@ -4,8 +4,8 @@
"ignore": true,
"import": "/model.json",
"assets": [
// "/player/bear.glb"
{ "filename": "/player/bear/graph.json" }
"/player/ben.glb"
// { "filename": "/player/bear/graph.json" }
],
"behaviors": [
"PlayerModelBehavior"

View File

@ -46,8 +46,8 @@
"bloom": {
"threshold": 1.0,
"size": 4,
"smoothness": 1
"size": 8,
"smoothness": 0.5
},
"shadows": {
"enabled": true

View File

@ -6,7 +6,8 @@
// { "filename": "./models/animal_crossing_small.glb" },
// { "filename": "./models/animal_crossing_small/graph.json" },
{ "filename": "/craeture.json", "delay": 2.0 }
{ "filename": "/craeture.json", "delay": 2.0 },
{ "filename": "/craeture2.json", "delay": 2.0 }
],
"metadata": {
"graph": {

View File

@ -23,7 +23,7 @@
"info_player_spawn": { "action": "attach", "filename": "./player.json", "transform": { "orientation": [ 0, 1, 0, 0 ] } },
"light_environment": { "ignore": false, "light": {
// "color": [0.1, 0.1, 0.1],
"power": 1000000,
"power": 1000,
"global": true,
"bias": {
"constant": 0,
@ -31,7 +31,7 @@
"shader": 0.000025
},
"radius": [0.9999999, 0],
"resolution": 1024
"resolution": 2048
} },
// "/^light_[^e]/": { "ignore": true },

View File

@ -1,8 +1,8 @@
{
"import": "./base_sourceengine.json",
"assets": [
{ "filename": "./models/mds_mcdonalds.glb" },
// { "filename": "./models/mds_mcdonalds/graph.json" },
// { "filename": "./models/mds_mcdonalds.glb" },
{ "filename": "./models/mds_mcdonalds/graph.json" },
{ "filename": "/burger.json", "delay": 1 }
],
"metadata": {

View File

@ -6,7 +6,7 @@
],
"metadata": {
"light": {
"fog-": {
"fog": {
// "color": [ 0.1, 0.1, 0.1 ],
// "color": [ 0.2, 0.2, 0.2 ],
"color": [ 0.3, 0.3, 0.3 ],
@ -15,7 +15,7 @@
"absorbtion": 0.125,
"density": {
"threshold": 0.35,
"multiplier": 2.0,
"multiplier": 1.0,
"scale": 25.0,
"offset": [0.2, 0, 1],
"timescale": 32

View File

@ -1,8 +1,8 @@
{
// "import": "./rp_downtown_v2.json"
// "import": "./ss2_medsci1.json"
"import": "./sh2_mcdonalds.json"
// "import": "./sh2_mcdonalds.json"
// "import": "./animal_crossing.json"
// "import": "./mds_mcdonalds.json"
"import": "./mds_mcdonalds.json"
// "import": "./gm_construct.json"
}

View File

@ -17,12 +17,13 @@
},
"bgm": {
"tracks": {
"/ui/tmrwah.ogg": {}
// "/ui/main menu.ogg": {},
"/ui/tainted.ogg": {
"intro": "/ui/tainted_intro.ogg",
"epsilon": 0.25,
"fade": true
}
// "/ui/tainted.ogg": {
// "intro": "/ui/tainted_intro.ogg",
// "epsilon": 0.25,
// "fade": true
// }
}
}
},

View File

@ -1,7 +1,7 @@
{
"engine": {
"scenes": {
"start": "SourceEngine",
"start": "StartMenu",
"matrix": { "reverseInfinite": true },
"meshes": { "interleaved": false },
"lights": { "enabled": true,

View File

@ -1,33 +0,0 @@
/*
#include <uf/engine/asset/masterdata.h>
#include <iostream>
//uf::stl::string uf::MasterData::root = "https://el..xyz/mastertable/get/%TABLE%/%KEY%?.json";
uf::stl::string uf::MasterData::root = uf::io::root + "/master/%TABLE%.json";
uf::asset uf::MasterData::assetLoader;
uf::Serializer uf::MasterData::load( const uf::stl::string& table, size_t key ) {
return this->load( table, std::to_string(key) );
}
uf::Serializer uf::MasterData::load( const uf::stl::string& table, const uf::stl::string& key ) {
this->m_table = table;
this->m_key = key;
uf::stl::string url = uf::string::replace( root, "%TABLE%", table );
auto payload = uf::asset::resolveToPayload( uf::string::replace( url, "%KEY%", key ) );
uf::stl::string filename = uf::asset::cache(payload);
if ( filename != "" ) this->m_data.readFromFile(filename);
return this->get();
}
uf::Serializer uf::MasterData::get( const uf::stl::string& key ) const {
uf::stl::string k = (key == "" ? this->m_key : key);
if ( k != "" ) return this->m_data[k];
return this->m_data;
}
const uf::stl::string& uf::MasterData::tableName() const {
return this->m_table;
}
const uf::stl::string& uf::MasterData::keyName() const {
return this->m_key;
}
*/

View File

@ -324,7 +324,11 @@ void uf::scene::unloadScene() {
uf::scene::scenes.pop_back();
}
uf::Scene& uf::scene::getCurrentScene() {
UF_ASSERT( !uf::scene::scenes.empty() );
//UF_ASSERT( !uf::scene::scenes.empty() );
if ( uf::scene::scenes.empty() ) {
return uf::Entity::null.as<uf::Scene>();
}
return *uf::scene::scenes.back();
}
void uf::scene::invalidateGraphs() {

View File

@ -47,6 +47,90 @@ namespace {
uf::graph::convert( self );
}
void load_migoto( uf::Object& self, const uf::Serializer& json ) {
struct Position {
pod::Vector3f position;
pod::Vector3f normal;
pod::Vector4f tangent;
};
struct TexCoord {
pod::ColorRgba color;
pod::Vector2f16 uv;
pod::Vector2f st;
pod::Vector2f16 wx;
};
struct Weight {
pod::Vector4f alpha;
pod::Vector4f indices;
};
auto& metadataJson = this->getComponent<uf::Serializer>();
//auto root = metadataJson["system"]["root"].as<uf::stl::string>();
auto root = json["root"].as(metadataJson["system"]["root"].as<uf::stl::string>());
auto ib_buffer = uf::io::readAsBuffer( root + "/" + json["ib_buffer"].as<uf::stl::string>() );
auto ib_buffer_start = (uint32_t*) ib_buffer.data();
auto pos_buffer = uf::io::readAsBuffer( root + "/" + json["pos_buffer"].as<uf::stl::string>() );
auto uv_buffer = uf::io::readAsBuffer( root + "/" + json["texcoord_buffer"].as<uf::stl::string>() );
auto weight_buffer = uf::io::readAsBuffer( root + "/" + json["weight_buffer"].as<uf::stl::string>() );
auto pos_buffer_start = (Position*) pos_buffer.data();
auto uv_buffer_start = (TexCoord*) uv_buffer.data();
auto weight_buffer_start = (Weight*) weight_buffer.data();
auto pos_stride = sizeof(float) * 10;
auto uv_stride = sizeof(uint8_t) * 4 + sizeof(float) * 4;
auto weight_stride = sizeof(float) * 8;
auto vb_stride = pos_stride + uv_stride + weight_stride;
auto ib_stride = sizeof(uint32_t);
auto ib_count = ib_buffer.size() / ib_stride;
auto vb_count = pos_buffer.size() / pos_stride;
uf::stl::vector<uint32_t> indices( ib_buffer_start, ib_buffer_start + ib_count );
uf::stl::vector<uf::graph::mesh::Skinned> vertices( vb_count );
for ( auto i = 0; i < vb_count; ++i ) {
auto& vertex = vertices[i];
auto& pos = pos_buffer_start[i];
auto& uv = uv_buffer_start[i];
auto& weight = weight_buffer_start[i];
vertex.position = pos.position;
vertex.normal = pos.normal;
vertex.tangent = pos.tangent;
vertex.color = uv.color;
vertex.uv[0] = uv.uv[0];
vertex.uv[1] = uv.uv[1];
//vertex.st = uv.st;
vertex.joints = weight.indices;
vertex.weights = weight.alpha;
}
uf::Image albedoImage;
albedoImage.open( root + "/" + json["albedo_path"].as<uf::stl::string>() );
auto& graphic = self.getComponent<uf::Graphic>();
auto& albedoTexture = graphic.material.textures.emplace_back();
auto& mesh = self.getComponent<uf::Mesh>();
albedoTexture.loadFromImage( albedoImage );
mesh.bindIndirect<pod::DrawCommand>();
mesh.bind<uf::graph::mesh::Skinned, uint32_t>();
mesh.insertVertices<uf::graph::mesh::Skinned>( vertices );
mesh.insertIndices<uint32_t>( indices );
uf::graph::convert( self );
}
}
void ext::CraetureBehavior::initialize( uf::Object& self ) {
/*
@ -63,6 +147,10 @@ void ext::CraetureBehavior::initialize( uf::Object& self ) {
auto& metadataJson = this->getComponent<uf::Serializer>();
UF_BEHAVIOR_METADATA_BIND_SERIALIZER_HOOKS(metadata, metadataJson);
if ( !ext::json::isNull( metadataJson["migoto"] ) ) {
::load_migoto( self, metadataJson["migoto"] );
}
}
void ext::CraetureBehavior::tick( uf::Object& self ) {
auto& metadata = this->getComponent<ext::CraetureBehavior::Metadata>();

View File

@ -152,7 +152,8 @@ void ext::BgmEmitterBehavior::Metadata::serialize( uf::Object& self, uf::Seriali
}
}
void ext::BgmEmitterBehavior::Metadata::deserialize( uf::Object& self, uf::Serializer& serializer ){
ext::json::forEach( serializer["bgm"]["tracks"], [&]( const uf::stl::string& key, const ext::json::Value& value ){
// iterate by value instead of reference because some keys might not exist and jsoncpp is agony
ext::json::forEach( serializer["bgm"]["tracks"], [&]( const uf::stl::string& key, ext::json::Value value ){
auto& track = /*this->*/tracks[key];
track.filename = key;
track.intro = value["intro"].as(track.intro);
@ -162,7 +163,8 @@ void ext::BgmEmitterBehavior::Metadata::deserialize( uf::Object& self, uf::Seria
} else if ( value["fade"].is<float>() ) {
track.fade = { value["fade"].as<float>(), value["fade"].as<float>() };
} else {
track.fade = ext::json::decode( value["fade"], track.fade );
// YUC
track.fade = ext::json::decode<float,2>( value["fade"], track.fade );
}
if ( track.intro != "" ) tracks[track.intro] = track;

View File

@ -799,6 +799,99 @@ void EXT_API ext::initialize() {
ext::ready = true;
UF_MSG_INFO("EXT took {} seconds to initialize", times.sys.elapsed().asDouble());
//
/*
{
struct Position {
pod::Vector3f position;
pod::Vector3f normal;
pod::Vector4f tangent;
};
struct TexCoord {
pod::ColorRgba color;
pod::Vector2f16 uv;
pod::Vector2f st;
pod::Vector2f16 wx;
};
struct Weight {
pod::Vector4f alpha;
pod::Vector4f indices;
};
auto ib_buffer = uf::io::readAsBuffer( "./data/tmp/a.ib" );
auto ib_buffer_start = (uint32_t*) ib_buffer.data();
auto pos_buffer = uf::io::readAsBuffer( "./data/tmp/pos.buf" );
auto uv_buffer = uf::io::readAsBuffer( "./data/tmp/uv.buf" );
auto weight_buffer = uf::io::readAsBuffer( "./data/tmp/weight.buf" );
auto pos_buffer_start = (Position*) pos_buffer.data();
auto uv_buffer_start = (TexCoord*) uv_buffer.data();
auto weight_buffer_start = (Weight*) weight_buffer.data();
auto pos_stride = sizeof(float) * 10;
auto uv_stride = sizeof(uint8_t) * 4 + sizeof(float) * 4;
auto weight_stride = sizeof(float) * 8;
auto vb_stride = pos_stride + uv_stride + weight_stride;
auto ib_stride = sizeof(uint32_t);
auto ib_count = ib_buffer.size() / ib_stride;
auto vb_count = pos_buffer.size() / pos_stride;
uf::stl::vector<uint32_t> indices( ib_buffer_start, ib_buffer_start + ib_count );
uf::stl::vector<uf::graph::mesh::Skinned> vertices( vb_count );
for ( auto i = 0; i < vb_count; ++i ) {
auto& vertex = vertices[i];
auto& pos = pos_buffer_start[i];
auto& uv = uv_buffer_start[i];
auto& weight = weight_buffer_start[i];
vertex.position = pos.position;
vertex.normal = pos.normal;
vertex.tangent = pos.tangent;
vertex.color = uv.color;
vertex.uv[0] = uv.uv[0];
vertex.uv[1] = uv.uv[1];
vertex.st = uv.st;
vertex.joints = weight.indices;
vertex.weights = weight.alpha;
}
// printout
std::stringstream ib_ss;
std::stringstream vb_ss;
ib_ss << "byte offset: 0\nfirst index: 0\nindex count: " << ib_count << "\ntopology: trianglelist\nformat: DXGI_FORMAT_R16_UINT\n\n";
vb_ss << "stride: 92\nfirst vertex: 0\nvertex count: " << vb_count << "\ntopology: trianglelist\nelement[0]:\n SemanticName: POSITION\n SemanticIndex: 0\n Format: R32G32B32_FLOAT\n InputSlot: 0\n AlignedByteOffset: 0\n InputSlotClass: per-vertex\n InstanceDataStepRate: 0\nelement[1]:\n SemanticName: NORMAL\n SemanticIndex: 0\n Format: R32G32B32_FLOAT\n InputSlot: 0\n AlignedByteOffset: 12\n InputSlotClass: per-vertex\n InstanceDataStepRate: 0\nelement[2]:\n SemanticName: TANGENT\n SemanticIndex: 0\n Format: R32G32B32A32_FLOAT\n InputSlot: 0\n AlignedByteOffset: 24\n InputSlotClass: per-vertex\n InstanceDataStepRate: 0\nelement[3]:\n SemanticName: BLENDWEIGHTS\n SemanticIndex: 0\n Format: R32G32B32A32_FLOAT\n InputSlot: 0\n AlignedByteOffset: 40\n InputSlotClass: per-vertex\n InstanceDataStepRate: 0\nelement[4]:\n SemanticName: BLENDINDICES\n SemanticIndex: 0\n Format: R32G32B32A32_UINT\n InputSlot: 0\n AlignedByteOffset: 56\n InputSlotClass: per-vertex\n InstanceDataStepRate: 0\nelement[5]:\n SemanticName: COLOR\n SemanticIndex: 0\n Format: R8G8B8A8_UNORM\n InputSlot: 0\n AlignedByteOffset: 72\n InputSlotClass: per-vertex\n InstanceDataStepRate: 0\nelement[6]:\n SemanticName: TEXCOORD\n SemanticIndex: 0\n Format: R16G16_FLOAT\n InputSlot: 0\n AlignedByteOffset: 76\n InputSlotClass: per-vertex\n InstanceDataStepRate: 0\nelement[7]:\n SemanticName: TEXCOORD\n SemanticIndex: 1\n Format: R32G32_FLOAT\n InputSlot: 0\n AlignedByteOffset: 80\n InputSlotClass: per-vertex\n InstanceDataStepRate: 0\nelement[8]:\n SemanticName: TEXCOORD\n SemanticIndex: 2\n Format: R16G16_FLOAT\n InputSlot: 0\n AlignedByteOffset: 88\n InputSlotClass: per-vertex\n InstanceDataStepRate: 0\nvertex-data:\n\n";
for ( auto i = 0; i < ib_count / 3; ++i ) {
ib_ss << indices[i*3+0] << " " << indices[i*3+1] << " " << indices[i*3+2] << "\n";
}
for ( auto i = 0; i < vb_count; ++i ) {
auto& vertex = vertices[i];
vb_ss << "vb0[" << i << "]+000 POSITION: " << vertex.position[0] << ", " << vertex.position[1] << ", " << vertex.position[2] <<
"\nvb0[" << i << "]+012 NORMAL: " << vertex.normal[0] << ", " << vertex.normal[1] << ", " << vertex.normal[2] <<
"\nvb0[" << i << "]+024 TANGENT: " << vertex.tangent[0] << ", " << vertex.tangent[1] << ", " << vertex.tangent[2] << ", " << vertex.tangent[3] <<
"\nvb0[" << i << "]+040 BLENDWEIGHTS: " << vertex.weights[0] << ", " << vertex.weights[1] << ", " << vertex.weights[2] << ", " << vertex.weights[3] <<
"\nvb0[" << i << "]+056 BLENDINDICES: " << vertex.joints[0] << ", " << vertex.joints[1] << ", " << vertex.joints[2] << ", " << vertex.joints[3] <<
"\nvb0[" << i << "]+072 COLOR: " << (int) vertex.color[0] << ", " << (int) vertex.color[1] << ", " << (int) vertex.color[2] << ", " << (int) vertex.color[3] <<
"\nvb0[" << i << "]+076 TEXCOORD: " << vertex.uv[0] << ", " << vertex.uv[1] <<
"\nvb0[" << i << "]+080 TEXCOORD1: " << vertex.st[0] << ", " << vertex.st[1] <<
"\nvb0[" << i << "]+088 TEXCOORD2: " << vertex.uv[0] << ", " << vertex.uv[1] <<
"\n\n";
}
uf::io::write( "./data/tmp/vb.txt", vb_ss.str() );
uf::io::write( "./data/tmp/ib.txt", ib_ss.str() );
}
*/
}
void EXT_API ext::tick() {