Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scale models and offset height when requested #15

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion src/main/kotlin/cache/loaders/ObjectLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ class ObjectLoader @Inject constructor(
def.blockingMask = inputStream.get().toInt()
} else if (opcode == 70) {
def.offsetX = inputStream.readUnsignedShort()
println("TODO: support offsetX, (got ${def.offsetX})")
} else if (opcode == 71) {
def.offsetHeight = inputStream.readUnsignedShort()
def.offsetHeight = inputStream.readUnsignedShort().toShort().toInt()
} else if (opcode == 72) {
def.offsetY = inputStream.readUnsignedShort()
println("TODO: support offsetY, (got ${def.offsetY})")
} else if (opcode == 73) {
def.obstructsGround = true
} else if (opcode == 74) {
Expand Down
27 changes: 27 additions & 0 deletions src/main/kotlin/controllers/worldRenderer/entities/Model.kt
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,33 @@ class Model(
}
}

fun scaleBy(
x: Int,
y: Int,
z: Int
): Model =
if (x == 128 && y == 128 && z == 128) {
this
} else {
val newDef = ModelDefinition(
modelDefinition,
shallowCopyVerts = false,
shallowCopyFaceColors = true,
shallowCopyFaceTextures = true
)
for (n in 0 until modelDefinition.vertexCount) {
newDef.vertexPositionsX[n] = newDef.vertexPositionsX[n] * x / 128
newDef.vertexPositionsY[n] = newDef.vertexPositionsY[n] * y / 128
newDef.vertexPositionsZ[n] = newDef.vertexPositionsZ[n] * z / 128
}
val model = Model(newDef)
model.faceColors1 = faceColors1
model.faceColors2 = faceColors2
model.faceColors3 = faceColors3
model.resetBounds()
model
}

private fun resetBounds() {
boundsType = 0
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/models/scene/SceneRegionBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ class SceneRegionBuilder @Inject constructor(
// FIXME: nonFlatShading affects fence doors
var model = Model(modelDefinition, objectDefinition.ambient, objectDefinition.contrast)

model = model.scaleBy(objectDefinition.modelSizeX, objectDefinition.modelSizeHeight, objectDefinition.modelSizeY)

if (objectDefinition.contouredGround >= 0) {
model = model.contourGround(
regionLoader,
Expand All @@ -422,7 +424,7 @@ class SceneRegionBuilder @Inject constructor(
)
}

return StaticObject(objectDefinition, model, height, type, orientation)
return StaticObject(objectDefinition, model, height + objectDefinition.offsetHeight, type, orientation)
}

private fun hslToRgb(var0: Int, var1: Int, var2: Int): Int {
Expand Down