Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
232 commits
Select commit Hold shift + click to select a range
21aacfa
wip importing
RanPix Nov 6, 2025
8284574
silly indices parsing
RanPix Nov 6, 2025
088cd06
almost load a model
RanPix Nov 7, 2025
020422b
Assets.
tillpp Mar 6, 2026
37adbae
removed material
tillpp Mar 6, 2026
a8fba76
added Templates for entity component and entity systems
tillpp Mar 6, 2026
61e9795
Entity registers and unregisters from entityComponents,
tillpp Mar 6, 2026
acc5c1b
have general Base64 classes and functions
tillpp Mar 6, 2026
9a3e70e
EntityComponentUpdate Protocol
tillpp Mar 6, 2026
bafca57
load EntityTypes from Assets
tillpp Mar 6, 2026
93bd094
made player a function
tillpp Mar 6, 2026
5fbf9ba
removed loadWorldAsset function
tillpp Mar 6, 2026
c2e7539
Merge remote-tracking branch 'origin/ECS_PlayerIsAFunction'
tillpp Mar 6, 2026
8f3bd44
Merge remote-tracking branch 'origin/ECS_ServerEntityLoadsComponents'…
tillpp Mar 6, 2026
0a32373
Merge remote-tracking branch 'origin/ECS_EntityTypeLoadingFromAsset' …
tillpp Mar 6, 2026
0fe9857
Merge remote-tracking branch 'origin/ECS_Protocol' into ECS_United7
tillpp Mar 6, 2026
60254d9
Merge remote-tracking branch 'origin/ECS_Template' into ECS_United7
tillpp Mar 6, 2026
a912431
Merge remote-tracking branch 'origin/ECS_Template' into ECS_ServerEnt…
tillpp Mar 6, 2026
9af0011
Merge remote-tracking branch 'origin/ECS_Template' into ECS_Protocol
tillpp Mar 6, 2026
2dbc78e
Merge remote-tracking branch 'origin/ECS_Template' into ECS_EntityTyp…
tillpp Mar 6, 2026
1e04fa3
removed loadWorldAssets
tillpp Mar 6, 2026
ac18860
Merge remote-tracking branch 'origin/ECS_Protocol' into ECS_United7
tillpp Mar 6, 2026
1b44749
Merge remote-tracking branch 'origin/ECS_ServerEntityLoadsComponents'…
tillpp Mar 6, 2026
baae55c
Merge remote-tracking branch 'origin/ECS_EntityTypeLoadingFromAsset' …
tillpp Mar 6, 2026
033c645
entityModel
tillpp Mar 6, 2026
3932133
added entityModelComponent
tillpp Mar 6, 2026
927849b
temporary Deinits
tillpp Mar 7, 2026
c962389
Merge remote-tracking branch 'origin/ECS_ServerEntityLoadsComponents'…
tillpp Mar 7, 2026
87b048a
fmt
tillpp Mar 7, 2026
82a8004
Merge remote-tracking branch 'origin/ECS_Protocol' into ECS_United7
tillpp Mar 7, 2026
c58f1e5
Merge remote-tracking branch 'origin/ECS_United7' into ECS_AddEntityM…
tillpp Mar 7, 2026
9fa8825
Merge remote-tracking branch 'origin/ECS_United7' into ECS_AddEntityM…
tillpp Mar 7, 2026
aadf9e8
fmt
tillpp Mar 7, 2026
74608ef
fmt
tillpp Mar 7, 2026
b913a8b
Merge remote-tracking branch 'upstream/master' into gltfmodels
RanPix Mar 16, 2026
a37c7e3
switch entity models to triangle meshes and draw them with normal dra…
RanPix Mar 17, 2026
1a7328a
fix formatting
RanPix Mar 17, 2026
9dce456
Revert "fix formatting"
RanPix Mar 17, 2026
de078f2
fix formatting
RanPix Mar 17, 2026
eb21a65
Merge branch 'entityInstancedRendering' into gltfmodels
RanPix Mar 17, 2026
6b9f57b
move loadGltf function to EntityModel
RanPix Mar 17, 2026
56c2574
render the gltf model again with the new struct
RanPix Mar 17, 2026
c7d52e6
what the hell is going on (getting there)
RanPix Mar 18, 2026
c8f7e64
ITS A 1 LINE FIX!!!!!!! UVs!!!!
RanPix Mar 18, 2026
dc533fc
remove redundant vertex attributes
RanPix Mar 20, 2026
a772887
fixes
RanPix Mar 20, 2026
4f63e05
Merge branch 'entityInstancedRendering' into gltfmodels
RanPix Mar 20, 2026
ab3bdd7
improve offsets
RanPix Mar 20, 2026
3fb2f7a
fix (hopefully) all issues with transform positioning
RanPix Mar 20, 2026
03aebf4
format
RanPix Mar 20, 2026
3a2bf28
optimize quaternion to mat function (taken from zmath repo)
RanPix Mar 21, 2026
9466192
load both gltf and glb files
RanPix Mar 21, 2026
1e10d2f
improve error handling
RanPix Mar 21, 2026
af029e6
NODE HIERARCHY WORKING
RanPix Mar 21, 2026
afe5680
cleanup
RanPix Mar 21, 2026
160a389
fix formatting
RanPix Mar 21, 2026
95ebdef
improve error handling + cleanup
RanPix Mar 21, 2026
3185949
remove test files
RanPix Mar 21, 2026
727832b
add reminder comment
RanPix Mar 21, 2026
952accc
add node struct
RanPix Mar 21, 2026
86aeb70
remove old cgltf files
RanPix Mar 21, 2026
2ec1523
Merge branch 'gltfmodels' into joints
RanPix Mar 21, 2026
f4d25de
thinking on the structure
RanPix Mar 21, 2026
25d8919
fix error
RanPix Mar 21, 2026
8a2fab4
Merge commit '25d891992fe6da9bce63f44d80b3b1f56cc1a9b2' into joints
RanPix Mar 21, 2026
adb9c24
simplify getHierarchyMatrix function
RanPix Mar 21, 2026
79e5665
fix formatting
RanPix Mar 21, 2026
9894803
Merge commit '79e566537aa741ccaca50971101d936d7575ef3c' into joints
RanPix Mar 21, 2026
91d8304
more work
RanPix Mar 21, 2026
30a315a
fix formatting
RanPix Mar 21, 2026
2b66994
Merge branch 'gltfmodels' into joints
RanPix Mar 21, 2026
95aecd3
start setting up first small prototype
RanPix Mar 22, 2026
1b2b067
add texture field to models and use default missing texture when one …
RanPix Mar 22, 2026
208c1a3
split gl mesh upload into a separete function
RanPix Mar 22, 2026
3168010
improve model builder loop
RanPix Mar 22, 2026
98248b1
remove test
RanPix Mar 22, 2026
08e749b
Merge commit '316801059de8fd5d28035bc18850f8e380dd6935' into gltfmodels
RanPix Mar 22, 2026
ab59a4a
remove old obj model loader
RanPix Mar 22, 2026
54d678b
rename function
RanPix Mar 22, 2026
bd23a6b
simplify attribute loading
RanPix Mar 22, 2026
cf25ddb
fix format
RanPix Mar 22, 2026
60406fb
add texture deinit
RanPix Mar 22, 2026
ae922bc
Merge commit '60406fb5bf0e252df1de3943694783267d40f3c9' into gltfmodels
RanPix Mar 22, 2026
20bc311
Merge commit 'ae922bc3d843e72ec0b036d42d627611bfa72234' into joints
RanPix Mar 22, 2026
d261a3e
fix model looking backwards and remove 180 degree matrix turn
RanPix Mar 22, 2026
df89778
Merge branch 'gltfmodels' into joints
RanPix Mar 22, 2026
7d6c5d9
send matrices to shader
RanPix Mar 22, 2026
1f796d4
simplify the loop
RanPix Mar 22, 2026
debaa7d
apply review comments
RanPix Mar 22, 2026
1e77f98
fix integer attribute
RanPix Mar 24, 2026
c2ad96a
IT WORKS!!!!!
RanPix Mar 24, 2026
b944b65
add parent ids to nodes
RanPix Mar 24, 2026
a93e11d
fix winding order and fix matrix math
RanPix Mar 24, 2026
2717cfa
SNALE CAN NOD
RanPix Mar 24, 2026
9666eeb
remove children from node
RanPix Mar 24, 2026
d016cc6
also remove deinit
RanPix Mar 24, 2026
28ed7c0
remove crashing code
RanPix Mar 24, 2026
5fec731
Merge branch 'master' into entityInstancedRendering
RanPix Apr 3, 2026
668bf16
fix texture stuff
RanPix Apr 4, 2026
d5c32a2
Merge remote-tracking branch 'upstream/master' into entityInstancedRe…
RanPix Apr 4, 2026
a1d4bf6
add bind function
RanPix Apr 4, 2026
dfecb3b
Merge branch 'entityInstancedRendering' into gltfmodels
RanPix Apr 4, 2026
a8ef1c3
Merge branch 'gltfmodels' into joints
RanPix Apr 4, 2026
47fbb3a
fixes and format
RanPix Apr 4, 2026
aa74be2
fix formatting
RanPix Apr 4, 2026
0ed025a
add uint type to vertex attribute types
RanPix Apr 4, 2026
b01cb7b
move entity model to its own file
RanPix Apr 4, 2026
5432f72
Merge branch 'entityInstancedRendering' into gltfmodels
RanPix Apr 4, 2026
c0061fc
fix error
RanPix Apr 4, 2026
e9d3070
remove bobik
RanPix Apr 4, 2026
fe888f1
remove comments
RanPix Apr 4, 2026
253f1b7
make merging easier
tillpp Apr 4, 2026
fa854b4
more simplification
tillpp Apr 4, 2026
c44644b
Merge branch 'master' into ECS_AddEntityModel
tillpp Apr 4, 2026
34a7c31
bringing more inline
tillpp Apr 4, 2026
7eb07c7
less
tillpp Apr 4, 2026
1fd28a9
fmt
tillpp Apr 4, 2026
8407584
fmt
tillpp Apr 4, 2026
31fe8e9
fmt
tillpp Apr 4, 2026
c129a63
add space
RanPix Apr 4, 2026
cb431e3
Merge branch 'gltfmodels' into joints
RanPix Apr 4, 2026
fce736c
improve test model
RanPix Apr 4, 2026
67af0be
Merge remote-tracking branch 'upstream/master' into entityInstancedRe…
RanPix Apr 5, 2026
b89505e
Merge remote-tracking branch 'upstream/master' into gltfmodels
RanPix Apr 5, 2026
dbfc549
improve error function
RanPix Apr 5, 2026
e7294f7
Merge commit 'dbfc54988e2edb8c5db4006a18f55bb4fcfd1d46' into joints
RanPix Apr 5, 2026
ae685f5
Merge branch 'master' into ECS_AddEntityModel
tillpp Apr 5, 2026
1238efc
Update src/entityModel.zig
RanPix Apr 5, 2026
52f36bc
Merge branch 'entityInstancedRendering' into gltfmodels
RanPix Apr 5, 2026
9e4e6a6
tmp rename
tillpp Apr 5, 2026
381e458
Merge branch 'master' into ECS_AddEntityModel
tillpp Apr 5, 2026
b7d0a68
merged
tillpp Apr 5, 2026
bc6e275
itemDrop not needed as component
tillpp Apr 5, 2026
42fd688
.
tillpp Apr 5, 2026
2768938
.
tillpp Apr 5, 2026
8a1e849
.
tillpp Apr 5, 2026
8e80725
.
tillpp Apr 5, 2026
807d8b8
Merge branch 'master' into ECS_AddEntityModelComponent
tillpp Apr 5, 2026
084543a
merge...
tillpp Apr 5, 2026
30c0996
.
tillpp Apr 5, 2026
41181f3
.
tillpp Apr 5, 2026
0081ea5
Merge branch 'ECS_AddEntityModel' into ECS_AddEntityModelComponent
tillpp Apr 5, 2026
7bed7df
fixed incorrect node transform
RanPix Apr 5, 2026
3d0418e
finalize the model, fix node reverse and add eyestalks rotation mode …
RanPix Apr 5, 2026
d007e7c
Model split
tillpp Apr 5, 2026
8581157
a solution to make @ranPix happy
tillpp Apr 5, 2026
9ff6aaa
comments
tillpp Apr 5, 2026
1ed66b6
Each descriptor has a model
tillpp Apr 6, 2026
0403d13
removed rawEntityModelData
tillpp Apr 6, 2026
3039d14
fmt
tillpp Apr 6, 2026
8a5db6e
descriptions is a better name then descriptor
tillpp Apr 6, 2026
e18f348
make it easier for #2762 to use glb files instead of obj
tillpp Apr 6, 2026
0fecebb
the .obj/.glb files are to heavy to be kept in memory. Remove them af…
tillpp Apr 6, 2026
03cdfeb
fmt
tillpp Apr 7, 2026
51553d7
Merge branch 'ECS_AddEntityModel' into ECS_AddEntityModelComponent
tillpp Apr 7, 2026
84654ee
merge fixed; Quantum really needs to hire a second PR reviewer - he i…
tillpp Apr 7, 2026
e6f4f97
Merge branch 'PixelGuys:master' into ECS_AddEntityModelComponent
tillpp Apr 8, 2026
20740ca
Quantums request changes for assets.zig
tillpp Apr 10, 2026
8bb00a0
use append and renamed functions
tillpp Apr 10, 2026
b0246c4
most of Quantums changed for entityModel.zig
tillpp Apr 10, 2026
9de1ab1
add entity model palette
tillpp Apr 10, 2026
6bd6680
used worldArena
tillpp Apr 10, 2026
b1d3059
forgot to remove temporary debug thing
tillpp Apr 10, 2026
00836e6
Merge branch 'PixelGuys:master' into ECS_AddEntityModel
tillpp Apr 10, 2026
d42c17c
Merge branch 'PixelGuys:master' into ECS_AddEntityModelComponent
tillpp Apr 10, 2026
8e34363
Merge branch 'ECS_AddEntityModel' into ECS_AddEntityModelComponent
tillpp Apr 10, 2026
09c4c26
typo
tillpp Apr 10, 2026
5247f07
missed a entryValue
tillpp Apr 10, 2026
5aa0ddc
Merge branch 'ECS_AddEntityModel' of https://github.com/tillpp/Cubzio…
tillpp Apr 10, 2026
23156fe
fmt
tillpp Apr 10, 2026
da2175f
Wunka told me to use main.files
tillpp Apr 10, 2026
14a7e6f
fix crash
tillpp Apr 10, 2026
abe9640
fmt
tillpp Apr 10, 2026
232b581
temporary loadfunction moved somewhere else
tillpp Apr 10, 2026
5ac7159
invalid boolean
tillpp Apr 10, 2026
fa6ba84
renamed invalid to isLoaded
tillpp Apr 10, 2026
3cd9f82
fmt
tillpp Apr 10, 2026
aa4a56d
fmt
tillpp Apr 10, 2026
37e3fe2
Merge branch 'ECS_AddEntityModel' into ECS_AddEntityModelComponent
tillpp Apr 10, 2026
66aa25e
fmt
tillpp Apr 10, 2026
8f9b624
name it worldAssetFolder
tillpp Apr 11, 2026
aae144c
allocations can't fail
tillpp Apr 11, 2026
6061302
You are using mismatched allocators in both paths.
tillpp Apr 11, 2026
ef98a78
removed deinitModelAndTexture
tillpp Apr 11, 2026
f17d3eb
nitpicking
tillpp Apr 11, 2026
b253c93
asserted here and the incorrect data (index < len) should be handled …
tillpp Apr 11, 2026
b3b5fc8
"loadModelsAndTexture"
tillpp Apr 11, 2026
84caf1a
We know the per world asset folder locally, you can also make it priv…
tillpp Apr 11, 2026
677638f
Idea, that me and MNHS came up with. to declare the entityModel as fa…
tillpp Apr 11, 2026
22ea1a5
revert change into descriptions
tillpp Apr 11, 2026
a7caab8
asset removed descriptions folder
tillpp Apr 11, 2026
ccd4650
reverted removing "model" attr from entityModel
tillpp Apr 11, 2026
f877fef
Merge branch 'ECS_AddEntityModel' into ECS_AddEntityModelComponent
tillpp Apr 11, 2026
2e2a126
playerEntityModels as worldsetting
tillpp Apr 11, 2026
096eb57
Merge branch 'master' into ECS_AddEntityModelComponent
tillpp Apr 11, 2026
e47eb77
Merge branch 'master' into ECS_AddEntityModelComponent
tillpp Apr 11, 2026
601b319
Merge branch 'master' into ECS_AddEntityModelComponent
tillpp Apr 11, 2026
6f21573
merge artefact
tillpp Apr 11, 2026
46b2697
reverted chages
tillpp Apr 11, 2026
a43766b
revert changes 2
tillpp Apr 11, 2026
885dfac
more clean
tillpp Apr 11, 2026
bd5d699
fmt
tillpp Apr 11, 2026
05576eb
comment moved
tillpp Apr 12, 2026
0a57121
removed comment
tillpp Apr 12, 2026
0d7129c
change order
tillpp Apr 12, 2026
23a0cc0
varInt and names
tillpp Apr 12, 2026
8fef535
nextIntBounded
tillpp Apr 12, 2026
4d62048
moved loading into entityModel
tillpp Apr 12, 2026
2f78bee
Merge branch 'master' into ECS_AddEntityModelComponent
tillpp Apr 12, 2026
3759c5f
Merge remote-tracking branch 'upstream/master' into joints
RanPix Apr 12, 2026
cf24fcf
add origin matrix
RanPix Apr 13, 2026
c480f08
remove arm rotation test code
RanPix Apr 13, 2026
8b42c5b
wip improve node detection
RanPix Apr 13, 2026
89c6b96
back to working state
RanPix Apr 13, 2026
3e7e63d
cleanup
RanPix Apr 13, 2026
084fe12
Merge remote-tracking branch 'Tillpp/ECS_AddEntityModelComponent' int…
RanPix Apr 13, 2026
cb0ae0a
Merge remote-tracking branch 'Tillpp/ECS_AddEntityModelComponent' int…
RanPix Apr 13, 2026
e6e611f
preliminary move to ecs8
RanPix Apr 13, 2026
50e73bc
init, wip
RanPix Apr 13, 2026
89b0172
client.get
tillpp Apr 13, 2026
303f131
Merge remote-tracking branch 'Tillpp/ECS_AddEntityModelComponent' int…
RanPix Apr 13, 2026
5e27e00
Merge remote-tracking branch 'Tillpp/ECS_AddEntityModelComponent' int…
RanPix Apr 13, 2026
f550bb4
cleanup
RanPix Apr 13, 2026
8b4b0d6
Merge branch 'joints' into heldItemDisplayForOthers
RanPix Apr 13, 2026
55a7958
make @ranpix happy. load models before entityComponents
tillpp Apr 13, 2026
aa139e9
Merge commit '55a79582e612889a0d0c03d7edeebf4e8672c698' into joints
RanPix Apr 13, 2026
fd70dc7
load player later
tillpp Apr 13, 2026
d11f0d4
fmt
tillpp Apr 13, 2026
8acc571
first iteration, add display
RanPix Apr 13, 2026
7acbf41
switch opengl context just for the handshake for a short time
tillpp Apr 13, 2026
5f8ed5c
i am an idiot
tillpp Apr 13, 2026
fa0cc39
Merge commit '5f8ed5c7aa82c8a127daf44b9c29ba4485c205a4' into joints
RanPix Apr 13, 2026
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
1 change: 1 addition & 0 deletions assets/cubyz/entityModels/cubert.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
.model = "cubyz:cubert",
.defaultTexture = "cubyz:cubert",
.height = 2,
.isPlayerModel = true,
.coordinateSystem = .right_handed_z_up,
}
Binary file modified assets/cubyz/entityModels/models/snale.glb
Binary file not shown.
1 change: 1 addition & 0 deletions assets/cubyz/entityModels/snale.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
.model = "cubyz:snale",
.defaultTexture = "cubyz:snale",
.height = 2,
.isPlayerModel = true,
.coordinateSystem = .left_handed_y_up,
}
Binary file modified assets/cubyz/entityModels/textures/snale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion assets/cubyz/shaders/entity_vertex.vert
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
layout (location = 0) in vec3 inPos;
layout (location = 1) in vec3 inNormal;
layout (location = 2) in vec2 inUV;
layout (location = 3) in uint inNodeID;

