Bladeren bron

scn -> hsd

ncannasse 7 jaren geleden
bovenliggende
commit
022646f15f
4 gewijzigde bestanden met toevoegingen van 20 en 10 verwijderingen
  1. 7 7
      h3d/impl/Serializable.hx
  2. 3 0
      h3d/mat/Material.hx
  3. 8 1
      h3d/scene/Object.hx
  4. 2 2
      h3d/scene/Scene.hx

+ 7 - 7
h3d/impl/Serializable.hx

@@ -247,17 +247,17 @@ class SceneSerializer extends hxbit.Serializer {
 		}
 	}
 
-	function initSCNPaths( resPath : String, projectPath : String ) {
+	function initHSDPaths( resPath : String, projectPath : String ) {
 		this.resPath = resPath;
 	}
 
-	public function loadSCN( bytes ) {
+	public function loadHSD( bytes ) {
 		setInput(bytes, 0);
-		if( getString() != "SCN" )
-			throw "Invalid SCN file";
+		if( getString() != "HSD" )
+			throw "Invalid HSD file";
 		version = getInt();
 		beginLoad(bytes, inPos);
-		initSCNPaths(getString(), getString());
+		initHSDPaths(getString(), getString());
 		var objs = [];
 		for( i in 0...getInt() ) {
 			var obj : h3d.scene.Object = cast getAnyRef();
@@ -270,9 +270,9 @@ class SceneSerializer extends hxbit.Serializer {
 		return { content : objs };
 	}
 
-	public function saveSCN( obj : h3d.scene.Object, includeRoot : Bool ) {
+	public function saveHSD( obj : h3d.scene.Object, includeRoot : Bool ) {
 		begin();
-		addString("SCN");
+		addString("HSD");
 		addInt(version); // version
 
 		var pos = out.length;

+ 3 - 0
h3d/mat/Material.hx

@@ -182,6 +182,7 @@ class Material extends BaseMaterial {
 	#if hxbit
 
 	function customSerialize( ctx : hxbit.Serializer ) {
+		// other props are serialized in BaseMaterial !
 		ctx.addInt(blendMode.getIndex());
 		ctx.addDynamic(props);
 	}
@@ -191,6 +192,8 @@ class Material extends BaseMaterial {
 		while( last.next != null ) last = last.next;
 		mshader = cast last.s;
 
+		// prevent changing the passes while setting blendmode/props
+		// since we have unserialized them, they are correctly set already
 		var old = passes;
 		passes = null;
 		blendMode = BlendMode.createByIndex(ctx.getInt());

+ 8 - 1
h3d/scene/Object.hx

@@ -81,6 +81,11 @@ class Object implements h3d.impl.Serializable {
 	**/
 	public var ignoreCollide(get, set) : Bool;
 
+	/**
+		When enable, the object can be serialized (default : true)
+	**/
+	public var allowSerialize(get, set) : Bool;
+
 	var absPos : h3d.Matrix;
 	var invPos : h3d.Matrix;
 	var qRot : h3d.Quat;
@@ -109,6 +114,7 @@ class Object implements h3d.impl.Serializable {
 	inline function get_alwaysSync() return flags.has(FAlwaysSync);
 	inline function get_inheritCulled() return flags.has(FInheritCulled);
 	inline function get_ignoreCollide() return flags.has(FIgnoreCollide);
+	inline function get_allowSerialize() return !flags.has(FNoSerialize);
 	inline function set_posChanged(b) return flags.set(FPosChanged, b || follow != null);
 	inline function set_culled(b) return flags.set(FCulled, b);
 	inline function set_visible(b) return flags.set(FVisible,b);
@@ -118,6 +124,7 @@ class Object implements h3d.impl.Serializable {
 	inline function set_alwaysSync(b) return flags.set(FAlwaysSync, b);
 	inline function set_inheritCulled(b) return flags.set(FInheritCulled, b);
 	inline function set_ignoreCollide(b) return flags.set(FIgnoreCollide, b);
+	inline function set_allowSerialize(b) return !flags.set(FNoSerialize, !b);
 
 	public function playAnimation( a : h3d.anim.Animation ) {
 		return currentAnimation = a.createInstance(this);
@@ -658,7 +665,7 @@ class Object implements h3d.impl.Serializable {
 	#if hxbit
 	function customSerialize( ctx : hxbit.Serializer ) {
 
-		var children = [for( o in children ) if( !o.flags.has(FNoSerialize) ) o];
+		var children = [for( o in children ) if( o.allowSerialize ) o];
 		ctx.addInt(children.length);
 		for( o in children )
 			ctx.addKnownRef(o);

+ 2 - 2
h3d/scene/Scene.hx

@@ -377,9 +377,9 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 
 
 	public function serializeScene() : haxe.io.Bytes {
-		#if hxbit		
+		#if hxbit
 		var s = new h3d.impl.Serializable.SceneSerializer();
-		return s.saveSCN(this, false);
+		return s.saveHSD(this, false);
 		#else
 		throw "You need -lib hxbit to serialize the scene data";
 		#end