Bladeren bron

use GADT property

ncannasse 10 jaren geleden
bovenliggende
commit
d3b12f9652
3 gewijzigde bestanden met toevoegingen van 15 en 4 verwijderingen
  1. 3 3
      hxd/fmt/hmd/Data.hx
  2. 11 0
      hxd/fmt/hmd/Library.hx
  3. 1 1
      hxd/fmt/hmd/Writer.hx

+ 3 - 3
hxd/fmt/hmd/Data.hx

@@ -38,11 +38,11 @@ package hxd.fmt.hmd;
 typedef DataPosition = Int;
 typedef Index<T> = Int;
 
-enum Property {
-	CameraFOVY( v : Float );
+enum Property<T> {
+	CameraFOVY( v : Float ) : Property<Float>;
 }
 
-typedef Properties = Null<Array<Property>>;
+typedef Properties = Null<Array<Property<Dynamic>>>;
 
 class Position {
 	public var x : Float;

+ 11 - 0
hxd/fmt/hmd/Library.hx

@@ -309,6 +309,17 @@ class Library {
 		return s;
 	}
 
+	public function getModelProperty<T>( objName : String, p : Property<T> ) : T {
+		for( m in header.models )
+			if( m.name == objName ) {
+				for( pr in m.props )
+					if( pr.getIndex() == p.getIndex() )
+						return pr.getParameters()[0];
+				throw '${objName} has no property ${p.getName()}';
+			}
+		throw 'Model ${objName} not found';
+	}
+
 	public function makeObject( ?loadTexture : String -> h3d.mat.Texture ) : h3d.scene.Object {
 		if( loadTexture == null )
 			loadTexture = function(_) return h3d.mat.Texture.fromColor(0xFF00FF);

+ 1 - 1
hxd/fmt/hmd/Writer.hx

@@ -10,7 +10,7 @@ class Writer {
 		this.out = out;
 	}
 
-	function writeProperty( p : Property ) {
+	function writeProperty( p : Property<Dynamic> ) {
 		out.writeByte(p.getIndex());
 		switch( p ) {
 		case CameraFOVY(v):