Skip to content

Commit

Permalink
Merge pull request #15 from ConnorDY/model-scaling
Browse files Browse the repository at this point in the history
Scale models and offset height when requested
  • Loading branch information
ScoreUnder authored Jul 13, 2022
2 parents 70d31cb + 9602775 commit b404cf7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
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

0 comments on commit b404cf7

Please sign in to comment.