///////////////////////////////////////// public Component_Scene CreateScene(bool enable) { DetachAndOrDestroyScene(); scene = ComponentUtility.CreateComponent <Component_Scene>(null, true, enable); //!!!!что еще отключать? scene.OctreeEnabled = false; //rendering pipeline { var pipeline = (Component_RenderingPipeline)scene.CreateComponent(RenderingSystem.RenderingPipelineDefault, -1, false); scene.RenderingPipeline = pipeline; //!!!!что еще отключать? pipeline.DeferredShading = AutoTrueFalse.False; pipeline.LODRange = new RangeI(0, 0); //pipeline.UseRenderTargets = false; //!!!! scene.BackgroundColor = new ColorValue(0.5, 0.5, 0.5); //scene.BackgroundColor = new ColorValue( 0, 0, 0, 0 ); scene.BackgroundColorAffectLighting = 1; scene.BackgroundColorEnvironmentOverride = new ColorValue(0.8, 0.8, 0.8); pipeline.Enabled = true; } //ambient light { var light = scene.CreateComponent <Component_Light>(); light.Type = Component_Light.TypeEnum.Ambient; light.Brightness = ReferenceUtility.MakeReference("Base\\ProjectSettings.component|PreviewAmbientLightBrightness"); //light.Brightness = ProjectSettings.Get.PreviewAmbientLightBrightness.Value; } //directional light { var light = scene.CreateComponent <Component_Light>(); light.Type = Component_Light.TypeEnum.Directional; light.Transform = new Transform(new Vector3(0, 0, 0), Quaternion.FromDirectionZAxisUp(new Vector3(0, 0, -1)), Vector3.One); light.Brightness = ReferenceUtility.MakeReference("Base\\ProjectSettings.component|PreviewDirectionalLightBrightness"); //light.Brightness = ProjectSettings.Get.PreviewDirectionalLightBrightness.Value; //!!!!? light.Shadows = false; //light.Type = Component_Light.TypeEnum.Point; //light.Transform = new Transform( new Vec3( 0, 0, 2 ), Quat.Identity, Vec3.One ); } scene.ViewportUpdateGetCameraSettings += Scene_ViewportUpdateGetCameraSettings; //connect scene to viewport if (viewport != null) { viewport.AttachedScene = scene; } return(scene); }
//!!!!rename public static T GetVariableFromCurrentFlow_Generic <T>(string name) { object value = null; if (CurrentFlow != null) { CurrentFlow.variables.TryGetValue(name, out value); } var expectedType = typeof(T); //auto convert types if (value != null && !expectedType.IsAssignableFrom(value.GetType())) { var newValue = MetadataManager.AutoConvertValue(value, expectedType); if (newValue == null) { newValue = MetadataManager.AutoConvertValue(ReferenceUtility.GetUnreferencedValue(value), expectedType); } value = newValue; } //default for value types if (value == null && expectedType.IsValueType) { value = Activator.CreateInstance(expectedType); } return((T)value); }
public override void NewObjectSetDefaultConfiguration(bool createdFromNewObjectWindow = false) { base.NewObjectSetDefaultConfiguration(createdFromNewObjectWindow); Transform = new Transform(TransformV.Position, Quaternion.LookAt(new Vector3(0, 0, -1), new Vector3(0, 1, 0))); Material = ReferenceUtility.MakeReference(@"Base\Components\Decal default.material"); }
public override void NewObjectSetDefaultConfiguration(bool createdFromNewObjectWindow = false) { base.NewObjectSetDefaultConfiguration(createdFromNewObjectWindow); //create surface var meshInSpace = CreateComponent <Component_MeshInSpace>(enabled: false); meshInSpace.Name = "Surface"; meshInSpace.CanBeSelected = false; var mesh = meshInSpace.CreateComponent <Component_Mesh>(); mesh.Name = "Mesh"; meshInSpace.Mesh = ReferenceUtility.MakeThisReference(meshInSpace, mesh); var geometry = mesh.CreateComponent <Component_MeshGeometry_Plane>(); geometry.Name = "Mesh Geometry"; geometry.Material = ReferenceUtility.MakeThisReference(geometry, this, "MaterialSurface"); var transformOffset = meshInSpace.CreateComponent <Component_TransformOffset>(); transformOffset.Name = "Attach Transform Offset"; transformOffset.PositionOffset = new Vector3(0, 0, 0.5); transformOffset.Source = ReferenceUtility.MakeThisReference(transformOffset, this, "Transform"); meshInSpace.Transform = ReferenceUtility.MakeThisReference(meshInSpace, transformOffset, "Result"); meshInSpace.Enabled = true; UpdateSettings(); }
void Update() { if (needUpdate) { //!!!!slowly? var demandedReturnType = GetDemandedReturnType(); if (demandedReturnType != createdPropertyReturnType || property == null) { Clear(); if (Enabled) //!!!!? { needUpdate = false; if (demandedReturnType != null) { //!!!!TypeInfo? Type unrefNetType = ReferenceUtility.GetUnreferencedType(demandedReturnType.GetNetType()); var type = MetadataManager.GetTypeOfNetType(unrefNetType); //!!!! var typeUnreferenced = type; var p = new PropertyImpl(this, "Output", false, type, typeUnreferenced, new Metadata.Parameter[0], true, "Parameter", false); p.Description = ""; property = p; createdPropertyReturnType = demandedReturnType; } } } } }
static void FixRootReferences(Component_Import3D import3D) { bool Fix(IReference reference, out string newReference) { if (reference.ReferenceSpecified) { var referenceValue = reference.GetByReference; if (referenceValue.Length >= "root:".Length && referenceValue.Substring(0, 5) == "root:") { newReference = referenceValue.Insert(5, "$Import3D\\"); return(true); } } newReference = null; return(false); } //Component_MeshGeometry.Material foreach (var meshGeometry in import3D.GetComponents <Component_MeshGeometry>(false, true)) { if (Fix(meshGeometry.Material, out var newReference)) { meshGeometry.Material = ReferenceUtility.MakeReference <Component_Material>(null, newReference); } } //Component_MeshInSpace.Mesh foreach (var meshInSpace in import3D.GetComponents <Component_MeshInSpace>(false, true)) { if (Fix(meshInSpace.Mesh, out var newReference)) { meshInSpace.Mesh = ReferenceUtility.MakeReference <Component_Mesh>(null, newReference); } } }
public override object GetValue(object obj, object[] index) { object result = null; //always obj == Owner Component_InvokeMember c = (Component_InvokeMember)obj; //!!!!так? if (invoke && !c.FlowSupport) { c.Invoke(); } object value; if (c.propertyValues.TryGetValue(Signature, out value)) { //update value for Reference type if (referenceSupport) { //convert from ReferenceNoValue if (value != null && value is ReferenceNoValue) { value = ReferenceUtility.MakeReference(ReferenceUtility.GetUnreferencedType(Type.GetNetType()), ((ReferenceNoValue)value).GetByReference); } IReference iReference = value as IReference; if (iReference != null) { //!!!!try catch? где еще так //get value by reference //!!!! value = iReference.GetValue(obj); //value = iReference.GetValue( Owner ); //!!!!? if (!ReadOnly) //!!!!new { //!!!! SetValue(obj, value, Indexers); //SetValue( Owner, value, Indexers ); } } } result = value; } //check the type. result can contains value with another type after change the type of property. if (result != null && !Type.IsAssignableFrom(MetadataManager.MetadataGetType(result))) { result = null; } if (result == null && Type.GetNetType().IsValueType) { result = Type.InvokeInstance(null); } return(result); }
public override object GetValue(object obj, object[] index) { //always obj == Owner var c = (Component_ConvertTo)obj; object result = c.Source.Value; //!!!!Metadata.TypeInfo support //auto convert types if (result != null && !Type.GetNetType().IsAssignableFrom(result.GetType())) { var newValue = MetadataManager.AutoConvertValue(result, Type.GetNetType()); if (newValue == null) { newValue = MetadataManager.AutoConvertValue(ReferenceUtility.GetUnreferencedValue(result), Type.GetNetType()); } result = newValue; } //check the type. result can contains value with another type after change the type of property. if (result != null && !Type.IsAssignableFrom(MetadataManager.MetadataGetType(result))) { result = null; } if (result == null && Type.GetNetType().IsValueType) { result = Type.InvokeInstance(null); } return(result); }
public void Init() { var sample = CreateComponent <Component_ShaderTextureSample>(); sample.TextureType = Component_ShaderTextureSample.TextureTypeEnum.Mask; Opacity = ReferenceUtility.MakeThisReference(this, sample, "R"); }
public object Invoke(object obj, object[] parameters) { object returnValue = null; var invokeItem = new InvokeStackItem(); invokeItem.obj = obj; invokeItem.parameters = parameters; if (invokeStack == null) { invokeStack = new Stack <InvokeStackItem>(); } invokeStack.Push(invokeItem); //execute flow Flow flow = null; if (Flow.Value != null) { flow = NeoAxis.Flow.ExecuteWithoutRemoveFromStack(Flow, null); } //get ref, out, return value parameters var bodyEnd = BodyEnd.Value; if (bodyEnd != null) { foreach (var p in bodyEnd.properties) { switch (p.parameterType) { case Component_MethodBodyEnd.PropertyImpl.ParameterType.Parameter: if (p.invokeParameterIndex < parameters.Length) { parameters[p.invokeParameterIndex] = ReferenceUtility.GetUnreferencedValue(p.GetValue(bodyEnd, null)); } break; case Component_MethodBodyEnd.PropertyImpl.ParameterType.ReturnValue: returnValue = ReferenceUtility.GetUnreferencedValue(p.GetValue(bodyEnd, null)); break; } } } if (flow != null) { NeoAxis.Flow.RemoveFromStack(flow); } invokeStack.Pop(); //returnValue = EngineApp.EngineTime % 4.0 > 2.0; return(returnValue); }
public override void Finish(bool cancel) { base.Finish(cancel); if (!cancel) { CreatingObject.Surface = ReferenceUtility.MakeReference(@"Base\Surfaces\Default.surface"); } }
public override void SetValue(object obj, object value, object[] index) { var c = (Component_DeclareVariable)obj; c.valuePropertyValue = value; //set variable to current flow var currentFlow = Flow.CurrentFlow; currentFlow?.SetVariable(c.GetVariableName(), ReferenceUtility.GetUnreferencedValue(value)); }
public void AddBaseObject(Component_ObjectInSpace obj) { var groupOfObjects = GetOrCreateGroupOfObjects(); if (groupOfObjects != null) { if (!groupOfObjects.BaseObjects.Contains((Component)obj)) { groupOfObjects.BaseObjects.Add(ReferenceUtility.MakeRootReference <Component>(obj)); } } }
public override void NewObjectSetDefaultConfiguration(bool createdFromNewObjectWindow = false) { if (Components.Count == 0) { var controller = CreateComponent <Component_SpriteAnimationController>(); controller.Name = "Sprite Animation Controller"; Animate = true; IdleAnimation = ReferenceUtility.MakeReference(@"Base\Sprites\Weapon\Animation Idle.component"); //FireAnimation = ReferenceUtility.MakeReference( @"Base\Sprites\Penguin\Animation Fire.component" ); } }
void UpdateDefaultValue(PropertyImpl property) { property.DefaultValueSpecified = DefaultValueSpecified.Value; if (property.DefaultValueSpecified && defaultValueProperty != null) { //!!!!need check type? property.DefaultValue = ReferenceUtility.GetUnreferencedValue(defaultValueProperty.GetValue(this, null)); } else { property.DefaultValue = null; } }
public override object GetValue(object obj, object[] index) { var c = (Component_DeclareVariable)obj; object result = null; object value = null; bool valueGotFromFlow = false; //get value from current flow var currentFlow = Flow.CurrentFlow; if (currentFlow != null) { if (currentFlow.GetVariable(c.GetVariableName(), out object unrefValue)) { value = ReferenceUtility.MakeReference(TypeUnreferenced.GetNetType(), unrefValue, ""); valueGotFromFlow = true; } } //get init value if (!valueGotFromFlow) { value = c.valuePropertyValue; //update value for Reference type IReference iReference = value as IReference; if (iReference != null) { //get value by reference value = iReference.GetValue(obj); SetValue(obj, value, Indexers); } } result = value; //check the type. result can contains value with another type after change the type of property. if (result != null && !Type.IsAssignableFrom(MetadataManager.MetadataGetType(result))) { result = null; } if (result == null && Type.GetNetType().IsValueType) { result = Type.InvokeInstance(null); } return(result); }
///////////////////////////////////////// public override void DragDropObjectCreateInitNode(Component_FlowGraphNode node, DragDropObjectCreateInitNodeContext context, ref bool handled) { //Component_ShaderTextureSample if (context.createComponentType != null && MetadataManager.GetTypeOfNetType(typeof(Component_Image)).IsAssignableFrom(context.createComponentType)) { var obj = node.CreateComponent <Component_ShaderTextureSample>(); obj.Name = "Texture Sample"; //!!!!если не из ресурса obj.Texture = ReferenceUtility.MakeReference <Component_Image>(null, context.createComponentType.Name); context.controlledObject = obj; handled = true; } }
public void UpdateOutput() { var groupOfObjects = GetOrCreateGroupOfObjects(); if (groupOfObjects != null) { var wasEnabled = groupOfObjects.Enabled; if (wasEnabled) { groupOfObjects.Enabled = false; } Component_GroupOfObjects.Object[] objects; var surface = Surface.Value; if (surface != null) { var element = groupOfObjects.GetComponent <Component_GroupOfObjectsElement_Surface>(); if (element == null) { element = groupOfObjects.CreateComponent <Component_GroupOfObjectsElement_Surface>(); element.Name = "Surface"; //!!!!? element.AutoAlign = false; element.Surface = ReferenceUtility.MakeThisReference(element, this, "Surface"); } objects = UpdateOutputDefault(surface, groupOfObjects); } else { objects = new Component_GroupOfObjects.Object[0]; } OnUpdateOutput(ref objects); UpdateOutputEvent?.Invoke(this, ref objects); groupOfObjects.ObjectsSet(objects); updatedForPointPositions = GetPointPositions(); if (wasEnabled) { groupOfObjects.Enabled = true; } } }
public override void NewObjectSetDefaultConfiguration(bool createdFromNewObjectWindow = false) { if (Components.Count == 0) { //Mesh { var mesh = CreateComponent <Component_Mesh>(); mesh.Name = "Mesh"; Mesh = ReferenceUtility.MakeThisReference(this, mesh); var geometry = mesh.CreateComponent <Component_MeshGeometry_Box>(); geometry.Name = "Mesh Geometry"; geometry.Dimensions = new Vector3(0.3, 0.3, 0.3); geometry.Material = ReferenceUtility.MakeReference("Base\\Materials\\White.material"); } } }
void IFlowExecutionComponent.FlowExecution(Flow flow, Flow.ExecutionStackItem entryItem) { var variable = Variable.Value; if (variable != null && valueProperty != null) { var value = ReferenceUtility.GetUnreferencedValue(valueProperty.GetValue(this, null)); flow.SetVariable(variable.GetVariableName(), value); } FlowInput next = Exit; if (next != null) { flow.ExecutionStack.Push(new Flow.ExecutionStackItem(next)); } }
public override void NewObjectSetDefaultConfiguration(bool createdFromNewObjectWindow = false) { if (Components.Count == 0) { //Mesh { var mesh = CreateComponent <Component_Mesh>(); mesh.Name = "Mesh"; Mesh = ReferenceUtility.MakeThisReference(this, mesh); var geometry = mesh.CreateComponent <Component_MeshGeometry_Pipe>(); geometry.Name = "Mesh Geometry"; geometry.Axis = 0; geometry.Radius = 0.04; geometry.Thickness = 0.01; geometry.Material = ReferenceUtility.MakeReference("Base\\Materials\\White.material"); } //Stock { var meshInSpace = CreateComponent <Component_MeshInSpace>(); meshInSpace.Name = "Stock"; var mesh = meshInSpace.CreateComponent <Component_Mesh>(); mesh.Name = "Mesh"; meshInSpace.Mesh = ReferenceUtility.MakeThisReference(this, mesh); var geometry = mesh.CreateComponent <Component_MeshGeometry_Box>(); geometry.Name = "Mesh Geometry"; geometry.Dimensions = new Vector3(0.4, 0.05, 0.15); geometry.Material = ReferenceUtility.MakeReference("Base\\Materials\\White.material"); meshInSpace.Mesh = ReferenceUtility.MakeThisReference(meshInSpace, mesh); var transformOffset = meshInSpace.CreateComponent <Component_TransformOffset>(); transformOffset.Name = "Attach Transform Offset"; transformOffset.PositionOffset = new Vector3(-0.22, 0, -0.1); transformOffset.Source = ReferenceUtility.MakeThisReference(transformOffset, this, "Transform"); meshInSpace.Transform = ReferenceUtility.MakeThisReference(meshInSpace, transformOffset, "Result"); } } }
void NewObjectCreateShaderGraph() { var graph = CreateComponent <Component_FlowGraph>(); graph.Name = "Shader graph"; graph.Specialization = ReferenceUtility.MakeReference( MetadataManager.GetTypeOfNetType(typeof(Component_FlowGraphSpecialization_Shader)).Name + "|Instance"); var node = graph.CreateComponent <Component_FlowGraphNode>(); node.Name = "Node " + Name; node.Position = new Vector2I(10, -7); node.ControlledObject = ReferenceUtility.MakeThisReference(node, this); if (Parent == null) { var toSelect = new Component[] { this, graph }; EditorDocumentConfiguration = KryptonConfigGenerator.CreateEditorDocumentXmlConfiguration(toSelect, graph); } }
//protected virtual bool OnTextTypingFilter( EKeys key, char character, string newText ) //{ // if( TextTypingFilter != null ) // { // if( !TextTypingFilter( this, key, character, newText ) ) // return false; // } // return true; //} public override void NewObjectSetDefaultConfiguration(bool createdFromNewObjectWindow = false) { base.NewObjectSetDefaultConfiguration(createdFromNewObjectWindow); var obj = CreateComponent <UIText>(); obj.Name = "Text"; obj.Text = ReferenceUtility.MakeThisReference(obj, this, "DisplayText"); //"Text" ); obj.TextHorizontalAlignment = EHorizontalAlignment.Left; //obj.TextHorizontalAlignment = ReferenceUtility.MakeThisReference( obj, this, "TextHorizontalAlignment" ); obj.Size = new UIMeasureValueVector2(UIMeasure.Parent, 1, 1); obj.CanBeSelected = false; obj.HorizontalAlignment = EHorizontalAlignment.Stretch; obj.VerticalAlignment = EVerticalAlignment.Stretch; //obj.Offset = new UIMeasureValueVector2( UIMeasure.Units, 4, 0 ); obj.ClipRectangle = true; //UIStyle.EditTextMargin obj.Margin = new UIMeasureValueRectangle(UIMeasure.Units, 4, 2, 4, 2); //obj.Margin = new UIMeasureValueRectangle( UIMeasure.Units, 2, 2, 2, 2 ); }
void IFlowExecutionComponent.FlowExecution(Flow flow, Flow.ExecutionStackItem entryItem) { var selection = Selection.Value; if (selection != null) { //!!!!always compare via strings? var selectionStr = selection.ToString(); for (int nCase = 0; nCase < Cases.Count; nCase++) { if (selectionStr == Cases[nCase]) { var p = GetProperty(nCase); if (p != null) { var v = (FlowInput)ReferenceUtility.GetUnreferencedValue(p.GetValue(this, null)); if (v != null) { flow.ExecutionStack.Push(new Flow.ExecutionStackItem(v)); return; } } } } } //Default { var p = GetProperty(-1); if (p != null) { var v = (FlowInput)ReferenceUtility.GetUnreferencedValue(p.GetValue(this, null)); if (v != null) { flow.ExecutionStack.Push(new Flow.ExecutionStackItem(v)); } } } }
void IFlowExecutionComponent.FlowExecution(Flow flow, Flow.ExecutionStackItem entryItem) { bool isEntry = entryItem.FlowInput != null && entryItem.FlowInput.PropertyName == nameof(Entry); int number = -1; if (!isEntry) { if (flow.InternalVariables.TryGetValue(this, out var value)) { number = (int)value; } } number++; var p = GetProperty(number); if (p != null) { flow.InternalVariables[this] = number; //reply after Body flow.ExecutionStack.Push(new Flow.ExecutionStackItem(this)); //go to Body var v = (FlowInput)ReferenceUtility.GetUnreferencedValue(p.GetValue(this, null)); if (v != null) { flow.ExecutionStack.Push(new Flow.ExecutionStackItem(v.Owner)); return; } } else { //end flow.InternalVariables.Remove(this); } }
//public override void UpdateParentVirtualMembers( ref List<Metadata.Member> members, ref Dictionary<string, Metadata.Member> memberBySignature ) //{ // base.UpdateParentVirtualMembers( ref members, ref memberBySignature ); // xx xx; // //create // if( createdMethod == null && Parent != null ) // { // createdMethod = CreateMethod(); // xx xx; // //!!!! // //Body.Value?.NeedUpdate(); // } // xx xx; // //add to parent // if( createdMethod != null ) // { // if( members == null ) // { // members = new List<Metadata.Member>(); // memberBySignature = new Dictionary<string, Metadata.Member>(); // } // members.Add( createdMethod ); // memberBySignature[ createdMethod.Signature ] = createdMethod; // } //} //public override Metadata.Member CreatedMember //{ // get // { // xx xx; // return createdMethod; // } //} void NewObjectCreateFlowGraph() { var graph = CreateComponent <Component_FlowGraph>(); graph.Name = "Flow Graph"; Component_MethodBody body; { var node = graph.CreateComponent <Component_FlowGraphNode>(); body = node.CreateComponent <Component_MethodBody>(); body.Name = body.BaseType.GetUserFriendlyNameForInstance(); node.Name = "Node " + body.Name; node.Position = new Vector2I(-25, -7); node.ControlledObject = ReferenceUtility.MakeThisReference(node, body); } Component_MethodBodyEnd bodyEnd; { var node = graph.CreateComponent <Component_FlowGraphNode>(); bodyEnd = node.CreateComponent <Component_MethodBodyEnd>(); bodyEnd.Name = bodyEnd.BaseType.GetUserFriendlyNameForInstance(); node.Name = "Node " + bodyEnd.Name; node.Position = new Vector2I(15, -7); node.ControlledObject = ReferenceUtility.MakeThisReference(node, bodyEnd); } Body = ReferenceUtility.MakeThisReference(this, body); body.Definition = ReferenceUtility.MakeThisReference(body, this); body.BodyEnd = ReferenceUtility.MakeThisReference(body, bodyEnd); bodyEnd.Body = ReferenceUtility.MakeThisReference(bodyEnd, body); //!!!!выделять, открывать созданные }
public override void NewObjectSetDefaultConfiguration(bool createdFromNewObjectWindow = false) { var emitter = CreateComponent <Component_ParticleEmitter>(); emitter.Name = "Emitter"; emitter.Material = ReferenceUtility.MakeReference(@"Base\Components\Particle system default.material"); emitter.DispersionAngle = new Component_ParticleEmitter.SingleProperty(10); var shape = emitter.CreateComponent <Component_ParticleEmitterShape_Point>(); shape.Name = "Point Shape"; shape.Transform = new Transform(Vector3.Zero, new Angles(0, 90, 0).ToQuaternion()); var colorMultiplier = emitter.CreateComponent <Component_ParticleColorMultiplierByTime>(); colorMultiplier.Name = "Color Multiplier By Time"; colorMultiplier.Channels = Component_ParticleColorMultiplierByTime.ChannelsEnum.Alpha; colorMultiplier.Type = Component_ParticleColorMultiplierByTime.TypeEnum.Curve; colorMultiplier.Curve.Add(new CurvePoint(0, 0)); colorMultiplier.Curve.Add(new CurvePoint(1, 1)); colorMultiplier.Curve.Add(new CurvePoint(2, 1)); colorMultiplier.Curve.Add(new CurvePoint(3, 0)); }
public static Component_TransformOffset Attach(Component_ObjectInSpace attachTo, Component_ObjectInSpace objectToAttach, DocumentInstance documentforUndoRedo = null, UndoMultiAction undoMultiAction = null) { var objectToTransform = CalculateObjectToTransform(objectToAttach); if (objectToTransform != null) { objectToAttach = objectToTransform; } //create _TransformOffset Component_TransformOffset transformOffset; { const string transformOffsetName = "Attach Transform Offset"; transformOffset = objectToAttach.CreateComponent <Component_TransformOffset>(enabled: false); transformOffset.Name = transformOffsetName; transformOffset.Source = ReferenceUtility.MakeReference <Transform>(null, ReferenceUtility.CalculateThisReference(transformOffset, attachTo, "Transform")); try { var f = attachTo.Transform.Value; var s = objectToAttach.Transform.Value; var offset = f.ToMatrix4().GetInverse() * s.ToMatrix4(); offset.Decompose(out Vector3 pos, out Quaternion rot, out Vector3 scl); transformOffset.PositionOffset = pos; transformOffset.RotationOffset = rot; transformOffset.ScaleOffset = scl; //transformOffset.Matrix = offset; //var offset = new Mat4( s.Rotation.ToMat3(), s.Position ) * new Mat4( f.Rotation.ToMat3(), f.Position ).GetInverse(); //var f = first.Transform.Value; //var s = second.Transform.Value; //var offset = new Mat4( s.Rotation.ToMat3(), s.Position ) * new Mat4( f.Rotation.ToMat3(), f.Position ).GetInverse(); ////var offset = second.Transform.Value.ToMat4() * first.Transform.Value.ToMat4().GetInverse(); //offset.Decompose( out Vec3 pos, out Quat rot, out Vec3 scl ); //transformOffset.PositionOffset = pos / f.Scale;// / s.Scale; //transformOffset.RotationOffset = rot; //transformOffset.ScaleOffset = s.Scale / f.Scale; ////transformOffset.ScaleOffset = scl; } catch { } transformOffset.Enabled = true; if (undoMultiAction != null) { undoMultiAction.AddAction(new UndoActionComponentCreateDelete(documentforUndoRedo, new Component[] { transformOffset }, true)); } } //change Transform { //undo action if (undoMultiAction != null) { var property = (Metadata.Property)objectToAttach.MetadataGetMemberBySignature("property:Transform"); var undoItem = new UndoActionPropertiesChange.Item(objectToAttach, property, objectToAttach.Transform, new object[0]); undoMultiAction.AddAction(new UndoActionPropertiesChange(new UndoActionPropertiesChange.Item[] { undoItem })); } //configure reference objectToAttach.Transform = ReferenceUtility.MakeReference <Transform>(null, ReferenceUtility.CalculateThisReference(objectToAttach, transformOffset, "Result")); } return(transformOffset); }
public override void RenderNodeReferences(Component_FlowGraph_DocumentWindow window, Component_FlowGraphNode node, Dictionary <Component, List <Component_FlowGraphNode> > objectToNodes, Dictionary <Component_FlowGraphNode.Representation.Item, EditorRenderSelectionState> referenceSelectionStates, out Component_FlowGraphNode.Representation.Item outMouseOverReference) { outMouseOverReference = null; var representation = node.GetRepresentation(); var renderer = window.ViewportControl.Viewport.CanvasRenderer; for (int nItem = 0; nItem < representation.Items.Count; nItem++) { var item = representation.Items[nItem]; //references from input if (item.Input != null) { var itemProperty = item as Component_FlowGraphNode.Representation.ItemProperty; if (itemProperty != null && ReferenceUtility.IsReferenceType(itemProperty.Property.Type.GetNetType()) && !MetadataManager.GetTypeOfNetType(typeof(FlowInput)).IsAssignableFrom(itemProperty.Property.TypeUnreferenced)) { Component obj = itemProperty.Owner.Owner.ControlledObject; if (obj != null) { var v = itemProperty.Property.GetValue(obj, null); IReference iReference = v as IReference; if (iReference != null && !string.IsNullOrEmpty(iReference.GetByReference)) { iReference.GetMember(obj, out object destObject, out Metadata.Member destMember); var destProperty = destMember as Metadata.Property; if (destProperty != null) { //reference to property //!!!!только компоненты? статичные свойства тоже нельзя? var destComponent = destObject as Component; if (destComponent != null && objectToNodes.TryGetValue(destComponent, out List <Component_FlowGraphNode> destNodes)) { foreach (var destNode in destNodes) { var destRep = destNode.GetRepresentation(); Component_FlowGraphNode.Representation.ItemProperty destSocket; if (destRep.ItemByProperty.TryGetValue(destProperty, out destSocket)) { if (destSocket.Output != null) { var from = GetSocketPositionInUnits(item, true); var to = GetSocketPositionInUnits(destSocket, false); if (!referenceSelectionStates.TryGetValue(item, out EditorRenderSelectionState state)) { state = EditorRenderSelectionState.None; } ColorValue color; if (state != EditorRenderSelectionState.None) { color = GetColorMultiplierSelectionState(state); } else { color = new ColorValue(0.5, 0.5, 0.5); } //ColorValue color = GetColorMultiplierSelectionState( state ); window.GetFlowGraphStyle().RenderReference(window, from, true, to, color, out bool mouseOver); if (mouseOver && outMouseOverReference == null) { outMouseOverReference = item; } } } } } } else { //reference to Component var unrefValue = ReferenceUtility.GetUnreferencedValue(iReference.GetValue(obj)); var destComponent = unrefValue as Component; if (destComponent != null && objectToNodes.TryGetValue(destComponent, out List <Component_FlowGraphNode> destNodes)) { foreach (var destNode in destNodes) { var destRep = destNode.GetRepresentation(); var destSocket = destRep.ItemObject; if (destSocket != null) { var from = GetSocketPositionInUnits(item, true); var to = GetSocketPositionInUnits(destSocket, false); if (!referenceSelectionStates.TryGetValue(item, out EditorRenderSelectionState state)) { state = EditorRenderSelectionState.None; } ColorValue color; if (state != EditorRenderSelectionState.None) { color = GetColorMultiplierSelectionState(state); } else { color = new ColorValue(0.5, 0.5, 0.5); } //ColorValue color = GetColorMultiplierSelectionState( state ); window.GetFlowGraphStyle().RenderReference(window, from, true, to, color, out bool mouseOver); if (mouseOver && outMouseOverReference == null) { outMouseOverReference = item; } } } } //!!!!invalid reference } } } } } //references from output (FlowInput) if (item.Output != null) { var itemProperty = item as Component_FlowGraphNode.Representation.ItemProperty; if (itemProperty != null && ReferenceUtility.IsReferenceType(itemProperty.Property.Type.GetNetType()) && MetadataManager.GetTypeOfNetType(typeof(FlowInput)).IsAssignableFrom(itemProperty.Property.TypeUnreferenced)) { Component obj = itemProperty.Owner.Owner.ControlledObject; if (obj != null) { var v = itemProperty.Property.GetValue(obj, null); IReference iReference = v as IReference; if (iReference != null && !string.IsNullOrEmpty(iReference.GetByReference)) { iReference.GetMember(obj, out object destObject, out Metadata.Member destMember); var destProperty = destMember as Metadata.Property; if (destProperty != null) { //!!!!только компоненты? статичные свойства тоже нельзя? var destComponent = destObject as Component; if (destComponent != null && objectToNodes.TryGetValue(destComponent, out List <Component_FlowGraphNode> destNodes)) { foreach (var destNode in destNodes) { var destRep = destNode.GetRepresentation(); Component_FlowGraphNode.Representation.ItemProperty destSocket; if (destRep.ItemByProperty.TryGetValue(destProperty, out destSocket)) { if (destSocket.Input != null) { var from = GetSocketPositionInUnits(item, false); var to = GetSocketPositionInUnits(destSocket, true); if (!referenceSelectionStates.TryGetValue(item, out EditorRenderSelectionState state)) { state = EditorRenderSelectionState.None; } ColorValue color; if (state != EditorRenderSelectionState.None) { color = GetColorMultiplierSelectionState(state); } else { color = new ColorValue(0.3, 0.3, 1); } //ColorValue color = GetColorMultiplierSelectionState( state ); window.GetFlowGraphStyle().RenderReference(window, from, false, to, color, out bool mouseOver); if (mouseOver && outMouseOverReference == null) { outMouseOverReference = item; } } } } } } else { //!!!!invalid reference } } } } } } }
public override void RenderNode(Component_FlowGraph_DocumentWindow window, Component_FlowGraphNode node, EditorRenderSelectionState selectionStateNode, EditorRenderSelectionState selectionStateControlledObject, object mouseOverObject, Component_FlowGraphNode.Representation.Connector referenceCreationSocketFrom, DragDropSetReferenceData dragDropSetReferenceData) { var representation = node.GetRepresentation(); var viewport = window.ViewportControl.Viewport; var mouse = viewport.MousePosition; var renderer = viewport.CanvasRenderer; FlowGraphRepresentationData representationData = new FlowGraphRepresentationData(); { var iRepresentationData = node.ControlledObject.Value as IFlowGraphRepresentationData; if (iRepresentationData != null) { iRepresentationData.GetFlowGraphRepresentationData(representationData); } } Vector2I nodeSize = representation.Size; RectangleI nodeRectWithOneBorder = new RectangleI(node.Position - new Vector2I(1, 1), node.Position + nodeSize + new Vector2I(1, 1)); //!!!!slowly var visibleCells = window.GetVisibleCells(); if (!visibleCells.Intersects(nodeRectWithOneBorder)) { return; } window.GetFontSizes(renderer, out var nodeFontSize, out var nodeFontSizeComment); Rectangle nodeRectInUnits = new RectangleI(node.Position, node.Position + nodeSize).ToRectangle(); Rectangle nodeRect = window.ConvertUnitToScreen(nodeRectInUnits); double cellHeight = window.ConvertUnitToScreenY(node.Position.Y + 1) - window.ConvertUnitToScreenY(node.Position.Y); //ColorValue totalNodeColorMultiplier = new ColorValue( 1, 1, 1 ); //{ // //if( settings.Error != null ) // // nodeColorMultiplier *= new ColorValue( 1, 0, 0 ); // //BlueprintGraphNodeObjectsEvent event_ = node as BlueprintGraphNodeObjectsEvent; // //if( event_ != null && !event_.Enabled ) // // nodeColorMultiplier = new ColorValue( .5f, .5f, .5f ); //} ColorValue nodeColorMultiplierWithSelection = /*totalNodeColorMultiplier*/ GetColorMultiplierSelectionState(selectionStateNode); ColorValue objColorMultiplierWithSelection = /*totalNodeColorMultiplier*/ GetColorMultiplierSelectionState(selectionStateControlledObject); //node selection if (selectionStateNode != EditorRenderSelectionState.None) { //node selection rectangle Rectangle nodeSelectionRectInUnits = nodeRectInUnits; nodeSelectionRectInUnits.Expand(.4); Rectangle nodeSelectionRect = window.ConvertUnitToScreen(nodeSelectionRectInUnits); renderer.AddQuad(nodeSelectionRect, new ColorValue(.3, .3, .3) * nodeColorMultiplierWithSelection); renderer.AddRectangle(nodeSelectionRect, new ColorValue(.6, .6, .6) * nodeColorMultiplierWithSelection); } //window { double titleHeight = cellHeight; //float titleHeight = ConvertUnitToScreenY( node.NodePosition.Y + 1 ) - ConvertUnitToScreenY( node.NodePosition.Y ); Rectangle titleRect = new Rectangle(nodeRect.Left, nodeRect.Top, nodeRect.Right, nodeRect.Top + titleHeight); Rectangle bodyRect = new Rectangle(nodeRect.Left, nodeRect.Top + titleHeight, nodeRect.Right, nodeRect.Bottom); //!!!! ColorValue contentTypeColor; ColorValue?titleColor = null; switch (representationData.NodeContentType) { case FlowGraphNodeContentType.Flow: contentTypeColor = new ColorValue(0.16 / 1.2, 0.34 / 1.2, 0.6 / 1.2); break; case FlowGraphNodeContentType.MethodBody: contentTypeColor = new ColorValue(0.45, 0.1, 0.1); break; case FlowGraphNodeContentType.FlowStart: contentTypeColor = new ColorValue(0.45, 0.1, 0.1); break; //case FlowchartNodeContentType.Flow: contentTypeColor = new ColorValue( 0.15, 0.15, 0.4 ); break; //case FlowchartNodeContentType.MethodBody: contentTypeColor = new ColorValue( 0.4, 0.1, 0.1 ); break; //!!!! default: //contentTypeColor = new ColorValue( 0.3, 0.3, 0.3 ); //titleColor = new ColorValue( 0.36, 0.36, 0.36 ); contentTypeColor = new ColorValue(0.26, 0.26, 0.26); //contentTypeColor = new ColorValue( 0.24, 0.24, 0.24 ); titleColor = new ColorValue(0.3, 0.3, 0.3); break; //default: contentTypeColor = new ColorValue( 0.3, 0.3, 0.3 ); break; } if (titleColor == null) { titleColor = contentTypeColor; } //!!!! //object is disabled { var c = node.ControlledObject.Value; if (c != null && !c.EnabledInHierarchy) { contentTypeColor *= new ColorValue(0.5, 0.5, 0.5, 1); } } if (selectionStateControlledObject != EditorRenderSelectionState.None) { titleColor = new ColorValue(0.3, 0.3, 0.3) * objColorMultiplierWithSelection; } //ColorValue titleColor; //if( selectionStateControlledObject == EditorRenderSelectionState.None ) // titleColor = contentTypeColor; //else // titleColor = new ColorValue( 0.3, 0.3, 0.3 ) * objColorMultiplierWithSelection; renderer.AddQuad(titleRect, titleColor.Value); //renderer.AddQuad( titleRect, new ColorValue( .3, .3, .3 ) * objColorMultiplierWithSelection ); renderer.AddQuad(bodyRect, contentTypeColor /* totalNodeColorMultiplier*/); //renderer.AddQuad( bodyRect, new ColorValue( .3, .3, .3 ) * totalNodeColorMultiplier ); //renderer.AddQuad( bodyRect, new ColorValue( 1, 1, 1 ) /*new ColorValue( .3, .3, .3 )*/ * nodeColorMultiplier ); //renderer.AddQuad( bodyRect, settings.BodyColor /*new ColorValue( .3, .3, .3 )*/ * nodeColorMultiplier ); //renderer.AddQuad( rect, new ColorValue( .3, .3, .3 ) * nodeColorMultiplierWithSelection ); renderer.AddRectangle(nodeRect, new ColorValue(.6, .6, .6) * objColorMultiplierWithSelection); renderer.AddLine( window.ConvertUnitToScreen(node.Position.ToVector2() + new Vector2(0, 1)), window.ConvertUnitToScreen(node.Position.ToVector2() + new Vector2(nodeSize.X, 1)), new ColorValue(.6, .6, .6) * objColorMultiplierWithSelection); //if( titleRect.IsContainsPoint( mouse ) ) // mouseOverObjects.AddWithCheckAlreadyContained( node ); } //!!!!было ////BlueprintGraphNodeComment: draw comment //if( node is BlueprintGraphNodeComment && !string.IsNullOrEmpty( node.NodeComment ) ) //{ // renderer.AddText( fontComment, node.NodeComment, rectNode.LeftTop, HorizontalAlign.Left, VerticalAlign.Bottom, // settings.CommentColor ); //} if (window.GetZoom() > .25f) { //Comment if (!string.IsNullOrEmpty(node.Comment)) //!!!!было && !( node is BlueprintGraphNodeComment ) ) { //!!!!style var color = new ColorValue(1, 1, 1); //settings.CommentColor renderer.AddText(window.NodeFontComment, nodeFontSizeComment, node.Comment, nodeRect.LeftTop, EHorizontalAlignment.Left, EVerticalAlignment.Bottom, color); } //title, texts { renderer.PushClipRectangle(nodeRect); //title { ColorValue titleColorMultiplier = new ColorValue(1, 1, 1); //!!!!было //if( node.IsFlowEntry() && !IsObjectSelected( node ) ) // titleColorMultiplier = new ColorValue( 1, 0, 0 ); Vector2 pos = window.ConvertUnitToScreen(node.Position.ToVector2() + new Vector2(.1f, 0)); renderer.AddText(window.NodeFont, nodeFontSize, representation.Title, pos, EHorizontalAlignment.Left, EVerticalAlignment.Top, titleColorMultiplier * objColorMultiplierWithSelection); } //!!!! ////texts //if( settings.Texts != null ) //{ // for( int n = 0; n < settings.Texts.Length; n++ ) // { // string text = settings.Texts[ n ]; // Vec2 pos2 = ConvertUnitToScreen( node.NodePosition.ToVec2() + new Vec2( .3, (float)n + 1 ) ); // renderer.AddText( fontValue, text, pos2 + new Vec2( 0, cellHeight * .05f ), EHorizontalAlign.Left, // EVerticalAlign.Top, new ColorValue( .7f, .7f, .7f ) * nodeColorMultiplierWithSelection ); // } //} renderer.PopClipRectangle(); } //client area { //!!!! var texture = representationData.NodeImage; if (texture != null) { Rectangle rect; if (representationData.NodeImageView == FlowGraphRepresentationData.NodeImageViewEnum.WideScaled) { double size = 6; rect = new Rectangle( node.Position.ToVector2() + new Vector2(0, representation.Size.Y - size), node.Position.ToVector2() + new Vector2(representation.Size.X, representation.Size.Y)); double border = 0.2; rect.Expand(-border); Rectangle rectInScreen = window.ConvertUnitToScreen(rect); var texCoords = new Rectangle(0, 0, 1, 1); var textureSize = texture.Result.ResultSize; var s = textureSize.ToVector2() / viewport.SizeInPixels.ToVector2(); var rect2 = new Rectangle(rectInScreen.Left, rectInScreen.Top, rectInScreen.Left + s.X, rectInScreen.Top + s.Y); renderer.PushClipRectangle(rectInScreen); renderer.PushTextureFilteringMode(CanvasRenderer.TextureFilteringMode.Point); renderer.AddQuad(rect2, new Rectangle(0, 0, 1, 1), texture); renderer.PopTextureFilteringMode(); renderer.PopClipRectangle(); } else { double size = 5; rect = new Rectangle( node.Position.ToVector2() + new Vector2(0, representation.Size.Y - size), node.Position.ToVector2() + new Vector2(size, representation.Size.Y)); double border = 0.2; rect.Expand(-border); Rectangle rectInScreen = window.ConvertUnitToScreen(rect); renderer.AddQuad(rectInScreen, new Rectangle(0, 0, 1, 1), texture); } //double size = 5; //double border = 0.2; //Rectangle rect = new Rectangle( // node.Position.ToVector2() + new Vector2( 0, representation.Size.Y - size ), // node.Position.ToVector2() + new Vector2( size, representation.Size.Y ) ); //rect.Expand( -border ); //Rectangle rectInScreen = window.ConvertUnitToScreen( rect ); //renderer.AddQuad( rectInScreen, new Rectangle( 0, 0, 1, 1 ), texture ); } } var mouseOverSocket = mouseOverObject as Component_FlowGraphNode.Representation.Connector; //items for (int nItem = 0; nItem < representation.Items.Count; nItem++) { var item = representation.Items[nItem]; ColorValue circleColorNotSpecified = new ColorValue(0.6, 0.6, 0.6); ColorValue circleColorSpecified = new ColorValue(1, 1, 1); ColorValue circleColorMouseOver = new ColorValue(1, 1, 0); ColorValue circleColorCanConnect = new ColorValue(1, 1, 0); bool isFlow = false; { var item2 = item as Component_FlowGraphNode.Representation.ItemProperty; //!!!!может кешировать, часто бывает if (item2 != null && MetadataManager.GetTypeOfNetType(typeof(FlowInput)).IsAssignableFrom(item2.Property.TypeUnreferenced)) { isFlow = true; } } //draw input circle if (item.Input != null) { Vector2 center = GetSocketPositionInUnits(item, true); Rectangle rect = window.ConvertUnitToScreen(new Rectangle(center - new Vector2(.25, .25), center + new Vector2(.25, .25))); ColorValue circleColor = circleColorNotSpecified; //check reference specified var itemProperty = item as Component_FlowGraphNode.Representation.ItemProperty; if (itemProperty != null && ReferenceUtility.IsReferenceType(itemProperty.Property.Type.GetNetType())) { Component obj = itemProperty.Owner.Owner.ControlledObject; if (obj != null) { var v = itemProperty.Property.GetValue(obj, null); var iReference = v as IReference; if (iReference != null && !string.IsNullOrEmpty(iReference.GetByReference)) { //!!!!инвалидная может быть circleColor = circleColorSpecified; } } } if (mouseOverSocket != null && mouseOverSocket.item == item && mouseOverSocket.input && referenceCreationSocketFrom == null && dragDropSetReferenceData == null) { circleColor = circleColorMouseOver; } if (referenceCreationSocketFrom != null && window.CanCreateReference(item.Input, referenceCreationSocketFrom)) { circleColor = circleColorCanConnect; } if (isFlow && dragDropSetReferenceData != null && window.CanCreateReferenceDragDropSetReference(dragDropSetReferenceData, item.Input, out string[] dummy))