pushed model rendering into individual model parts
This commit is contained in:
parent
8129b5547c
commit
8127ed0011
3 changed files with 87 additions and 56 deletions
|
@ -21,12 +21,25 @@ object ArmorModel {
|
|||
class ArmorModel(par1: Float, par2: Float, par3: Int, par4: Int) extends ModelPlayer(0.0F) {
|
||||
var renderSpec: NBTTagCompound = null
|
||||
var visible: Int = 0
|
||||
bipedHeadwear.showModel = false
|
||||
bipedHead = new RenderPart(this)
|
||||
bipedBody = new RenderPart(this)
|
||||
bipedRightArm = new RenderPart(this)
|
||||
bipedLeftArm = new RenderPart(this)
|
||||
bipedRightLeg = new RenderPart(this)
|
||||
bipedLeftLeg = new RenderPart(this)
|
||||
setInitialOffsets(bipedHead, 0.0F, 0.0F + par2, 0.0F)
|
||||
setInitialOffsets(bipedBody, 0.0F, 0.0F + par2, 0.0F)
|
||||
setInitialOffsets(bipedRightArm, 5, 2.0F + par2, 0.0F)
|
||||
setInitialOffsets(bipedLeftArm, -5, 2.0F + par2, 0.0F)
|
||||
setInitialOffsets(bipedRightLeg, 2, 12.0F + par2, 0.0F)
|
||||
setInitialOffsets(bipedLeftLeg, -2, 12.0F + par2, 0.0F)
|
||||
this.bipedHead.setRotationPoint(0.0F, 0.0F + par2, 0.0F)
|
||||
this.bipedBody.setRotationPoint(0.0F, 0.0F + par2, 0.0F)
|
||||
this.bipedRightArm.setRotationPoint(-5.0F, 2.0F + par2, 0.0F)
|
||||
this.bipedLeftArm.setRotationPoint(5.0F, 2.0F + par2, 0.0F)
|
||||
this.bipedRightLeg.setRotationPoint(-1.9F, 12.0F + par2, 0.0F)
|
||||
this.bipedLeftLeg.setRotationPoint(1.9F, 12.0F + par2, 0.0F)
|
||||
|
||||
private def logModelParts(model: WavefrontObject) {
|
||||
MuseLogger.logDebug(model.toString + ":")
|
||||
|
@ -56,17 +69,22 @@ class ArmorModel(par1: Float, par2: Float, par3: Int, par4: Int) extends ModelPl
|
|||
} catch {
|
||||
case _: Exception =>
|
||||
}
|
||||
this.setRotationAngles(par2, par3, par4, par5, par6, scale, entity)
|
||||
|
||||
bipedHead.isHidden = false
|
||||
bipedBody.isHidden = false
|
||||
bipedRightArm.isHidden = false
|
||||
bipedLeftArm.isHidden = false
|
||||
bipedRightLeg.isHidden = false
|
||||
bipedLeftLeg.isHidden = false
|
||||
|
||||
bipedHead.showModel = true
|
||||
bipedBody.showModel = true
|
||||
bipedRightArm.showModel = true
|
||||
bipedLeftArm.showModel = true
|
||||
bipedRightLeg.showModel = true
|
||||
bipedLeftLeg.showModel = true
|
||||
|
||||
setRotationAngles(par2, par3, par4, par5, par6, scale, entity)
|
||||
super.render(entity, par2, par3, par4, par5, par6, scale)
|
||||
|
||||
|
||||
glPushMatrix()
|
||||
glScaled(scale, scale, scale)
|
||||
import scala.collection.JavaConverters._
|
||||
val colours = renderSpec.getIntArray("colours")
|
||||
for (tag <- NBTTagAccessor.getValues(renderSpec).asScala) {
|
||||
RenderPart(tag, colours, this, visible)
|
||||
}
|
||||
glPopMatrix()
|
||||
}
|
||||
}
|
|
@ -10,58 +10,49 @@ import org.lwjgl.opengl.GL11._
|
|||
|
||||
sealed trait MorphTarget {
|
||||
val name: String
|
||||
val degrad = (180F / Math.PI.asInstanceOf[Float])
|
||||
val degrad = 180F / Math.PI.asInstanceOf[Float]
|
||||
|
||||
def apply(m: ModelBiped): ModelRenderer
|
||||
|
||||
def applyTransform(m: ModelRenderer) = {
|
||||
glTranslatef(m.rotationPointX, m.rotationPointY, m.rotationPointZ)
|
||||
glRotatef(m.rotateAngleZ * degrad, 0.0F, 0.0F, 1.0F)
|
||||
glRotatef(m.rotateAngleY * degrad, 0.0F, 1.0F, 0.0F)
|
||||
glRotatef(m.rotateAngleX * degrad + 180, 1.0F, 0.0F, 0.0F)
|
||||
glTranslated(m.field_82906_o, m.field_82907_q - 26, m.field_82908_p)
|
||||
m
|
||||
}
|
||||
}
|
||||
|
||||
case object Cloak extends MorphTarget {
|
||||
val name = "Cloak"
|
||||
|
||||
def apply(m: ModelBiped) = applyTransform(m.bipedCloak)
|
||||
def apply(m: ModelBiped) = m.bipedCloak
|
||||
}
|
||||
|
||||
case object Head extends MorphTarget {
|
||||
val name = "Head"
|
||||
|
||||
def apply(m: ModelBiped) = applyTransform(m.bipedHead)
|
||||
def apply(m: ModelBiped) = m.bipedHead
|
||||
}
|
||||
|
||||
case object Body extends MorphTarget {
|
||||
val name = "Body"
|
||||
|
||||
def apply(m: ModelBiped) = applyTransform(m.bipedBody)
|
||||
def apply(m: ModelBiped) = m.bipedBody
|
||||
}
|
||||
|
||||
case object RightArm extends MorphTarget {
|
||||
val name = "RightArm"
|
||||
|
||||
def apply(m: ModelBiped) = applyTransform(m.bipedRightArm)
|
||||
def apply(m: ModelBiped) = m.bipedRightArm
|
||||
}
|
||||
|
||||
case object LeftArm extends MorphTarget {
|
||||
val name = "LeftArm"
|
||||
|
||||
def apply(m: ModelBiped) = applyTransform(m.bipedLeftArm)
|
||||
def apply(m: ModelBiped) = m.bipedLeftArm
|
||||
}
|
||||
|
||||
case object RightLeg extends MorphTarget {
|
||||
val name = "RightLeg"
|
||||
|
||||
def apply(m: ModelBiped) = applyTransform(m.bipedRightLeg)
|
||||
def apply(m: ModelBiped) = m.bipedRightLeg
|
||||
}
|
||||
|
||||
case object LeftLeg extends MorphTarget {
|
||||
val name = "LeftLeg"
|
||||
|
||||
def apply(m: ModelBiped) = applyTransform(m.bipedLeftLeg)
|
||||
def apply(m: ModelBiped) = m.bipedLeftLeg
|
||||
}
|
|
@ -5,42 +5,64 @@ import net.minecraft.client.Minecraft
|
|||
import net.machinemuse.powersuits.client.render.item.ArmorModel
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.machinemuse.utils.render.Render
|
||||
import net.minecraft.client.model.{ModelBase, ModelRenderer}
|
||||
import net.machinemuse.general.NBTTagAccessor
|
||||
import org.lwjgl.opengl.GL11._
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
/**
|
||||
* Author: MachineMuse (Claire Semple)
|
||||
* Created: 4:16 AM, 29/04/13
|
||||
*/
|
||||
object RenderPart {
|
||||
def apply(nbt: NBTTagCompound, c: Array[Int], m: ArmorModel, slot: Int) {
|
||||
//MuseLogger.logDebug("rendering model " + nbt.getString("model") + ":" + nbt.getString("part"))
|
||||
ModelRegistry.getPart(nbt).map(f = part => {
|
||||
if (part.slot == slot) {
|
||||
val withMaybeGlow = if (part.getGlow(nbt)) {
|
||||
a: Render[_] => Render withGlow a
|
||||
} else {
|
||||
a: Render[_] => a
|
||||
}
|
||||
|
||||
withMaybeGlow {
|
||||
Render.withPushedMatrix {
|
||||
Render pure {
|
||||
try {
|
||||
Minecraft.getMinecraft.renderEngine.bindTexture(part.getTexture(nbt))
|
||||
part.morph(m)
|
||||
val ix = part.getColourIndex(nbt)
|
||||
if (ix < c.size) {
|
||||
Colour.doGLByInt(c(ix))
|
||||
class RenderPart(base: ModelBase) extends ModelRenderer(base) {
|
||||
override def render(par1: Float) {
|
||||
val renderSpec = ArmorModel.instance.renderSpec
|
||||
import scala.collection.JavaConverters._
|
||||
val colours = renderSpec.getIntArray("colours")
|
||||
|
||||
for (nbt <- NBTTagAccessor.getValues(renderSpec).asScala) {
|
||||
ModelRegistry.getPart(nbt).map(part => {
|
||||
if (part.slot == ArmorModel.instance.visible && part.morph.apply(ArmorModel.instance) == this) {
|
||||
withMaybeGlow(part, nbt) {
|
||||
Render.withPushedMatrix {
|
||||
Render pure {
|
||||
GL11.glScaled(par1, par1, par1)
|
||||
try {
|
||||
Minecraft.getMinecraft.renderEngine.bindTexture(part.getTexture(nbt))
|
||||
applyTransform
|
||||
val ix = part.getColourIndex(nbt)
|
||||
if (ix < colours.size) {
|
||||
Colour.doGLByInt(colours(ix))
|
||||
}
|
||||
part.modelSpec.applyOffsetAndRotation // not yet implemented
|
||||
part.modelSpec.model.renderPart(part.partName)
|
||||
Colour.WHITE.doGL()
|
||||
} catch {
|
||||
case e: Throwable =>
|
||||
}
|
||||
part.modelSpec.applyOffsetAndRotation
|
||||
part.modelSpec.model.renderPart(part.partName)
|
||||
Colour.WHITE.doGL()
|
||||
} catch {
|
||||
case e: Throwable =>
|
||||
}
|
||||
}
|
||||
}
|
||||
}.run()
|
||||
}
|
||||
})
|
||||
}.run()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
val degrad = 180F / Math.PI.asInstanceOf[Float]
|
||||
|
||||
def withMaybeGlow(part: ModelPartSpec, nbt: NBTTagCompound) = if (part.getGlow(nbt)) {
|
||||
a: Render[_] => Render withGlow a
|
||||
} else {
|
||||
a: Render[_] => a
|
||||
}
|
||||
|
||||
def applyTransform {
|
||||
glTranslatef(rotationPointX, rotationPointY, rotationPointZ)
|
||||
glRotatef(rotateAngleZ * degrad, 0.0F, 0.0F, 1.0F)
|
||||
glRotatef(rotateAngleY * degrad, 0.0F, 1.0F, 0.0F)
|
||||
glRotatef(rotateAngleX * degrad + 180, 1.0F, 0.0F, 0.0F)
|
||||
glTranslated(field_82906_o, field_82907_q - 26, field_82908_p)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue