2
0
Эх сурвалжийг харах

- fix quad-to-poly and poly-to-quad issues with scale != 1

ChuckAtShiro 6 жил өмнө
parent
commit
2120186446

+ 7 - 1
hide/prefab/PolygonEditor.hx

@@ -166,6 +166,10 @@ class PolygonEditor {
 		return editContext.getContext(polygonPrefab);
 		return editContext.getContext(polygonPrefab);
 	}
 	}
 
 
+	inline function refreshInteractive() {
+		editContext.scene.editor.refreshInteractive(polygonPrefab);
+	}
+
 	public function update( ?propName : String) {
 	public function update( ?propName : String) {
 		if(propName == "showDebug"){
 		if(propName == "showDebug"){
 			for(mp in movablePoints){
 			for(mp in movablePoints){
@@ -178,6 +182,8 @@ class PolygonEditor {
 		}
 		}
 		else if(propName == "editMode") {
 		else if(propName == "editMode") {
 			setSelected(getContext(), true);
 			setSelected(getContext(), true);
+		} else {
+			refreshInteractive();
 		}
 		}
 	}
 	}
 
 
@@ -578,7 +584,7 @@ class PolygonEditor {
 			editModeButton.toggleClass("editModeEnabled", editMode);
 			editModeButton.toggleClass("editModeEnabled", editMode);
 			setSelected(getContext(), true);
 			setSelected(getContext(), true);
 			if(!editMode) 
 			if(!editMode) 
-				editContext.scene.editor.refreshInteractive(polygonPrefab);
+				refreshInteractive();
 		});
 		});
 
 
 		props.find(".reset").click(function(_) {
 		props.find(".reset").click(function(_) {

+ 2 - 12
hrt/prefab/Object3D.hx

@@ -104,18 +104,8 @@ class Object3D extends Prefab {
 
 
 	override function updateInstance( ctx: Context, ?propName : String ) {
 	override function updateInstance( ctx: Context, ?propName : String ) {
 		var o = ctx.local3d;
 		var o = ctx.local3d;
-		o.x = x;
-		o.y = y;
-		o.z = z;
-		if(propName == null || propName.indexOf("scale") == 0) {
-			o.scaleX = scaleX;
-			o.scaleY = scaleY;
-			o.scaleZ = scaleZ;
-		}
-		if(propName == null || propName.indexOf("rotation") == 0)
-			o.setRotation(Math.degToRad(rotationX), Math.degToRad(rotationY), Math.degToRad(rotationZ));
-		if(propName == null || propName == "visible")
-			o.visible = visible;
+		applyPos(o);
+		o.visible = visible;
 	}
 	}
 
 
 	override function removeInstance(ctx: Context):Bool {
 	override function removeInstance(ctx: Context):Bool {

+ 26 - 7
hrt/prefab/l3d/Polygon.hx

@@ -17,6 +17,7 @@ class Polygon extends Object3D {
 	public var debugColor : Int = 0xFFFFFFFF;
 	public var debugColor : Int = 0xFFFFFFFF;
 	public var editor : hide.prefab.PolygonEditor;
 	public var editor : hide.prefab.PolygonEditor;
 	public var cachedPrim : h3d.prim.Polygon;
 	public var cachedPrim : h3d.prim.Polygon;
+	var prevScale = [1.0, 1.0];
 	#end
 	#end
 
 
 	override function save() {
 	override function save() {
@@ -189,14 +190,20 @@ class Polygon extends Object3D {
 			polyPrim.alloc(h3d.Engine.getCurrent());
 			polyPrim.alloc(h3d.Engine.getCurrent());
 		}
 		}
 		#if editor
 		#if editor
-		if(cachedPrim != null)
-			cachedPrim.decref();
+		clearCustomPolygonCache();
 		cachedPrim = polyPrim;
 		cachedPrim = polyPrim;
 		cachedPrim.incref();
 		cachedPrim.incref();
 		#end
 		#end
 		return polyPrim;
 		return polyPrim;
 	}
 	}
 
 
+	public function clearCustomPolygonCache() {
+		if(cachedPrim != null) {
+			cachedPrim.decref();
+			cachedPrim = null;
+		}
+	}
+
 	public function getPrimitive( ctx : Context ) : h3d.prim.Polygon {
 	public function getPrimitive( ctx : Context ) : h3d.prim.Polygon {
 		var mesh = Std.downcast(ctx.local3d, h3d.scene.Mesh);
 		var mesh = Std.downcast(ctx.local3d, h3d.scene.Mesh);
 		return Std.downcast(mesh.primitive, h3d.prim.Polygon);
 		return Std.downcast(mesh.primitive, h3d.prim.Polygon);
@@ -264,7 +271,8 @@ class Polygon extends Object3D {
 		var updateProps = null;
 		var updateProps = null;
 
 
 		ctx.properties.add(group, viewModel, function(pname) {
 		ctx.properties.add(group, viewModel, function(pname) {
-			if( pname == "kind" ) {
+			var pIsKind = pname == "kind";
+			if( pIsKind ) {
 				editor.reset();
 				editor.reset();
 
 
 				if( prevKind != Custom ){
 				if( prevKind != Custom ){
@@ -284,13 +292,23 @@ class Polygon extends Object3D {
 			}
 			}
 
 
 			switch( viewModel.kind ) {
 			switch( viewModel.kind ) {
-				case "Quad": shape = Quad;
-				case "Disc": shape = Disc(viewModel.segments, viewModel.angle, viewModel.innerRadius, viewModel.rings);
+				case "Quad": 
+					shape = Quad;
+					if(pIsKind && prevKind == Custom) {
+						scaleX = prevScale[0]; 
+						scaleY = prevScale[1];
+					}
+				case "Disc": 
+					shape = Disc(viewModel.segments, viewModel.angle, viewModel.innerRadius, viewModel.rings);
+					if(pIsKind && prevKind == Custom) {
+						scaleX = prevScale[0]; 
+						scaleY = prevScale[1];
+					}
 				case "Custom":
 				case "Custom":
 					shape = Custom;
 					shape = Custom;
-					if(points == null) {
+					if(pIsKind) {
 						if(prevKind == Quad) {
 						if(prevKind == Quad) {
-							var prevScale = [scaleX, scaleY];
+							prevScale = [scaleX, scaleY];
 							function apply() {
 							function apply() {
 								points = [
 								points = [
 									new Point(-scaleX/2, -scaleY/2),
 									new Point(-scaleX/2, -scaleY/2),
@@ -309,6 +327,7 @@ class Polygon extends Object3D {
 								else apply();
 								else apply();
 								ctx.onChange(this, null);
 								ctx.onChange(this, null);
 							}));
 							}));
+							clearCustomPolygonCache();
 							apply();
 							apply();
 							ctx.onChange(this, null);
 							ctx.onChange(this, null);
 						}
 						}