Allow specifying all 16 model textures via its index

fixes #1144
This commit is contained in:
IntegratedQuantum 2025-03-22 14:25:32 +01:00
parent 01cfb786aa
commit 1268f8e95e
8 changed files with 54 additions and 54 deletions

View File

@ -9,12 +9,12 @@
.model = .{
.radius = 4,
},
.texture_top = "cubyz:branch/baobab/dot",
.texture_bottom = "cubyz:branch/baobab/half_line",
.texture_right = "cubyz:branch/baobab/line",
.texture_left = "cubyz:branch/baobab/bend",
.texture_front = "cubyz:branch/baobab/intersection",
.texture_back = "cubyz:branch/baobab/cross",
.texture0 = "cubyz:branch/baobab/dot",
.texture1 = "cubyz:branch/baobab/half_line",
.texture2 = "cubyz:branch/baobab/line",
.texture3 = "cubyz:branch/baobab/bend",
.texture4 = "cubyz:branch/baobab/intersection",
.texture5 = "cubyz:branch/baobab/cross",
.item = .{
.material = .{
.density = 0.2,

View File

@ -9,12 +9,12 @@
.model = .{
.radius = 4,
},
.texture_top = "cubyz:branch/birch/dot",
.texture_bottom = "cubyz:branch/birch/half_line",
.texture_right = "cubyz:branch/birch/line",
.texture_left = "cubyz:branch/birch/bend",
.texture_front = "cubyz:branch/birch/intersection",
.texture_back = "cubyz:branch/birch/cross",
.texture0 = "cubyz:branch/birch/dot",
.texture1 = "cubyz:branch/birch/half_line",
.texture2 = "cubyz:branch/birch/line",
.texture3 = "cubyz:branch/birch/bend",
.texture4 = "cubyz:branch/birch/intersection",
.texture5 = "cubyz:branch/birch/cross",
.item = .{
.material = .{
.density = 0.3,

View File

@ -9,12 +9,12 @@
.model = .{
.radius = 4,
},
.texture_top = "cubyz:branch/cactus/dot",
.texture_bottom = "cubyz:branch/cactus/half_line",
.texture_right = "cubyz:branch/cactus/line",
.texture_left = "cubyz:branch/cactus/bend",
.texture_front = "cubyz:branch/cactus/intersection",
.texture_back = "cubyz:branch/cactus/cross",
.texture0 = "cubyz:branch/cactus/dot",
.texture1 = "cubyz:branch/cactus/half_line",
.texture2 = "cubyz:branch/cactus/line",
.texture3 = "cubyz:branch/cactus/bend",
.texture4 = "cubyz:branch/cactus/intersection",
.texture5 = "cubyz:branch/cactus/cross",
.item = .{
.material = .{
.density = 0.8,

View File

@ -9,12 +9,12 @@
.model = .{
.radius = 4,
},
.texture_top = "cubyz:branch/mahogany/dot",
.texture_bottom = "cubyz:branch/mahogany/half_line",
.texture_right = "cubyz:branch/mahogany/line",
.texture_left = "cubyz:branch/mahogany/bend",
.texture_front = "cubyz:branch/mahogany/intersection",
.texture_back = "cubyz:branch/mahogany/cross",
.texture0 = "cubyz:branch/mahogany/dot",
.texture1 = "cubyz:branch/mahogany/half_line",
.texture2 = "cubyz:branch/mahogany/line",
.texture3 = "cubyz:branch/mahogany/bend",
.texture4 = "cubyz:branch/mahogany/intersection",
.texture5 = "cubyz:branch/mahogany/cross",
.item = .{
.material = .{
.density = 0.5,

View File

@ -9,12 +9,12 @@
.model = .{
.radius = 4,
},
.texture_top = "cubyz:branch/oak/dot",
.texture_bottom = "cubyz:branch/oak/half_line",
.texture_right = "cubyz:branch/oak/line",
.texture_left = "cubyz:branch/oak/bend",
.texture_front = "cubyz:branch/oak/intersection",
.texture_back = "cubyz:branch/oak/cross",
.texture0 = "cubyz:branch/oak/dot",
.texture1 = "cubyz:branch/oak/half_line",
.texture2 = "cubyz:branch/oak/line",
.texture3 = "cubyz:branch/oak/bend",
.texture4 = "cubyz:branch/oak/intersection",
.texture5 = "cubyz:branch/oak/cross",
.item = .{
.material = .{
.density = 0.25,

View File

@ -9,12 +9,12 @@
.model = .{
.radius = 4,
},
.texture_top = "cubyz:branch/pine/dot",
.texture_bottom = "cubyz:branch/pine/half_line",
.texture_right = "cubyz:branch/pine/line",
.texture_left = "cubyz:branch/pine/bend",
.texture_front = "cubyz:branch/pine/intersection",
.texture_back = "cubyz:branch/pine/cross",
.texture0 = "cubyz:branch/pine/dot",
.texture1 = "cubyz:branch/pine/half_line",
.texture2 = "cubyz:branch/pine/line",
.texture3 = "cubyz:branch/pine/bend",
.texture4 = "cubyz:branch/pine/intersection",
.texture5 = "cubyz:branch/pine/cross",
.item = .{
.material = .{
.density = 0.25,

View File

@ -9,12 +9,12 @@
.model = .{
.radius = 4,
},
.texture_top = "cubyz:branch/willow/dot",
.texture_bottom = "cubyz:branch/willow/half_line",
.texture_right = "cubyz:branch/willow/line",
.texture_left = "cubyz:branch/willow/bend",
.texture_front = "cubyz:branch/willow/intersection",
.texture_back = "cubyz:branch/willow/cross",
.texture0 = "cubyz:branch/willow/dot",
.texture1 = "cubyz:branch/willow/half_line",
.texture2 = "cubyz:branch/willow/line",
.texture3 = "cubyz:branch/willow/bend",
.texture4 = "cubyz:branch/willow/intersection",
.texture5 = "cubyz:branch/willow/cross",
.item = .{
.material = .{
.density = 0.5,

View File

@ -429,16 +429,13 @@ pub const meshes = struct { // MARK: meshes
time: u32,
};
const TextureData = extern struct {
textureIndices: [6]u16,
};
const FogData = extern struct {
fogDensity: f32,
fogColor: u32,
};
var size: u32 = 0;
var _modelIndex: [maxBlockCount]ModelIndex = undefined;
var textureData: [maxBlockCount]TextureData = undefined;
var textureIndices: [maxBlockCount][16]u16 = undefined;
/// Stores the number of textures after each block was added. Used to clean additional textures when the world is switched.
var maxTextureCount: [maxBlockCount]u32 = undefined;
/// Number of loaded meshes. Used to determine if an update is needed.
@ -556,11 +553,11 @@ pub const meshes = struct { // MARK: meshes
}
pub inline fn fogDensity(block: Block) f32 {
return textureFogData.items[animation.items[textureData[block.typ].textureIndices[0]].startFrame].fogDensity;
return textureFogData.items[animation.items[textureIndices[block.typ][0]].startFrame].fogDensity;
}
pub inline fn fogColor(block: Block) u32 {
return textureFogData.items[animation.items[textureData[block.typ].textureIndices[0]].startFrame].fogColor;
return textureFogData.items[animation.items[textureIndices[block.typ][0]].startFrame].fogColor;
}
pub inline fn hasFog(block: Block) bool {
@ -569,9 +566,9 @@ pub const meshes = struct { // MARK: meshes
pub inline fn textureIndex(block: Block, orientation: usize) u16 {
if(orientation < 16) {
return textureData[block.typ].textureIndices[orientation];
return textureIndices[block.typ][orientation];
} else {
return textureData[block.data].textureIndices[orientation - 16];
return textureIndices[block.data][orientation - 16];
}
}
@ -657,10 +654,13 @@ pub const meshes = struct { // MARK: meshes
return result;
}
pub fn getTextureIndices(zon: ZonElement, assetFolder: []const u8, textureIndicesRef: []u16) void {
pub fn getTextureIndices(zon: ZonElement, assetFolder: []const u8, textureIndicesRef: *[16]u16) void {
const defaultIndex = readTexture(zon.get(?[]const u8, "texture", null), assetFolder) catch 0;
for(textureIndicesRef, sideNames) |*ref, name| {
const textureId = zon.get(?[]const u8, name, null);
inline for(textureIndicesRef, 0..) |*ref, i| {
var textureId = zon.get(?[]const u8, std.fmt.comptimePrint("texture{}", .{i}), null);
if(i < sideNames.len) {
textureId = zon.get(?[]const u8, sideNames[i], textureId);
}
ref.* = readTexture(textureId, assetFolder) catch defaultIndex;
}
}
@ -671,7 +671,7 @@ pub const meshes = struct { // MARK: meshes
// The actual model is loaded later, in the rendering thread.
// But textures can be loaded here:
getTextureIndices(zon, assetFolder, &textureData[meshes.size].textureIndices);
getTextureIndices(zon, assetFolder, &textureIndices[meshes.size]);
maxTextureCount[meshes.size] = @intCast(textureIDs.items.len);