Skip to content

Commit fa4adbd

Browse files
committed
Move SubSkin from SC to heaps, with changes:
- Reuse existing Skin shader from baseSkin - Optim of the bind map using packed ints to avoid allocs
1 parent 9eb92b5 commit fa4adbd

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

h3d/scene/Skin.hx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,4 +691,51 @@ class Skin extends MultiMaterial {
691691
}
692692
}
693693

694+
}
695+
696+
class SubSkin extends h3d.scene.Skin {
697+
698+
var baseSkin : h3d.scene.Skin;
699+
var bindMap : Array<Int> = null;
700+
701+
public function new( baseSkin : h3d.scene.Skin, subSkin : h3d.scene.Skin, ?parent) {
702+
this.baseSkin = baseSkin;
703+
super(null, subSkin.materials, parent);
704+
skinShader = subSkin.skinShader;
705+
setSkinData(subSkin.skinData, false);
706+
}
707+
708+
function initBinds() {
709+
bindMap = [];
710+
for( b in skinData.allJoints ) {
711+
var b2 = baseSkin.skinData.namedJoints.get(b.name);
712+
if( b2 != null )
713+
bindJoint(b2, b);
714+
}
715+
}
716+
717+
override function setSkinData( s, shaderInit = true ) {
718+
super.setSkinData(s, shaderInit);
719+
initBinds();
720+
}
721+
722+
function bindJoint(from: h3d.anim.Skin.Joint, to: h3d.anim.Skin.Joint) {
723+
if(!baseSkin.skinData.allJoints.contains(from)) throw "assert";
724+
if(!skinData.allJoints.contains(to)) throw "assert";
725+
bindMap.push((from.index << 16) | to.index);
726+
}
727+
728+
override function syncJoints() {
729+
if(!baseSkin.buffersDirty)
730+
return;
731+
jointsUpdated = true;
732+
if( bindMap != null ) {
733+
for( b in bindMap ) {
734+
var to = b & ((1<<16)-1);
735+
var from = b >> 16;
736+
jointsData[to]?.currentRelPos = baseSkin.jointsData[from]?.currentRelPos;
737+
}
738+
}
739+
super.syncJoints();
740+
}
694741
}

0 commit comments

Comments
 (0)