Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
soft reset (cleanup)
Browse files Browse the repository at this point in the history
  • Loading branch information
e2002e committed Jan 10, 2024
1 parent d025777 commit 8f04159
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 12 deletions.
18 changes: 17 additions & 1 deletion Sources/iron/RenderPath.hx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ class RenderPath {
public static var numTrisShadow = 0;
#end

#if (rp_voxels != "Off")
static var voxelized = 0;
public function voxelize() : Bool {
if(iron.Scene.active.camera.transform.diff() && armory.renderpath.RenderPathCreator.clipmapLevel == 0) {
voxelized = 0;
}
else
for (mesh in iron.Scene.active.meshes) {
if (mesh.transform.diff() && armory.renderpath.RenderPathCreator.clipmapLevel == 0) {
voxelized = 0;
break;
}
}
return ++voxelized > Main.voxelgiClipmapCount ? false : true;
}
#end

public static function setActive(renderPath: RenderPath) {
active = renderPath;
}
Expand Down Expand Up @@ -124,7 +141,6 @@ class RenderPath {
commands();

if (!isProbe) frame++;

}

public function setTarget(target: String, additional: Array<String> = null, viewportScale = 1.0) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/iron/data/ShaderData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ShaderContext {
public function new(raw: TShaderContext, done: ShaderContext->Void, overrideContext: TShaderOverride = null) {
this.raw = raw;
#if (rp_voxels == "Off")
if (raw.name == "voxel") {
if (raw.name == "voxel" || raw.name == "voxelbounce") {
done(this);
return;
}
Expand Down
34 changes: 29 additions & 5 deletions Sources/iron/object/MeshObject.hx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class MeshObject extends Object {
public var cameraDistance: Float;
public var screenSize = 0.0;
public var frustumCulling = true;
public var tilesheet: Tilesheet = null;
public var activeTilesheet: Tilesheet = null;
public var tilesheets: Array<Tilesheet> = null;
public var skip_context: String = null; // Do not draw this context
public var force_context: String = null; // Draw only this context
static var lastPipeline: PipelineState = null;
Expand Down Expand Up @@ -79,7 +80,8 @@ class MeshObject extends Object {
particleSystems = null;
}
#end
if (tilesheet != null) tilesheet.remove();
if (activeTilesheet != null) activeTilesheet.remove();
if (tilesheets != null) for (ts in tilesheets) { ts.remove(); }
if (Scene.active != null) Scene.active.meshes.remove(this);
data.refcount--;
super.remove();
Expand Down Expand Up @@ -115,7 +117,29 @@ class MeshObject extends Object {
#end

public function setupTilesheet(sceneName: String, tilesheet_ref: String, tilesheet_action_ref: String) {
tilesheet = new Tilesheet(sceneName, tilesheet_ref, tilesheet_action_ref);
activeTilesheet = new Tilesheet(sceneName, tilesheet_ref, tilesheet_action_ref);
if(tilesheets == null) tilesheets = new Array<Tilesheet>();
tilesheets.push(activeTilesheet);
}

public function setActiveTilesheet(sceneName: String, tilesheet_ref: String, tilesheet_action_ref: String) {
var set = false;
// Check if tilesheet already created
if (tilesheets != null) {
for (ts in tilesheets) {
if (ts.raw.name == tilesheet_ref) {
activeTilesheet = ts;
activeTilesheet.play(tilesheet_action_ref);
set = true;
break;
}
}
}
// If not already created
if (!set) {
setupTilesheet(sceneName, tilesheet_ref, tilesheet_action_ref);
}

}

inline function isLodMaterial(): Bool {
Expand Down Expand Up @@ -157,7 +181,7 @@ class MeshObject extends Object {
// particleSystems for update, particleOwner for render
if (particleSystems != null || particleOwner != null) radiusScale *= 1000;
#end
if (context == "voxel") radiusScale *= 100;
if (context == "voxel" || context == "voxelbounce") radiusScale *= 100;
if (data.geom.instanced) radiusScale *= 100;
var isShadow = context == "shadowmap";
var frustumPlanes = isShadow ? light.frustumPlanes : camera.frustumPlanes;
Expand Down Expand Up @@ -242,7 +266,7 @@ class MeshObject extends Object {
if (raw != null && raw.lods != null && raw.lods.length > 0) {
computeScreenSize(Scene.active.camera);
initLods();
if (context == "voxel") {
if (context == "voxel" || context == "voxelbounce") {
// Voxelize using the lowest lod
lod = cast lods[lods.length - 1];
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/iron/object/ParticleSystem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ class ParticleSystem {
dimx = object.transform.dim.x;
dimy = object.transform.dim.y;

if (object.tilesheet != null) {
tilesx = object.tilesheet.raw.tilesx;
tilesy = object.tilesheet.raw.tilesy;
tilesFramerate = object.tilesheet.raw.framerate;
if (object.activeTilesheet != null) {
tilesx = object.activeTilesheet.raw.tilesx;
tilesy = object.activeTilesheet.raw.tilesy;
tilesFramerate = object.activeTilesheet.raw.framerate;
}

// Animate
Expand Down
17 changes: 17 additions & 0 deletions Sources/iron/object/Tilesheet.hx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ class Tilesheet {
Scene.active.tilesheets.remove(this);
}

/**
* Set the frame of the current active tilesheet action. Automatically un-pauses action.
* @param frame Frame offset with 0 as the first frame of the active action.
**/
public function setFrameOffset(frame: Int) {
setFrame(action.start + frame);
paused = false;
}

/**
* Returns the current frame.
* @return Frame offset with 0 as the first frame of the active action.
*/
public function getFrameOffset(): Int {
return frame - action.start;
}

function update() {
if (!ready || paused || action.start >= action.end) return;

Expand Down
35 changes: 34 additions & 1 deletion Sources/iron/object/Uniforms.hx
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,34 @@ class Uniforms {
helpMat3.setFrom4(helpMat);
m = helpMat3;
}
case "_normalMatrixSphere": {
helpMat.setFrom(object.transform.world);
// Align to camera..
helpMat.multmat(camera.V);
helpMat._00 = 1.0; helpMat._10 = 0.0; helpMat._20 = 0.0;
helpMat._01 = 0.0; helpMat._11 = 1.0; helpMat._21 = 0.0;
helpMat._02 = 0.0; helpMat._12 = 0.0; helpMat._22 = 1.0;
helpMat2.getInverse(camera.V);
helpMat.multmat(helpMat2);
helpMat2.getInverse(helpMat);
helpMat2.transpose3x3();
helpMat3.setFrom4(helpMat2);
m = helpMat3;
}
case "_normalMatrixCylinder": {
helpMat.setFrom(object.transform.world);
// Align to camera..
helpMat.multmat(camera.V);
helpMat._00 = 1.0; helpMat._20 = 0.0;
helpMat._01 = 0.0; helpMat._21 = 0.0;
helpMat._02 = 0.0; helpMat._22 = 1.0;
helpMat2.getInverse(camera.V);
helpMat.multmat(helpMat2);
helpMat2.getInverse(helpMat);
helpMat2.transpose3x3();
helpMat3.setFrom4(helpMat2);
m = helpMat3;
}
case "_viewMatrix3": {
#if arm_centerworld
helpMat3.setFrom4(vmat(camera.V));
Expand Down Expand Up @@ -1016,10 +1044,15 @@ class Uniforms {
var vy: Null<kha.FastFloat> = null;
switch (c.link) {
case "_tilesheetOffset": {
var ts = cast(object, MeshObject).tilesheet;
var ts = cast(object, MeshObject).activeTilesheet;
vx = ts.tileX;
vy = ts.tileY;
}
case "_tilesheetTiles": {
var ts = cast(object, MeshObject).activeTilesheet;
vx = ts.raw.tilesx;
vy = ts.raw.tilesy;
}
#if arm_morph_target
case "_morphScaleOffset": {
var mt = cast(object, MeshObject).morphTarget;
Expand Down

0 comments on commit 8f04159

Please sign in to comment.