Allow specifying the side model for the torch rotation.

fixes #1016
This commit is contained in:
IntegratedQuantum 2025-03-04 19:00:41 +01:00
parent aacd2bae5b
commit 72a68d6b6d
4 changed files with 82 additions and 21 deletions

View File

@ -10,9 +10,12 @@
.absorbedLight = 0x010101, .absorbedLight = 0x010101,
.collide= false, .collide= false,
.rotation = .torch, .rotation = .torch,
.model = "cubyz:torch", .model = .{
.base = "cubyz:torch",
.side = "cubyz:torch_side",
},
.texture = "cubyz:torch", .texture = "cubyz:torch",
.item= .{ .item = .{
.texture = "torch.png", .texture = "torch.png",
}, },
.lodReplacement = "cubyz:air", .lodReplacement = "cubyz:air",

View File

@ -0,0 +1,44 @@
v -0.107468665 0.5625 0.24080175
v 0.114171505 0.5625 0.9573041
v -0.107468665 0.4375 0.24080175
v 0.114171505 0.4375 0.9573041
v 0.011948407 0.4375 0.20386171
v 0.23358858 0.4375 0.92036414
v 0.011948407 0.5625 0.20386171
v 0.23358858 0.5625 0.92036414
vt 0.75 0.0625
vt 0.75 0.25
vt 0.78125 0.0625
vt 0.78125 0.25
vt 0.5 0.0625
vt 0.5 0.25
vt 0.53125 0.0625
vt 0.53125 0.25
vt 0.25 0.3125
vt 0.25 0.5
vt 0.28125 0.3125
vt 0.28125 0.5
vt 0 0.3125
vt 0 0.5
vt 0.03125 0.3125
vt 0.03125 0.5
vt 0 0.03125
vt 0 0.0625
vt 0.03125 0.03125
vt 0.03125 0.0625
vt 0.25 0
vt 0.25 0.03125
vt 0.28125 0
vt 0.28125 0.03125
vn -0.9553365 0 0.29552022
vn 0.9553365 0 -0.29552022
vn 0 -1 0
vn 0 1 0
vn 0.29552022 0 0.9553365
vn -0.29552022 0 -0.9553365
f 2/2/1 1/1/1 3/3/1 4/4/1
f 6/6/2 5/5/2 7/7/2 8/8/2
f 4/10/3 3/9/3 5/11/3 6/12/3
f 8/14/4 7/13/4 1/15/4 2/16/4
f 6/18/5 8/17/5 2/19/5 4/20/5
f 3/22/6 1/21/6 7/23/6 5/24/6

View File

