From ea8324bd5785acd0644a65e57250afd6df27ad46 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Fri, 27 Dec 2024 10:29:25 -0800 Subject: [PATCH] Wind Waker: Make LegacyActor use dCamera_c for globals Keep around the J3DModelInstanceSimple for now, just render it using mDoExt_modelUpdateDL --- src/Common/JSYSTEM/J3D/J3DGraphBase.ts | 3 - src/ZeldaTwilightPrincess/m_do_ext.ts | 2 +- src/ZeldaWindWaker/LegacyActor.ts | 17 ++--- src/ZeldaWindWaker/d_a.ts | 86 +++++++++++++------------- src/ZeldaWindWaker/d_kankyo_wether.ts | 2 +- src/ZeldaWindWaker/m_do_ext.ts | 13 ++-- 6 files changed, 57 insertions(+), 66 deletions(-) diff --git a/src/Common/JSYSTEM/J3D/J3DGraphBase.ts b/src/Common/JSYSTEM/J3D/J3DGraphBase.ts index 77d25b2be..6235b8a79 100644 --- a/src/Common/JSYSTEM/J3D/J3DGraphBase.ts +++ b/src/Common/JSYSTEM/J3D/J3DGraphBase.ts @@ -1105,9 +1105,6 @@ export class J3DModelInstance { if (cullFrustum === null || disableCulling || jnt1.joints[i].bbox.isEmpty()) { this.jointVisibility[i] = true; } else { - // Frustum cull. - // Note to future self: joint bboxes do *not* contain their child joints (see: trees in Super Mario Sunshine). - // You *cannot* use PARTIAL_INTERSECTION to optimize frustum culling. bboxScratch.transform(jnt1.joints[i].bbox, jointToWorldMatrix); this.jointVisibility[i] = cullFrustum.contains(bboxScratch); } diff --git a/src/ZeldaTwilightPrincess/m_do_ext.ts b/src/ZeldaTwilightPrincess/m_do_ext.ts index 0d10deae6..d2f02a095 100644 --- a/src/ZeldaTwilightPrincess/m_do_ext.ts +++ b/src/ZeldaTwilightPrincess/m_do_ext.ts @@ -288,6 +288,6 @@ export class mDoExt_morf_c implements JointMatrixCalc { } public entryDL(globals: dGlobals, renderInstManager: GfxRenderInstManager, viewerInput: ViewerRenderInput, drawListSet: dDlst_list_Set | null = null): void { - mDoExt_modelEntryDL(globals, this.model, renderInstManager, viewerInput); + mDoExt_modelEntryDL(globals, this.model, renderInstManager, viewerInput, drawListSet); } } diff --git a/src/ZeldaWindWaker/LegacyActor.ts b/src/ZeldaWindWaker/LegacyActor.ts index c27b957f5..c37065bf3 100644 --- a/src/ZeldaWindWaker/LegacyActor.ts +++ b/src/ZeldaWindWaker/LegacyActor.ts @@ -20,7 +20,7 @@ import { dProcName_e } from './d_procname.js'; import { ResAssetType, ResEntry, ResType } from './d_resorce.js'; import { fopAcM_prm_class, fopAc_ac_c } from './f_op_actor.js'; import { cPhs__Status, fGlobals, fpcPf__RegisterFallback } from './framework.js'; -import { mDoExt_McaMorf, mDoExt_modelEntryDL } from './m_do_ext.js'; +import { mDoExt_McaMorf, mDoExt_modelEntryDL, mDoExt_modelUpdateDL } from './m_do_ext.js'; import { MtxTrans, calc_mtx, mDoMtx_ZXYrotM } from './m_do_mtx.js'; import { WindWakerRenderer, ZWWExtraTextures, dGlobals } from "./Main.js"; @@ -1813,7 +1813,7 @@ function spawnLegacyActor(globals: dGlobals, legacy: d_a_noclip_legacy, actor: f // Special-case actors -export class BMDObjectRenderer { +class BMDObjectRenderer { public visible = true; public modelMatrix: mat4 = mat4.create(); public lightTevColorType = LightType.Actor; @@ -1851,13 +1851,6 @@ export class BMDObjectRenderer { this.modelInstance.setMaterialColorWriteEnabled(materialName, v); } - private setExtraTextures(extraTextures: ZWWExtraTextures): void { - extraTextures.fillExtraTextures(this.modelInstance); - - for (let i = 0; i < this.childObjects.length; i++) - this.childObjects[i].setExtraTextures(extraTextures); - } - public prepareToRender(globals: dGlobals, morf: mDoExt_McaMorf | null, device: GfxDevice, renderInstManager: GfxRenderInstManager, viewerInput: Viewer.ViewerRenderInput): void { if (!this.visible) return; @@ -1879,10 +1872,10 @@ export class BMDObjectRenderer { if (morf) { morf.calc(); - morf.entryDL(globals, renderInstManager, viewerInput); + morf.entryDL(globals, renderInstManager); } else { - this.setExtraTextures(globals.renderer.extraTextures); - this.modelInstance.prepareToRender(device, renderInstManager, viewerInput); + this.modelInstance.animationController.setTimeInMilliseconds(viewerInput.time); + mDoExt_modelUpdateDL(globals, this.modelInstance, renderInstManager); } for (let i = 0; i < this.childObjects.length; i++) diff --git a/src/ZeldaWindWaker/d_a.ts b/src/ZeldaWindWaker/d_a.ts index 1b105d419..c797dbc11 100644 --- a/src/ZeldaWindWaker/d_a.ts +++ b/src/ZeldaWindWaker/d_a.ts @@ -268,7 +268,7 @@ class d_a_ep extends fopAc_ac_c { if (this.type === 0 || this.type === 3) { settingTevStruct(globals, LightType.BG0, this.pos, this.tevStr); setLightTevColorType(globals, this.model, this.tevStr, globals.camera); - mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput); + mDoExt_modelUpdateDL(globals, this.model, renderInstManager); // TODO(jstpierre): ga } @@ -512,7 +512,7 @@ class d_a_bg extends fopAc_ac_c { settingTevStruct(globals, LightType.BG0 + i, null, this.bgTevStr[i]!); setLightTevColorType(globals, this.bgModel[i]!, this.bgTevStr[i]!, globals.camera); // this is actually mDoExt_modelEntryDL - mDoExt_modelUpdateDL(globals, this.bgModel[i]!, renderInstManager, viewerInput); + mDoExt_modelUpdateDL(globals, this.bgModel[i]!, renderInstManager); } const roomNo = this.parameters; @@ -626,7 +626,7 @@ class d_a_vrbox extends fopAc_ac_c { mat4.copy(this.model.modelMatrix, calc_mtx); dKy_setLight__OnModelInstance(envLight, this.model, globals.camera); - mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput, globals.dlst.sky); + mDoExt_modelUpdateDL(globals, this.model, renderInstManager, globals.dlst.sky); } } @@ -743,17 +743,17 @@ class d_a_vrbox2 extends fopAc_ac_c { if (this.usoUmi !== null) { mat4.copy(this.usoUmi.modelMatrix, calc_mtx); - mDoExt_modelUpdateDL(globals, this.usoUmi, renderInstManager, viewerInput, globals.dlst.sky); + mDoExt_modelUpdateDL(globals, this.usoUmi, renderInstManager, globals.dlst.sky); } if (this.kasumiMae !== null) { mat4.copy(this.kasumiMae.modelMatrix, calc_mtx); - mDoExt_modelUpdateDL(globals, this.kasumiMae, renderInstManager, viewerInput, globals.dlst.sky); + mDoExt_modelUpdateDL(globals, this.kasumiMae, renderInstManager, globals.dlst.sky); } calc_mtx[13] += 100.0; mat4.copy(this.backCloud.modelMatrix, calc_mtx); - mDoExt_modelUpdateDL(globals, this.backCloud, renderInstManager, viewerInput, globals.dlst.sky); + mDoExt_modelUpdateDL(globals, this.backCloud, renderInstManager, globals.dlst.sky); } } @@ -1086,7 +1086,7 @@ class d_a_obj_Ygush00 extends fopAc_ac_c { this.btkAnm.entry(this.model); this.bckAnm.entry(this.model); - mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput); + mDoExt_modelUpdateDL(globals, this.model, renderInstManager); } } @@ -1174,7 +1174,7 @@ class d_a_obj_lpalm extends fopAc_ac_c { settingTevStruct(globals, LightType.BG0, this.pos, this.tevStr); setLightTevColorType(globals, this.model, this.tevStr, globals.camera); - mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput); + mDoExt_modelUpdateDL(globals, this.model, renderInstManager); } } @@ -1260,7 +1260,7 @@ class d_a_obj_zouK extends fopAc_ac_c { setLightTevColorType(globals, this.model, this.tevStr, globals.camera); this.setEffectMtx(globals, this.pos, 0.5); this.bckAnm.entry(this.model); - mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput); + mDoExt_modelUpdateDL(globals, this.model, renderInstManager); } } @@ -1314,7 +1314,7 @@ class d_a_swhit0 extends fopAc_ac_c { this.model.setColorOverride(ColorKind.C2, d_a_swhit0.color2Normal); this.bckAnm.entry(this.model); this.btkAnm.entry(this.model); - mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput); + mDoExt_modelUpdateDL(globals, this.model, renderInstManager); } } @@ -1511,8 +1511,7 @@ class dDlst_2DObject_c extends dDlst_2DBase_c { super(); } - public draw(globals: dGlobals, renderInstManager: GfxRenderInstManager, viewerInput: ViewerRenderInput): void { - const device = globals.modelCache.device; + public draw(globals: dGlobals, renderInstManager: GfxRenderInstManager): void { const renderInst = renderInstManager.newRenderInst(); globals.quadStatic.setOnRenderInst(renderInst); @@ -1552,8 +1551,7 @@ class dDlst_2DNumber_c extends dDlst_2DBase_c { return cPhs__Status.Complete; } - public draw(globals: dGlobals, renderInstManager: GfxRenderInstManager, viewerInput: ViewerRenderInput): void { - const device = globals.modelCache.device; + public draw(globals: dGlobals, renderInstManager: GfxRenderInstManager): void { const template = renderInstManager.pushTemplate(); globals.quadStatic.setOnRenderInst(template); @@ -1967,24 +1965,24 @@ class d_a_mgameboard extends fopAc_ac_c { settingTevStruct(globals, LightType.Actor, this.pos, this.tevStr); setLightTevColorType(globals, this.boardModel, this.tevStr, globals.camera); - mDoExt_modelUpdateDL(globals, this.boardModel, renderInstManager, viewerInput); + mDoExt_modelUpdateDL(globals, this.boardModel, renderInstManager); if (!this.minigameActive) return; setLightTevColorType(globals, this.cursorModel, this.tevStr, globals.camera); - mDoExt_modelUpdateDL(globals, this.cursorModel, renderInstManager, viewerInput, globals.dlst.ui); + mDoExt_modelUpdateDL(globals, this.cursorModel, renderInstManager, globals.dlst.ui); for (let i = 0; i < this.hitModelCount; i++) { const model = this.hitModels[i]; setLightTevColorType(globals, model, this.tevStr, globals.camera); - mDoExt_modelUpdateDL(globals, model, renderInstManager, viewerInput, globals.dlst.ui); + mDoExt_modelUpdateDL(globals, model, renderInstManager, globals.dlst.ui); } for (let i = 0; i < this.missModelCount; i++) { const model = this.missModels[i]; setLightTevColorType(globals, model, this.tevStr, globals.camera); - mDoExt_modelUpdateDL(globals, model, renderInstManager, viewerInput, globals.dlst.ui); + mDoExt_modelUpdateDL(globals, model, renderInstManager, globals.dlst.ui); } // Show ships after the game ends. @@ -1992,19 +1990,19 @@ class d_a_mgameboard extends fopAc_ac_c { for (let i = 0; i < this.minigame.ships.length; i++) { const model = this.shipModels[i]; setLightTevColorType(globals, model, this.tevStr, globals.camera); - mDoExt_modelUpdateDL(globals, model, renderInstManager, viewerInput, globals.dlst.ui); + mDoExt_modelUpdateDL(globals, model, renderInstManager, globals.dlst.ui); } } renderInstManager.setCurrentList(globals.dlst.ui[1]); for (let i = 0; i < this.bullet.length; i++) - this.bullet[i].draw(globals, renderInstManager, viewerInput); + this.bullet[i].draw(globals, renderInstManager); for (let i = 0; i < this.squid.length; i++) - this.squid[i].draw(globals, renderInstManager, viewerInput); - this.scoreNum.draw(globals, renderInstManager, viewerInput); - this.highscoreNum.draw(globals, renderInstManager, viewerInput); - this.highscoreLabel.draw(globals, renderInstManager, viewerInput); - this.highscorePad.draw(globals, renderInstManager, viewerInput); + this.squid[i].draw(globals, renderInstManager); + this.scoreNum.draw(globals, renderInstManager); + this.highscoreNum.draw(globals, renderInstManager); + this.highscoreLabel.draw(globals, renderInstManager); + this.highscorePad.draw(globals, renderInstManager); } } @@ -2280,7 +2278,7 @@ class dCloth_packet_c { renderInstManager.submitRenderInst(renderInst); } - public cloth_draw(globals: dGlobals, renderInstManager: GfxRenderInstManager, viewerInput: ViewerRenderInput): void { + public cloth_draw(globals: dGlobals, renderInstManager: GfxRenderInstManager): void { /* const ctx = getDebugOverlayCanvas2D(); @@ -2382,8 +2380,8 @@ class d_a_sie_flag extends fopAc_ac_c { settingTevStruct(globals, LightType.BG0, this.pos, this.tevStr); settingTevStruct(globals, LightType.Actor, this.pos, this.clothTevStr); setLightTevColorType(globals, this.model, this.tevStr, globals.camera); - mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput); - this.cloth.cloth_draw(globals, renderInstManager, viewerInput); + mDoExt_modelUpdateDL(globals, this.model, renderInstManager); + this.cloth.cloth_draw(globals, renderInstManager); } public override execute(globals: dGlobals, deltaTimeFrames: number): void { @@ -2468,8 +2466,8 @@ class d_a_tori_flag extends fopAc_ac_c { settingTevStruct(globals, LightType.BG0, this.pos, this.tevStr); settingTevStruct(globals, LightType.Actor, this.pos, this.clothTevStr); setLightTevColorType(globals, this.model, this.tevStr, globals.camera); - mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput); - this.cloth.cloth_draw(globals, renderInstManager, viewerInput); + mDoExt_modelUpdateDL(globals, this.model, renderInstManager); + this.cloth.cloth_draw(globals, renderInstManager); } public override execute(globals: dGlobals, deltaTimeFrames: number): void { @@ -3188,7 +3186,7 @@ class d_a_kamome extends fopAc_ac_c { settingTevStruct(globals, LightType.Actor, this.pos, this.tevStr); setLightTevColorType(globals, this.morf.model, this.tevStr, globals.camera); - this.morf.entryDL(globals, renderInstManager, viewerInput); + this.morf.entryDL(globals, renderInstManager); // drawWorldSpaceLine(getDebugOverlayCanvas2D(), globals.camera.clipFromWorldMatrix, this.pos, this.targetPos, Green, 2); // drawWorldSpacePoint(getDebugOverlayCanvas2D(), globals.camera.clipFromWorldMatrix, this.pos, Magenta, 8); @@ -3447,7 +3445,7 @@ class d_a_obj_ikada extends fopAc_ac_c implements ModeFuncExec { setLightTevColorType(globals, this.model, this.tevStr, globals.camera); const specScale = 0.75; dDlst_texSpecmapST(this.effectMtx, globals, this.pos, this.tevStr, specScale); - mDoExt_modelEntryDL(globals, this.model, renderInstManager, viewerInput); + mDoExt_modelEntryDL(globals, this.model, renderInstManager); /* drawWorldSpaceText(getDebugOverlayCanvas2D(), globals.camera.clipFromWorldMatrix, this.pos, `PId: ${this.processId}`, 0, White, { outline: 2 }); @@ -4251,7 +4249,7 @@ class d_a_obj_flame extends fopAc_ac_c { if (this.brkAnm !== null) this.brkAnm.entry(this.model); - mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput, globals.dlst.wetherEffectSet); + mDoExt_modelUpdateDL(globals, this.model, renderInstManager, globals.dlst.wetherEffectSet); } private mode_wait(globals: dGlobals): void { @@ -4707,13 +4705,13 @@ export class d_a_ff extends fopAc_ac_c { MtxTrans(this.pos, false); scaleMatrix(calc_mtx, calc_mtx, this.flyScale); mat4.copy(this.model[0].modelMatrix, calc_mtx); - mDoExt_modelUpdateDL(globals, this.model[0], renderInstManager, viewerInput, globals.dlst.effect); + mDoExt_modelUpdateDL(globals, this.model[0], renderInstManager, globals.dlst.effect); if (this.glowScale > 0.01) { mDoMtx_YrotM(calc_mtx, this.liveTimer * 0x0100); scaleMatrix(calc_mtx, calc_mtx, this.glowScale, this.glowScale * this.glowScaleY, this.glowScale); mat4.copy(this.model[1].modelMatrix, calc_mtx); - mDoExt_modelUpdateDL(globals, this.model[1], renderInstManager, viewerInput, globals.dlst.effect); + mDoExt_modelUpdateDL(globals, this.model[1], renderInstManager, globals.dlst.effect); } } } @@ -4803,13 +4801,13 @@ class d_a_npc_ls1 extends fopNpc_npc_c { // this.btkAnim.entry(this.morf.model, this.btkFrame); // this.btpAnim.entry(this.morf.model, this.btpFrame); - this.morf.entryDL(globals, renderInstManager, viewerInput); + this.morf.entryDL(globals, renderInstManager); - mDoExt_modelEntryDL(globals, this.handModel, renderInstManager, viewerInput); + mDoExt_modelEntryDL(globals, this.handModel, renderInstManager); if (this.itemModel) { setLightTevColorType(globals, this.itemModel, this.tevStr, globals.camera); - mDoExt_modelEntryDL(globals, this.itemModel, renderInstManager, viewerInput); + mDoExt_modelEntryDL(globals, this.itemModel, renderInstManager); } this.drawShadow(); @@ -5036,7 +5034,7 @@ class d_a_npc_zl1 extends fopNpc_npc_c { if (this.btpAnim.anm) this.btpAnim.entry(this.morf.model); if (this.btkAnim.anm) this.btkAnim.entry(this.morf.model); - this.morf.entryDL(globals, renderInstManager, viewerInput); + this.morf.entryDL(globals, renderInstManager); } public override execute(globals: dGlobals, deltaTimeFrames: number): void { @@ -5303,15 +5301,15 @@ class d_a_py_lk extends fopAc_ac_c implements ModeFuncExec { this.model.setShapeVisible(LkModelShape.Buckle, false); setLightTevColorType(globals, this.modelKatsura, this.tevStr, globals.camera); - mDoExt_modelEntryDL(globals, this.modelKatsura, renderInstManager, viewerInput); + mDoExt_modelEntryDL(globals, this.modelKatsura, renderInstManager); } if (this.equippedItem === LkEquipItem.Sword) { setLightTevColorType(globals, this.equippedItemModel!, this.tevStr, globals.camera); - mDoExt_modelEntryDL(globals, this.equippedItemModel!, renderInstManager, viewerInput); + mDoExt_modelEntryDL(globals, this.equippedItemModel!, renderInstManager); setLightTevColorType(globals, this.modelSwordHilt, this.tevStr, globals.camera); - mDoExt_modelEntryDL(globals, this.modelSwordHilt, renderInstManager, viewerInput); + mDoExt_modelEntryDL(globals, this.modelSwordHilt, renderInstManager); } // TODO: @@ -5326,7 +5324,7 @@ class d_a_py_lk extends fopAc_ac_c implements ModeFuncExec { if (this.anmBtk.anm) this.anmBtk.entry(this.model); setLightTevColorType(globals, this.model, this.tevStr, globals.camera); - mDoExt_modelEntryDL(globals, this.model, renderInstManager, viewerInput); + mDoExt_modelEntryDL(globals, this.model, renderInstManager); } private playerInit(globals: dGlobals) { diff --git a/src/ZeldaWindWaker/d_kankyo_wether.ts b/src/ZeldaWindWaker/d_kankyo_wether.ts index a1ddf85ff..e6b18b9be 100644 --- a/src/ZeldaWindWaker/d_kankyo_wether.ts +++ b/src/ZeldaWindWaker/d_kankyo_wether.ts @@ -2812,7 +2812,7 @@ export class d_thunder extends kankyo_class { this.btkAnm.entry(this.model, this.btkTime); this.brkAnm.entry(this.model); - mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput); + mDoExt_modelUpdateDL(globals, this.model, renderInstManager); } public override execute(globals: dGlobals, deltaTimeFrames: number): void { diff --git a/src/ZeldaWindWaker/m_do_ext.ts b/src/ZeldaWindWaker/m_do_ext.ts index c6a5ab788..a7c62dd64 100644 --- a/src/ZeldaWindWaker/m_do_ext.ts +++ b/src/ZeldaWindWaker/m_do_ext.ts @@ -86,7 +86,7 @@ export class mDoExt_bvaAnm extends mDoExt_baseAnm { } } -export function mDoExt_modelEntryDL(globals: dGlobals, modelInstance: J3DModelInstance, renderInstManager: GfxRenderInstManager, viewerInput: ViewerRenderInput, drawListSet: dDlst_list_Set | null = null): void { +export function mDoExt_modelEntryDL(globals: dGlobals, modelInstance: J3DModelInstance, renderInstManager: GfxRenderInstManager, drawListSet: dDlst_list_Set | null = null): void { if (!modelInstance.visible) return; @@ -104,18 +104,21 @@ export function mDoExt_modelEntryDL(globals: dGlobals, modelInstance: J3DModelIn const camera = globals.camera; modelInstance.calcView(camera.viewFromWorldMatrix, camera.frustum); + if (!modelInstance.isAnyShapeVisible()) + return; + renderInstManager.setCurrentList(drawListSet[0]); modelInstance.drawOpa(renderInstManager, camera.clipFromViewMatrix); renderInstManager.setCurrentList(drawListSet[1]); modelInstance.drawXlu(renderInstManager, camera.clipFromViewMatrix); } -export function mDoExt_modelUpdateDL(globals: dGlobals, modelInstance: J3DModelInstance, renderInstManager: GfxRenderInstManager, viewerInput: ViewerRenderInput, drawListSet: dDlst_list_Set | null = null): void { +export function mDoExt_modelUpdateDL(globals: dGlobals, modelInstance: J3DModelInstance, renderInstManager: GfxRenderInstManager, drawListSet: dDlst_list_Set | null = null): void { if (!modelInstance.visible) return; modelInstance.calcAnim(); - mDoExt_modelEntryDL(globals, modelInstance, renderInstManager, viewerInput, drawListSet); + mDoExt_modelEntryDL(globals, modelInstance, renderInstManager, drawListSet); } const scratchTransform = new JointTransformInfo(); @@ -228,8 +231,8 @@ export class mDoExt_McaMorf implements JointMatrixCalc { this.model.jointMatrixCalc = this; } - public entryDL(globals: dGlobals, renderInstManager: GfxRenderInstManager, viewerInput: ViewerRenderInput, drawListSet: dDlst_list_Set | null = null): void { - mDoExt_modelEntryDL(globals, this.model, renderInstManager, viewerInput); + public entryDL(globals: dGlobals, renderInstManager: GfxRenderInstManager, drawListSet: dDlst_list_Set | null = null): void { + mDoExt_modelEntryDL(globals, this.model, renderInstManager, drawListSet); } }