mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-08 11:44:21 -04:00
Add collision for stairs
This commit is contained in:
parent
ea7dec4a01
commit
e736f17c4a
@ -289,7 +289,7 @@ pub fn createBlockModel(_: Block, modeData: *u16, zon: ZonElement) ModelIndex {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const index = main.models.Model.init(quads.items);
|
const index = main.models.Model.init(quads.items, null);
|
||||||
if(i == 0) {
|
if(i == 0) {
|
||||||
modelIndex = index;
|
modelIndex = index;
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ pub fn createBlockModel(_: Block, _: *u16, _: ZonElement) ModelIndex {
|
|||||||
quads.append(rotateQuad(pattern, neighbor));
|
quads.append(rotateQuad(pattern, neighbor));
|
||||||
}
|
}
|
||||||
|
|
||||||
const index = main.models.Model.init(quads.items);
|
const index = main.models.Model.init(quads.items, null);
|
||||||
if(i == 0) {
|
if(i == 0) {
|
||||||
modelIndex = index;
|
modelIndex = index;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ pub fn createBlockModel(_: Block, _: *u16, zon: ZonElement) ModelIndex {
|
|||||||
quadList.items[i + len].textureSlot += 16;
|
quadList.items[i + len].textureSlot += 16;
|
||||||
quadList.items[i].opaqueInLod = 2;
|
quadList.items[i].opaqueInLod = 2;
|
||||||
}
|
}
|
||||||
const modelIndex = main.models.Model.init(quadList.items);
|
const modelIndex = main.models.Model.init(quadList.items, null);
|
||||||
modelCache = modelIndex;
|
modelCache = modelIndex;
|
||||||
return modelIndex;
|
return modelIndex;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,9 @@ const Mat4f = vec.Mat4f;
|
|||||||
const Vec2f = vec.Vec2f;
|
const Vec2f = vec.Vec2f;
|
||||||
const Vec3f = vec.Vec3f;
|
const Vec3f = vec.Vec3f;
|
||||||
const Vec3i = vec.Vec3i;
|
const Vec3i = vec.Vec3i;
|
||||||
|
const Vec3d = vec.Vec3d;
|
||||||
const ZonElement = main.ZonElement;
|
const ZonElement = main.ZonElement;
|
||||||
|
const AABB = main.game.collision.AABB;
|
||||||
|
|
||||||
var modelIndex: ?ModelIndex = null;
|
var modelIndex: ?ModelIndex = null;
|
||||||
|
|
||||||
@ -234,7 +236,26 @@ pub fn createBlockModel(_: Block, _: *u16, _: ZonElement) ModelIndex {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const index = main.models.Model.init(quads.items);
|
var collision = main.globalAllocator.alloc(AABB, 8);
|
||||||
|
var hasBrokenParts = false;
|
||||||
|
for(0..8) |j| {
|
||||||
|
const x: u1 = @intCast(j & 0b001);
|
||||||
|
const y: u1 = @intCast((j & 0b010) >> 1);
|
||||||
|
const z: u1 = @intCast((j & 0b100) >> 2);
|
||||||
|
if(hasSubBlock(@intCast(i), x, y, z)) {
|
||||||
|
const minX = @as(f64, @floatFromInt(x)) * 0.5;
|
||||||
|
const minY = @as(f64, @floatFromInt(y)) * 0.5;
|
||||||
|
const minZ = @as(f64, @floatFromInt(z)) * 0.5;
|
||||||
|
const maxX = minX + 0.5;
|
||||||
|
const maxY = minY + 0.5;
|
||||||
|
const maxZ = minZ + 0.5;
|
||||||
|
|
||||||
|
collision[j] = AABB {.min = Vec3d{minX, minY, minZ}, .max = Vec3d{maxX, maxY, maxZ}};
|
||||||
|
} else {
|
||||||
|
hasBrokenParts = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const index = main.models.Model.init(quads.items, if(hasBrokenParts) collision else null);
|
||||||
if(i == 0) {
|
if(i == 0) {
|
||||||
modelIndex = index;
|
modelIndex = index;
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ pub const Model = struct {
|
|||||||
return @popCount(@as(u3, @bitCast(hasTwoOnes))) == 2 and @popCount(@as(u3, @bitCast(hasTwoZeroes))) == 2;
|
return @popCount(@as(u3, @bitCast(hasTwoOnes))) == 2 and @popCount(@as(u3, @bitCast(hasTwoZeroes))) == 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(quadInfos: []const QuadInfo) ModelIndex {
|
pub fn init(quadInfos: []const QuadInfo, collision: ?[]AABB) ModelIndex {
|
||||||
const adjustedQuads = main.stackAllocator.alloc(QuadInfo, quadInfos.len);
|
const adjustedQuads = main.stackAllocator.alloc(QuadInfo, quadInfos.len);
|
||||||
defer main.stackAllocator.free(adjustedQuads);
|
defer main.stackAllocator.free(adjustedQuads);
|
||||||
for(adjustedQuads, quadInfos) |*dest, *src| {
|
for(adjustedQuads, quadInfos) |*dest, *src| {
|
||||||
@ -197,8 +197,12 @@ pub const Model = struct {
|
|||||||
self.allNeighborsOccluded = self.allNeighborsOccluded and self.isNeighborOccluded[neighbor];
|
self.allNeighborsOccluded = self.allNeighborsOccluded and self.isNeighborOccluded[neighbor];
|
||||||
self.noNeighborsOccluded = self.noNeighborsOccluded and !self.isNeighborOccluded[neighbor];
|
self.noNeighborsOccluded = self.noNeighborsOccluded and !self.isNeighborOccluded[neighbor];
|
||||||
}
|
}
|
||||||
self.collision = main.globalAllocator.alloc(AABB, 1);
|
if(collision)|realCollision| {
|
||||||
self.collision[0] = AABB {.min = @floatCast(self.min), .max = @floatCast(self.max)};
|
self.collision = realCollision;
|
||||||
|
} else {
|
||||||
|
self.collision = main.globalAllocator.alloc(AABB, 1);
|
||||||
|
self.collision[0] = AABB {.min = @floatCast(self.min), .max = @floatCast(self.max)};
|
||||||
|
}
|
||||||
|
|
||||||
return modelIndex;
|
return modelIndex;
|
||||||
}
|
}
|
||||||
@ -235,7 +239,7 @@ pub const Model = struct {
|
|||||||
quad.cornerUV[i] = @as(Vec2f, quad.cornerUV[i]) - minUv;
|
quad.cornerUV[i] = @as(Vec2f, quad.cornerUV[i]) - minUv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Model.init(quadInfos);
|
return Model.init(quadInfos, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn loadRawModelDataFromObj(allocator: main.heap.NeverFailingAllocator, data: []const u8) []QuadInfo {
|
pub fn loadRawModelDataFromObj(allocator: main.heap.NeverFailingAllocator, data: []const u8) []QuadInfo {
|
||||||
@ -415,7 +419,7 @@ pub const Model = struct {
|
|||||||
for(modelList) |model| {
|
for(modelList) |model| {
|
||||||
model.model().getRawFaces(&quadList);
|
model.model().getRawFaces(&quadList);
|
||||||
}
|
}
|
||||||
return Model.init(quadList.items);
|
return Model.init(quadList.items, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn transformModel(model: Model, transformFunction: anytype, transformFunctionParameters: anytype) ModelIndex {
|
pub fn transformModel(model: Model, transformFunction: anytype, transformFunctionParameters: anytype) ModelIndex {
|
||||||
@ -425,7 +429,7 @@ pub const Model = struct {
|
|||||||
for(quadList.items) |*quad| {
|
for(quadList.items) |*quad| {
|
||||||
@call(.auto, transformFunction, .{quad} ++ transformFunctionParameters);
|
@call(.auto, transformFunction, .{quad} ++ transformFunctionParameters);
|
||||||
}
|
}
|
||||||
return Model.init(quadList.items);
|
return Model.init(quadList.items, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn appendQuadsToList(quadList: []const QuadIndex, list: *main.ListUnmanaged(FaceData), allocator: NeverFailingAllocator, block: main.blocks.Block, x: i32, y: i32, z: i32, comptime backFace: bool) void {
|
fn appendQuadsToList(quadList: []const QuadIndex, list: *main.ListUnmanaged(FaceData), allocator: NeverFailingAllocator, block: main.blocks.Block, x: i32, y: i32, z: i32, comptime backFace: bool) void {
|
||||||
@ -581,7 +585,7 @@ pub fn init() void {
|
|||||||
|
|
||||||
nameToIndex = .init(main.globalAllocator.allocator);
|
nameToIndex = .init(main.globalAllocator.allocator);
|
||||||
|
|
||||||
nameToIndex.put("none", Model.init(&.{})) catch unreachable;
|
nameToIndex.put("none", Model.init(&.{}, null)) catch unreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset() void {
|
pub fn reset() void {
|
||||||
@ -593,7 +597,7 @@ pub fn reset() void {
|
|||||||
extraQuadInfos.clearRetainingCapacity();
|
extraQuadInfos.clearRetainingCapacity();
|
||||||
quadDeduplication.clearRetainingCapacity();
|
quadDeduplication.clearRetainingCapacity();
|
||||||
nameToIndex.clearRetainingCapacity();
|
nameToIndex.clearRetainingCapacity();
|
||||||
nameToIndex.put("none", Model.init(&.{})) catch unreachable;
|
nameToIndex.put("none", Model.init(&.{}, null)) catch unreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit() void {
|
pub fn deinit() void {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user