package hrt.prefab; class Constraint extends Prefab { public var object(default,null) : String; public var target(default,null) : String; public var positionOnly(default,null) : Bool; override public function load(v:Dynamic) { object = v.object; target = v.target; positionOnly = v.positionOnly; } override function save() { return { object : object, target : target, positionOnly : positionOnly }; } public function apply( root : h3d.scene.Object ) { var srcObj = root.getObjectByName(object.split(".").pop()); var targetObj = root.getObjectByName(target.split(".").pop()); if( srcObj != null && targetObj != null ){ srcObj.follow = targetObj; srcObj.followPositionOnly = positionOnly; } else trace("failed to resolve constraint"); return srcObj; } override function makeInstance( ctx : Context ) { if(!enabled) return ctx; var srcObj = ctx.locateObject(object); var targetObj = ctx.locateObject(target); if( srcObj != null && targetObj != null ){ srcObj.follow = targetObj; srcObj.followPositionOnly = positionOnly; } return ctx; } #if editor override function getHideProps() : HideProps { return { icon : "lock", name : "Constraint" }; } override function edit(ctx:EditContext) { var curObj = ctx.rootContext.locateObject(object); var props = ctx.properties.add(new hide.Element('
Source
Target
Position Only
'),this, function(_) { if( curObj != null ) curObj.follow = null; makeInstance(ctx.rootContext); curObj = ctx.rootContext.locateObject(object); }); for( select in [props.find("[field=object]"), props.find("[field=target]")] ) { for( path in ctx.getNamedObjects() ) { var parts = path.split("."); var opt = new hide.Element("