layout(location = 0) out vec2 outTexCoord;
layout(location = 1) out vec3 mvVertexPos;
Expand All @@ -13,6 +14,7 @@ layout(location = 0) uniform mat4 projectionMatrix;
layout(location = 1) uniform mat4 viewMatrix;
layout(location = 2) uniform vec3 ambientLight;
layout(location = 3) uniform uint light;
layout(location = 6) uniform mat4 nodeMatrices[20];

vec3 square(vec3 x) {
return x*x;
Expand All @@ -35,7 +37,7 @@ vec3 calcLight(uint fullLight) {
void main() {
normal = inNormal;

vec4 mvPos = viewMatrix*vec4(inPos, 1);
vec4 mvPos = viewMatrix * nodeMatrices[inNodeID] * vec4(inPos, 1);
gl_Position = projectionMatrix*mvPos;
mvVertexPos = mvPos.xyz;
outTexCoord = inUV;
Expand Down
21 changes: 21 additions & 0 deletions src/client/Entity.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const Mat4f = vec.Mat4f;
const Vec3d = vec.Vec3d;
const Vec3f = vec.Vec3f;
const Vec4f = vec.Vec4f;
const EntityModel = main.entityModel.EntityModel;
const NeverFailingAllocator = main.heap.NeverFailingAllocator;

const BinaryReader = main.utils.BinaryReader;
Expand All @@ -40,6 +41,7 @@ pub fn init(self: *@This(), zon: ZonElement, allocator: NeverFailingAllocator) !
.name = allocator.dupe(u8, zon.get([]const u8, "name", "")),
.playerIndex = zon.get(?usize, "playerIndex", null),
};

self._interpolationPos = [_]f64{
self.pos[0],
self.pos[1],
Expand Down Expand Up @@ -77,6 +79,25 @@ pub fn update(self: *@This(), time: i16, lastTime: i16) void {
self.rot[0] = @floatCast(self.interpolatedValues.outPos[3]);
self.rot[1] = @floatCast(self.interpolatedValues.outPos[4]);
self.rot[2] = @floatCast(self.interpolatedValues.outPos[5]);

if (main.entity.components.@"cubyz:model".client.get(self.id)) |modelComp| {
const model = modelComp.entityModel.get();

const head = model.nodeReverse.get("Head");
if (model.nodeReverse.get("Eyestalks")) |eyestalksId| {
const stalkRot = self.rot[0]*0.25;
const headRot = self.rot[0]*0.75;
modelComp.nodes[eyestalksId].rot = vec.quatFromAxisAngle(Vec3f{1, 0, 0}, stalkRot);
modelComp.matrices[eyestalksId] = modelComp.nodes[eyestalksId].getHierarchyMatrix(modelComp.nodes);

const headId = head.?;
modelComp.nodes[headId].rot = vec.quatFromAxisAngle(Vec3f{1, 0, 0}, headRot);
modelComp.matrices[headId] = modelComp.nodes[headId].getHierarchyMatrix(modelComp.nodes);
} else if (head) |headId| {
modelComp.nodes[headId].rot = vec.quatFromAxisAngle(Vec3f{1, 0, 0}, self.rot[0]);
modelComp.matrices[headId] = modelComp.nodes[headId].getHierarchyMatrix(modelComp.nodes);
}
}
}

pub fn format(self: *const @This(), writer: *std.Io.Writer) std.Io.Writer.Error!void {
Expand Down
72 changes: 48 additions & 24 deletions src/client/entity_manager.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ var uniforms: struct {
light: c_int,
contrast: c_int,
ambientLight: c_int,
nodeMatrices: c_int,
} = undefined;

var pipeline: graphics.Pipeline = undefined; // Entities are sometimes small and sometimes big. Therefor it would mean a lot of work to still use smooth lighting. Therefor the non-smooth shader is used for those.
pub var entities: main.utils.VirtualList(main.client.Entity, 1 << 20) = undefined;
pub var mutex: std.Thread.Mutex = .{};
var model: *main.entityModel.EntityModel = undefined;
pub var model: *main.entityModel.EntityModel = undefined;
pub fn init() void {
entities = .init();
pipeline = graphics.Pipeline.init(
Expand Down Expand Up @@ -77,6 +78,21 @@ pub fn initAfterWorld() void {
std.log.err("EntityModel {s} wasn't found", .{"cubyz:snale"});
break :blk main.entityModel.default();
}).get();

// TODO: remove before merge
addEntity(ZonElement.parseFromString(main.globalArena, null,
\\ .{
\\ .id = 1,
\\ .name = "bobik",
\\
\\ }
)) catch unreachable;
var w = utils.BinaryWriter.init(main.stackAllocator);
w.deinit();
w.writeVarInt(u32, 4);
var r = utils.BinaryReader.init(w.data.items);

main.entity.components.@"cubyz:model".client.load(1, &r,0) catch unreachable;
}
pub fn renderNames(projMatrix: Mat4f, playerPos: Vec3d) void {
mutex.lock();
Expand Down Expand Up @@ -132,29 +148,37 @@ pub fn render(projMatrix: Mat4f, ambientLight: Vec3f, playerPos: Vec3d) void {
for (entities.items()) |ent| {
if (ent.id == game.Player.id) continue; // don't render local player

model.bind();
const blockPos: vec.Vec3i = @intFromFloat(@floor(ent.pos));
const lightVals: [6]u8 = main.renderer.mesh_storage.getLight(blockPos[0], blockPos[1], blockPos[2]) orelse @splat(0);
const light = (@as(u32, lightVals[0] >> 3) << 25 |
@as(u32, lightVals[1] >> 3) << 20 |
@as(u32, lightVals[2] >> 3) << 15 |
@as(u32, lightVals[3] >> 3) << 10 |
@as(u32, lightVals[4] >> 3) << 5 |
@as(u32, lightVals[5] >> 3) << 0);

c.glUniform1ui(uniforms.light, @bitCast(@as(u32, light)));

const pos: Vec3d = ent.getRenderPosition() - playerPos;
const modelMatrix = (Mat4f.identity()
.mul(Mat4f.translation(Vec3f{
@floatCast(pos[0]),
@floatCast(pos[1]),
@floatCast(pos[2] - 1.0 + 0.09375),
}))
.mul(Mat4f.rotationZ(-ent.rot[2])));
const modelViewMatrix = game.camera.viewMatrix.mul(modelMatrix);
c.glUniformMatrix4fv(uniforms.viewMatrix, 1, c.GL_TRUE, @ptrCast(&modelViewMatrix));
c.glDrawElements(c.GL_TRIANGLES, model.indexCount, c.GL_UNSIGNED_INT, null);
if (main.entity.components.@"cubyz:model".client.get(ent.id)) |modelComp| {
modelComp.entityModel.get().bind();
const blockPos: vec.Vec3i = @intFromFloat(@floor(ent.pos));
const lightVals: [6]u8 = main.renderer.mesh_storage.getLight(blockPos[0], blockPos[1], blockPos[2]) orelse @splat(0);
const light = (@as(u32, lightVals[0] >> 3) << 25 |
@as(u32, lightVals[1] >> 3) << 20 |
@as(u32, lightVals[2] >> 3) << 15 |
@as(u32, lightVals[3] >> 3) << 10 |
@as(u32, lightVals[4] >> 3) << 5 |
@as(u32, lightVals[5] >> 3) << 0);

c.glUniform1ui(uniforms.light, @bitCast(@as(u32, light)));

const pos: Vec3d = ent.getRenderPosition() - playerPos;
const modelMatrix = (Mat4f.identity()
.mul(Mat4f.translation(Vec3f{
@floatCast(pos[0]),
@floatCast(pos[1]),
@floatCast(pos[2] - 1.0 + 0.09375),
}))
.mul(Mat4f.rotationZ(-ent.rot[2])));
const modelViewMatrix = game.camera.viewMatrix.mul(modelMatrix);
c.glUniformMatrix4fv(uniforms.viewMatrix, 1, c.GL_TRUE, @ptrCast(&modelViewMatrix));
c.glUniformMatrix4fv(uniforms.nodeMatrices, main.entityModel.EntityModel.maxNodesCount, c.GL_TRUE, @ptrCast(&modelComp.matrices));
c.glDrawElements(c.GL_TRIANGLES, model.indexCount, c.GL_UNSIGNED_INT, null);

if (modelComp.entityModel.get().nodeReverse.get("RightItem")) |rightHandItemId| {
const nodeMat = modelComp.nodes[rightHandItemId].getHierarchyMatrix(modelComp.nodes);
main.itemdrop.ItemDropRenderer.renderOtherEntityDisplayItem(ambientLight, lightVals, projMatrix, modelMatrix, nodeMat);
}
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/entity.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ pub const EntityComponentLoadError = error{
UnreadableVersion,
UnreadableComponentData,
UnknownComponentId,
InvalidComponentVersion,
};
pub const Entity = enum(u32) {
noValue = std.math.maxInt(u32),
_,
};
// Analogous to Protocols.
pub const EntityComponentId = u32;
const EntityComponentVTable = struct {
serverLoad: *const fn (entityId: u32, reader: *main.utils.BinaryReader, version: u32) EntityComponentLoadError!void,
Expand Down
1 change: 1 addition & 0 deletions src/entityComponent/_list.zig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub const @"cubyz:_template" = @import("_template.zig");
pub const @"cubyz:model" = @import("model.zig");
114 changes: 114 additions & 0 deletions src/entityComponent/model.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
const std = @import("std");

const main = @import("main");
const chunk = main.chunk;
const game = main.game;
const graphics = main.graphics;
const c = graphics.c;
const ZonElement = main.ZonElement;
const renderer = main.renderer;
const settings = main.settings;
const utils = main.utils;
const vec = main.vec;
const Mat4f = vec.Mat4f;
const Vec3d = vec.Vec3d;
const Vec3f = vec.Vec3f;
const Vec4f = vec.Vec4f;
const NeverFailingAllocator = main.heap.NeverFailingAllocator;

const BinaryReader = main.utils.BinaryReader;

pub var entityComponentID: main.entity.EntityComponentId = undefined;
pub const entityComponentVersion = 0;

// ############################# Client only stuff ################################
pub const client = struct {
const Component = struct {
entityModel: main.entityModel.EntityModelIndex, // model
hasLoaded: bool = false,
nodes: [20]main.entityModel.EntityModel.Node = undefined,
matrices: [20]Mat4f = undefined,
};
pub var components: main.utils.SparseSet(Component, main.entity.Entity) = .{};

var countToCrash = 0;
pub fn init() void {}
pub fn deinit() void {
components.deinit(main.globalAllocator);
}
pub fn clear() void {
components.clear();
}
pub fn load(entity: u32, reader: *utils.BinaryReader, version: u32) main.entity.EntityComponentLoadError!void {
if (version != 0)
return error.InvalidComponentVersion;

const entityModel = reader.readVarInt(u32) catch return main.entity.EntityComponentLoadError.UnreadableComponentData;

const ptr = components.get(@enumFromInt(entity)) orelse components.add(main.globalAllocator, @enumFromInt(entity));
ptr.* = Component{
.entityModel = .{.index = entityModel},
};
const model = ptr.entityModel.get();

for (0..model.nodeCount) |i| {
ptr.nodes[i] = model.nodes[i];
}

for (0..model.nodeCount) |i| {
ptr.matrices[i] = ptr.nodes[i].getHierarchyMatrix(ptr.nodes);
}
}
pub fn unload(entity: u32) void {
components.remove(@enumFromInt(entity)) catch {};
}
pub fn get(entity: u32) ?*Component {
return components.get(@enumFromInt(entity));
}
};

// ############################# Server only stuff ################################

pub const server = struct {
pub const Component = struct {
entityModel: main.entityModel.EntityModelIndex, // model
pub fn save(self: Component, writer: *utils.BinaryWriter, audience: main.entity.AudienceInfo) main.entity.ComponentSaveBehaviour {
_ = audience;
writer.writeVarInt(u32, self.entityModel.index);
return .save;
}
};
var components: main.utils.SparseSet(Component, main.entity.Entity) = undefined;
pub fn init() void {
components = .{};
}
pub fn deinit() void {
components.deinit(main.globalAllocator);
}
pub fn loadFromData(entity: u32, reader: *utils.BinaryReader, version: u32) main.entity.EntityComponentLoadError!void {
if (version != 0)
return error.InvalidComponentVersion;
const entityModel = reader.readVarInt(u32) catch return main.entity.EntityComponentLoadError.UnreadableComponentData;

try loadByIndex(entity, main.entityModel.EntityModelIndex{.index = entityModel});
}
pub fn loadByID(entity: u32, entityModelID: []const u8) main.entity.EntityComponentLoadError!void {
try loadByIndex(entity, main.entityModel.getById(entityModelID) orelse main.entityModel.default());
}
pub fn loadByIndex(entity: u32, entityModel: main.entityModel.EntityModelIndex) main.entity.EntityComponentLoadError!void {
const ptr = components.get(@enumFromInt(entity)) orelse components.add(main.globalAllocator, @enumFromInt(entity));
ptr.* = Component{
.entityModel = entityModel,
};
}
pub fn unload(entity: u32) void {
components.remove(@enumFromInt(entity)) catch {};
}
pub fn put(entity: u32, renderComponent: Component) void {
const ptr = components.get(@enumFromInt(entity)) orelse components.add(main.globalAllocator, @enumFromInt(entity));
ptr.* = renderComponent;
}
pub fn get(entity: u32) ?*Component {
return components.get(@enumFromInt(entity));
}
};
Loading
Loading