@ -623,7 +623,7 @@ pub const meshes = struct { // MARK: meshes
} }
pub fn register(assetFolder: []const u8, _: []const u8, zon: ZonElement) void { pub fn register(assetFolder: []const u8, _: []const u8, zon: ZonElement) void {
_modelIndex[meshes.size] = _mode[meshes.size].createBlockModel(zon.get([]const u8, "model", "cubyz:cube")); _modelIndex[meshes.size] = _mode[meshes.size].createBlockModel(zon.getChild("model"));
// The actual model is loaded later, in the rendering thread. // The actual model is loaded later, in the rendering thread.
// But textures can be loaded here: // But textures can be loaded here:

View File

@ -10,6 +10,7 @@ const Vec2f = vec.Vec2f;
const Vec3i = vec.Vec3i; const Vec3i = vec.Vec3i;
const Vec3f = vec.Vec3f; const Vec3f = vec.Vec3f;
const Mat4f = vec.Mat4f; const Mat4f = vec.Mat4f;
const ZonElement = main.ZonElement;
const RayIntersectionResult = struct { const RayIntersectionResult = struct {
distance: f64, distance: f64,
@ -29,8 +30,8 @@ pub const RotationMode = struct { // MARK: RotationMode
fn generateData(_: *main.game.World, _: Vec3i, _: Vec3f, _: Vec3f, _: Vec3i, _: ?Neighbor, _: *Block, _: Block, blockPlacing: bool) bool { fn generateData(_: *main.game.World, _: Vec3i, _: Vec3f, _: Vec3f, _: Vec3i, _: ?Neighbor, _: *Block, _: Block, blockPlacing: bool) bool {
return blockPlacing; return blockPlacing;
} }
fn createBlockModel(modelId: []const u8) u16 { fn createBlockModel(zon: ZonElement) u16 {
return main.models.getModelIndex(modelId); return main.models.getModelIndex(zon.as([]const u8, "cubyz:cube"));
} }
fn updateData(_: *Block, _: Neighbor, _: Block) bool { fn updateData(_: *Block, _: Neighbor, _: Block) bool {
return false; return false;
@ -111,7 +112,7 @@ pub const RotationMode = struct { // MARK: RotationMode
model: *const fn(block: Block) u16 = &DefaultFunctions.model, model: *const fn(block: Block) u16 = &DefaultFunctions.model,
createBlockModel: *const fn(modelId: []const u8) u16 = &DefaultFunctions.createBlockModel, createBlockModel: *const fn(zon: ZonElement) u16 = &DefaultFunctions.createBlockModel,
/// Updates the block data of a block in the world or places a block in the world. /// Updates the block data of a block in the world or places a block in the world.
/// return true if the placing was successful, false otherwise. /// return true if the placing was successful, false otherwise.
@ -156,7 +157,8 @@ pub const RotationModes = struct {
rotatedModels.deinit(); rotatedModels.deinit();
} }
pub fn createBlockModel(modelId: []const u8) u16 { pub fn createBlockModel(zon: ZonElement) u16 {
const modelId = zon.as([]const u8, "cubyz:cube");
if(rotatedModels.get(modelId)) |modelIndex| return modelIndex; if(rotatedModels.get(modelId)) |modelIndex| return modelIndex;
const baseModelIndex = main.models.getModelIndex(modelId); const baseModelIndex = main.models.getModelIndex(modelId);
@ -196,7 +198,8 @@ pub const RotationModes = struct {
rotatedModels.deinit(); rotatedModels.deinit();
} }
pub fn createBlockModel(modelId: []const u8) u16 { pub fn createBlockModel(zon: ZonElement) u16 {
const modelId = zon.as([]const u8, "cubyz:cube");
if(rotatedModels.get(modelId)) |modelIndex| return modelIndex; if(rotatedModels.get(modelId)) |modelIndex| return modelIndex;
const baseModelIndex = main.models.getModelIndex(modelId); const baseModelIndex = main.models.getModelIndex(modelId);
@ -276,7 +279,8 @@ pub const RotationModes = struct {
} }
} }
pub fn createBlockModel(modelId: []const u8) u16 { pub fn createBlockModel(zon: ZonElement) u16 {
const modelId = zon.as([]const u8, "cubyz:cube");
if(fenceModels.get(modelId)) |modelIndex| return modelIndex; if(fenceModels.get(modelId)) |modelIndex| return modelIndex;
const baseModelIndex = main.models.getModelIndex(modelId); const baseModelIndex = main.models.getModelIndex(modelId);
@ -370,7 +374,8 @@ pub const RotationModes = struct {
} }
} }
pub fn createBlockModel(modelId: []const u8) u16 { pub fn createBlockModel(zon: ZonElement) u16 {
const modelId = zon.as([]const u8, "cubyz:cube");
if(branchModels.get(modelId)) |modelIndex| return modelIndex; if(branchModels.get(modelId)) |modelIndex| return modelIndex;
const baseModelIndex = main.models.getModelIndex(modelId); const baseModelIndex = main.models.getModelIndex(modelId);
@ -562,7 +567,7 @@ pub const RotationModes = struct {
return mem[0..faces]; return mem[0..faces];
} }
pub fn createBlockModel(_: []const u8) u16 { pub fn createBlockModel(_: ZonElement) u16 {
if(modelIndex != 0) { if(modelIndex != 0) {
return modelIndex; return modelIndex;
} }
@ -802,11 +807,18 @@ pub const RotationModes = struct {
rotatedModels.deinit(); rotatedModels.deinit();
} }
pub fn createBlockModel(modelId: []const u8) u16 { pub fn createBlockModel(zon: ZonElement) u16 {
if(rotatedModels.get(modelId)) |modelIndex| return modelIndex; const baseModelId: []const u8 = zon.get([]const u8, "base", "cubyz:cube");
const sideModelId: []const u8 = zon.get([]const u8, "side", "cubyz:cube");
const key: []const u8 = std.mem.concat(main.stackAllocator.allocator, u8, &.{baseModelId, sideModelId}) catch unreachable;
defer main.stackAllocator.free(key);
const baseModelIndex = main.models.getModelIndex(modelId); if(rotatedModels.get(key)) |modelIndex| return modelIndex;
const baseModelIndex = main.models.getModelIndex(baseModelId);
const baseModel = main.models.models.items[baseModelIndex]; const baseModel = main.models.models.items[baseModelIndex];
const sideModelIndex = main.models.getModelIndex(sideModelId);
const sideModel = main.models.models.items[sideModelIndex];
// Rotate the model: // Rotate the model:
var centerModel: u16 = undefined; var centerModel: u16 = undefined;
var negXModel: u16 = undefined; var negXModel: u16 = undefined;
@ -817,10 +829,10 @@ pub const RotationModes = struct {
const torchData: TorchData = @bitCast(@as(u5, @intCast(i))); const torchData: TorchData = @bitCast(@as(u5, @intCast(i)));
if(i & i - 1 == 0) { if(i & i - 1 == 0) {
if(torchData.center) centerModel = baseModel.transformModel(rotationMatrixTransform, .{Mat4f.identity()}); if(torchData.center) centerModel = baseModel.transformModel(rotationMatrixTransform, .{Mat4f.identity()});
if(torchData.negX) negXModel = baseModel.transformModel(rotationMatrixTransform, .{Mat4f.translation(.{-0.4, 0, 0.2}).mul(Mat4f.rotationY(0.3))}); if(torchData.negX) negXModel = sideModel.transformModel(rotationMatrixTransform, .{Mat4f.rotationZ(0)});
if(torchData.posX) posXModel = baseModel.transformModel(rotationMatrixTransform, .{Mat4f.translation(.{0.4, 0, 0.2}).mul(Mat4f.rotationY(-0.3))}); if(torchData.posX) posXModel = sideModel.transformModel(rotationMatrixTransform, .{Mat4f.rotationZ(std.math.pi)});
if(torchData.negY) negYModel = baseModel.transformModel(rotationMatrixTransform, .{Mat4f.translation(.{0, -0.4, 0.2}).mul(Mat4f.rotationX(-0.3))}); if(torchData.negY) negYModel = sideModel.transformModel(rotationMatrixTransform, .{Mat4f.rotationZ(std.math.pi/2.0)});
if(torchData.posY) posYModel = baseModel.transformModel(rotationMatrixTransform, .{Mat4f.translation(.{0, 0.4, 0.2}).mul(Mat4f.rotationX(0.3))}); if(torchData.posY) posYModel = sideModel.transformModel(rotationMatrixTransform, .{Mat4f.rotationZ(-std.math.pi/2.0)});
} else { } else {
var models: [5]u16 = undefined; var models: [5]u16 = undefined;
var amount: usize = 0; var amount: usize = 0;
@ -848,7 +860,7 @@ pub const RotationModes = struct {
} }
} }
const modelIndex = centerModel; const modelIndex = centerModel;
rotatedModels.put(modelId, modelIndex) catch unreachable; rotatedModels.put(key, modelIndex) catch unreachable;
return modelIndex; return modelIndex;
} }
@ -968,7 +980,8 @@ pub const RotationModes = struct {
rotatedModels.deinit(); rotatedModels.deinit();
} }
pub fn createBlockModel(modelId: []const u8) u16 { pub fn createBlockModel(zon: ZonElement) u16 {
const modelId = zon.as([]const u8, "cubyz:cube");
if(rotatedModels.get(modelId)) |modelIndex| return modelIndex; if(rotatedModels.get(modelId)) |modelIndex| return modelIndex;
const baseModelIndex = main.models.getModelIndex(modelId); const baseModelIndex = main.models.getModelIndex(modelId);
@ -1093,7 +1106,8 @@ pub const RotationModes = struct {
fn init() void {} fn init() void {}
fn deinit() void {} fn deinit() void {}
pub fn createBlockModel(modelId: []const u8) u16 { pub fn createBlockModel(zon: ZonElement) u16 {
const modelId = zon.as([]const u8, "cubyz:cube");
if(!std.mem.eql(u8, modelId, "cubyz:cube")) { if(!std.mem.eql(u8, modelId, "cubyz:cube")) {
std.log.err("Ores can only be use on cube models.", .{modelId}); std.log.err("Ores can only be use on cube models.", .{modelId});
} }