/// <summary> /// Moves a Visual3D object to a new position. It updates the Position property. /// </summary> /// <remarks> /// The successive transformation operations (translation, scaling or rotation) are cumulative (the last one is relative to its previous one). /// </remarks> /// <param name="visual">A Visual3D object to move.</param> /// <param name="p">A Point3D object designing the new position.</param> public void MoveTo(Visual3D visual, Point3D p) { Matrix3D matrix = (Matrix3D)visual.GetValue(MatrixProperty); matrix.OffsetX = p.X; matrix.OffsetY = p.Y; matrix.OffsetZ = p.Z; visual.SetValue(MatrixPropertyKey, matrix); ApplyTransform(visual); visual.SetValue(PositionPropertyKey, p); }
/// <summary> /// Translates a Visual3D object. /// </summary> /// <remarks> /// The successive transformation operations (translation, scaling or rotation) are cumulative (the last one is relative to its previous one). /// </remarks> /// <param name="visual">A Visual3D object to scale.</param> /// <param name="v">A vector containing the x-, y- and z-axis offsets.</param> public void Translate(Visual3D visual, Vector3D v) { Matrix3D matrix = (Matrix3D)visual.GetValue(MatrixProperty); matrix.Translate(v); visual.SetValue(MatrixPropertyKey, matrix); ApplyTransform(visual); Point3D position = (Point3D)visual.GetValue(PositionProperty) + v; visual.SetValue(PositionPropertyKey, position); }
/// <summary> /// Rotates a Visual3D object around the z-axis. /// </summary> /// <remarks> /// The successive transformation operations (translation, scaling or rotation) are cumulative (the last one is relative to its previous one). /// </remarks> /// <param name="visual">A Visual3D object to rotate.</param> /// <param name="angle">The angle of the z-axis rotation, in degrees.</param> public void RotateZ(Visual3D visual, double angle) { Matrix3D matrix = (Matrix3D)visual.GetValue(MatrixProperty); Quaternion q = new Quaternion(new Vector3D(0, 0, 1) * matrix, angle); matrix.RotateAt(q, (Point3D)visual.GetValue(PositionProperty)); visual.SetValue(MatrixPropertyKey, matrix); ApplyTransform(visual); }
/// <summary> /// Scales a Visual3D object. /// </summary> /// <remarks> /// The successive transformation operations (translation, scaling or rotation) are cumulative (the last one is relative to its previous one). /// </remarks> /// <param name="visual">A Visual3D object to scale.</param> /// <param name="v">A vector containing the x-, y- and z-axis scale factors.</param> public void Scale(Visual3D visual, Vector3D v) { Matrix3D matrix = (Matrix3D)visual.GetValue(MatrixProperty); matrix.ScaleAt( v, (Point3D)visual.GetValue(PositionProperty)); visual.SetValue(MatrixPropertyKey, matrix); ApplyTransform(visual); }
/// <summary> /// Rotates a Visual3D object around the z-, y- and then x-axis. /// </summary> /// <remarks> /// The successive transformation operations (translation, scaling or rotation) are cumulative (the last one is relative to its previous one). /// </remarks> /// <param name="visual">A Visual3D object to rotate.</param> /// <param name="angleX">The angle of the x-axis rotation, in degrees.</param> /// <param name="angleY">The angle of the y-axis rotation, in degrees.</param> /// <param name="angleZ">The angle of the z-axis rotation, in degrees.</param> public void RotateZYX(Visual3D visual, double angleX, double angleY, double angleZ) { Point3D position = (Point3D)visual.GetValue(PositionProperty); Matrix3D matrix = (Matrix3D)visual.GetValue(MatrixProperty); matrix.RotateAt(new Quaternion(new Vector3D(0, 0, 1) * matrix, angleZ), position); matrix.RotateAt(new Quaternion(new Vector3D(0, 1, 0) * matrix, angleY), position); matrix.RotateAt(new Quaternion(new Vector3D(1, 0, 0) * matrix, angleX), position); visual.SetValue(MatrixPropertyKey, matrix); ApplyTransform(visual); }
private void ApplyTransform(Visual3D visual) { Matrix3D matrix = (Matrix3D)visual.GetValue(MatrixProperty); MatrixTransform3D previousMatrixTransform = (MatrixTransform3D)visual.GetValue(MatrixTransformProperty); visual.SetValue(PreviousMatrixTransformPropertyKey, previousMatrixTransform); // new instance because MatrixTransform3D may be frozen and can't accept a new matrix MatrixTransform3D matrixTransform = new MatrixTransform3D(matrix); visual.SetValue(MatrixTransformPropertyKey, matrixTransform); if (visual.Transform != null) { if (visual.Transform is Transform3DGroup) { Transform3DGroup transformGroup = (Transform3DGroup)visual.Transform; if (!transformGroup.Children.Contains(previousMatrixTransform)) { transformGroup.Children.Add(matrixTransform); } else { int previousIndex = transformGroup.Children.IndexOf(previousMatrixTransform); transformGroup.Children[previousIndex] = matrixTransform; } } else { Transform3DGroup transformGroup = new Transform3DGroup(); transformGroup.Children.Add(visual.Transform); transformGroup.Children.Add(matrixTransform); visual.Transform = transformGroup; } } else { visual.Transform = matrixTransform; } }
private static Visual3D MakeVisual3D(Variation v, string visualName) { string skipName = visualName.Replace("Visual", "Skip"); string skipType = v[skipName] == null ? string.Empty : v[skipName]; string visualType = v[visualName.Replace("Visual", "VisualType")]; string visualTransformName = visualName.Replace("Visual", "VisualTransform"); Visual3D visual = null; if (visualType == null || visualType == "ModelVisual3D") { //Default V1 test codepath visual = MakeModelVisual3D(v, visualName); ((ModelVisual3D)visual).Transform = TransformFactory.MakeTransform(v[visualTransformName]); } #if TARGET_NET3_5 else if (visualType == "ModelUIElement3D") { visual = MakeModelUIElement3D(v, visualName); visual.Transform = TransformFactory.MakeTransform(v[visualTransformName]); } else if (visualType == "ViewportVisual3D") { visual = MakeViewportVisual3D(v, visualName); visual.Transform = TransformFactory.MakeTransform(v[visualTransformName]); } #endif else { throw new ArgumentException("Unable to create VisualType (" + visualType + ")." + "Supported types are ModelVisual3D (+V3.5 ModelUIElement3D and ViewportVisual3D)."); } visual.SetValue(Const.SkipProperty, skipType); return(visual); }
public static void SetPrimitiveData(Visual3D target, SelectablePrimitive value) { target.SetValue(PrimitiveDataProperty, value); }
internal static bool TryAddObject(EnvDTE.Expression exp, HelixViewport3D hv, Map <string, ModelVisual3D> _dict) { if (!exp.IsValidValue) { return(false); } // get type string type = exp.Type; // create the 3d ModelVisual3D _mv3d; Logger.Log("", string.Format("Searching this type in dictionary: {0}", type)); // try get object from dictionary MetaObject obj; if (dictType_.TryGetValue(type, out obj)) { // let's create a brand new one obj = obj.InstantiateNew(); obj.Run(exp); _mv3d = obj.To3DViz(); obj.VisualizationProperties(_mv3d); } else if (IsEnumerable(exp)) { // clean from enumerables' characters type = CleanFromEnumerables(type); if (!dictType_.TryGetValue(type, out obj)) { Logger.Log("", string.Format("Could not find this type in dictionary: {0}", type)); return(false); } // let's create a brand new one obj = obj.InstantiateNew(); _mv3d = new ModelVisual3D(); foreach (EnvDTE.Expression exp1 in ReaderUtils.ReadEnumerable(exp)) { obj.Run(exp1); ModelVisual3D mv3d = obj.To3DViz(); obj.VisualizationProperties(mv3d); _mv3d.Children.Add(mv3d); } } else { Logger.Log("", string.Format("Could not find this type in dictionary: {0}", type)); return(false); } if (_mv3d.Children != null && _mv3d.Children.Count > 0) { for (int i = 0; i < _mv3d.Children.Count; i++) { Visual3D mv3d = _mv3d.Children[i]; // new bindings Binding myBinding = new Binding(); myBinding.Source = mv3d; myBinding.Path = new PropertyPath("MyProperties"); myBinding.Mode = BindingMode.TwoWay; myBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; // set bindings BindingOperations.SetBinding(mv3d, MyProperties.MyParentProperty, myBinding); // set value mv3d.SetValue(MyProperties.MyParentProperty, _mv3d); } } Logger.Log(exp, string.Format("Add3D")); _mv3d.SetName(exp.Name); // add to dict and viewport _dict.Add(exp.Name, _mv3d); hv.Items.Add(_mv3d); // exit Logger.Log(exp, string.Format("Add3D - Added to dict")); return(true); }
// Token: 0x06000691 RID: 1681 RVA: 0x00014908 File Offset: 0x00012B08 internal DependencyObject InstantiateTree(UncommonField <HybridDictionary[]> dataField, DependencyObject container, DependencyObject parent, List <DependencyObject> affectedChildren, ref List <DependencyObject> noChildIndexChildren, ref FrugalStructList <ChildPropertyDependent> resourceDependents) { EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose, EventTrace.Event.WClientParseFefCrInstBegin); FrameworkElement frameworkElement = container as FrameworkElement; bool flag = frameworkElement != null; DependencyObject dependencyObject = null; if (this._text != null) { IAddChild addChild = parent as IAddChild; if (addChild == null) { throw new InvalidOperationException(SR.Get("TypeMustImplementIAddChild", new object[] { parent.GetType().Name })); } addChild.AddText(this._text); } else { dependencyObject = this.CreateDependencyObject(); EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose, EventTrace.Event.WClientParseFefCrInstEnd); FrameworkObject frameworkObject = new FrameworkObject(dependencyObject); Visual3D visual3D = null; bool flag2 = false; if (!frameworkObject.IsValid) { visual3D = (dependencyObject as Visual3D); if (visual3D != null) { flag2 = true; } } bool isFE = frameworkObject.IsFE; if (!flag2) { FrameworkElementFactory.NewNodeBeginInit(isFE, frameworkObject.FE, frameworkObject.FCE); if (StyleHelper.HasResourceDependentsForChild(this._childIndex, ref resourceDependents)) { frameworkObject.HasResourceReference = true; } FrameworkElementFactory.UpdateChildChains(this._childName, this._childIndex, isFE, frameworkObject.FE, frameworkObject.FCE, affectedChildren, ref noChildIndexChildren); FrameworkElementFactory.NewNodeStyledParentProperty(container, flag, isFE, frameworkObject.FE, frameworkObject.FCE); if (this._childIndex != -1) { StyleHelper.CreateInstanceDataForChild(dataField, container, dependencyObject, this._childIndex, this._frameworkTemplate.HasInstanceValues, ref this._frameworkTemplate.ChildRecordFromChildIndex); } if (this.HasLoadedChangeHandler) { BroadcastEventHelper.AddHasLoadedChangeHandlerFlagInAncestry(dependencyObject); } } else if (this._childName != null) { affectedChildren.Add(dependencyObject); } else { if (noChildIndexChildren == null) { noChildIndexChildren = new List <DependencyObject>(4); } noChildIndexChildren.Add(dependencyObject); } if (container == parent) { TemplateNameScope value = new TemplateNameScope(container); NameScope.SetNameScope(dependencyObject, value); if (flag) { frameworkElement.TemplateChild = frameworkObject.FE; } else { FrameworkElementFactory.AddNodeToLogicalTree((FrameworkContentElement)parent, this._type, isFE, frameworkObject.FE, frameworkObject.FCE); } } else { this.AddNodeToParent(parent, frameworkObject); } if (!flag2) { StyleHelper.InvalidatePropertiesOnTemplateNode(container, frameworkObject, this._childIndex, ref this._frameworkTemplate.ChildRecordFromChildIndex, false, this); } else { for (int i = 0; i < this.PropertyValues.Count; i++) { if (this.PropertyValues[i].ValueType != PropertyValueType.Set) { throw new NotSupportedException(SR.Get("Template3DValueOnly", new object[] { this.PropertyValues[i].Property })); } object obj = this.PropertyValues[i].ValueInternal; Freezable freezable = obj as Freezable; if (freezable != null && !freezable.CanFreeze) { obj = freezable.Clone(); } MarkupExtension markupExtension = obj as MarkupExtension; if (markupExtension != null) { ProvideValueServiceProvider provideValueServiceProvider = new ProvideValueServiceProvider(); provideValueServiceProvider.SetData(visual3D, this.PropertyValues[i].Property); obj = markupExtension.ProvideValue(provideValueServiceProvider); } visual3D.SetValue(this.PropertyValues[i].Property, obj); } } for (FrameworkElementFactory frameworkElementFactory = this._firstChild; frameworkElementFactory != null; frameworkElementFactory = frameworkElementFactory._nextSibling) { frameworkElementFactory.InstantiateTree(dataField, container, dependencyObject, affectedChildren, ref noChildIndexChildren, ref resourceDependents); } if (!flag2) { FrameworkElementFactory.NewNodeEndInit(isFE, frameworkObject.FE, frameworkObject.FCE); } } return(dependencyObject); }