Example #1
0
        public List <CallbackGeomListener> getFragments()
        {
            var callbackListeners = new List <CallbackGeomListener>();

            // create the callback object

            foreach (COMApi.InwOaPath3 path in oSel.Paths())
            {
                CallbackGeomListener callbkListener = new CallbackGeomListener();
                foreach (COMApi.InwOaFragment3 frag in path.Fragments())
                {
                    COMApi.InwLTransform3f3 localToWorld = (COMApi.InwLTransform3f3)(object) frag.GetLocalToWorldMatrix();

                    //create Global Cordinate System Matrix
                    Array   array_v1      = (Array)(object)localToWorld.Matrix;
                    var     elements      = ToArray <double>(array_v1);
                    float[] elementsFloat = new float[elements.Length];
                    for (int i = 0; i < elements.Length; i++)
                    {
                        elementsFloat[i] = (float)elements[i];
                    }

                    callbkListener.matrix = elementsFloat;
                    frag.GenerateSimplePrimitives(COMApi.nwEVertexProperty.eNORMAL, callbkListener);
                }
                callbackListeners.Add(callbkListener);
            }
            return(callbackListeners);
        }
Example #2
0
        private void VisitModelItem(Model model, ModelItem mi, NavModelNode node)
        {
            node.DisplayName = ((mi.DisplayName.Length == 0) ? mi.ClassDisplayName : mi.DisplayName);
            this.ReadProperties(mi, node);
            //如果该项目有几何图形
            bool hasGeometry = mi.HasGeometry;

            if (hasGeometry)
            {
                //转换为COM选择集
                Autodesk.Navisworks.Api.Interop.ComApi.InwOaPath inwOaPath = ComApiBridge.ToInwOaPath(mi);
                //创建回调对象
                NavGeometryCallback navGeometryCallback = new NavGeometryCallback();
                navGeometryCallback.UnitScaleToMM = (float)UnitConversion.ScaleFactor(model.Units, Units.Millimeters);
                foreach (InwOaFragment3 inwOaFragment in inwOaPath.Fragments())
                {
                    Autodesk.Navisworks.Api.Interop.ComApi.InwOpState10    state              = ComApiBridge.State;
                    Autodesk.Navisworks.Api.Interop.ComApi.InwOaPath3      inwOaPath2         = (Autodesk.Navisworks.Api.Interop.ComApi.InwOaPath3)inwOaFragment.path;
                    Autodesk.Navisworks.Api.Interop.ComApi.InwLTransform3f localToWorldMatrix = inwOaFragment.GetLocalToWorldMatrix();
                    Array array3 = (Array)(object)localToWorldMatrix.Matrix;


                    InwOaPath path = inwOaFragment.path;
                    ModelItem obj2 = ComApiBridge.ToModelItem(path);
                    bool      flag = !mi.Equals(obj2);
                    if (!flag)
                    {
                        ComApi.InwLTransform3f3 localToWorld = (ComApi.InwLTransform3f3)(object) inwOaFragment.GetLocalToWorldMatrix();
                        //Array array_v1 = (Array)(object)localToWorld.Matrix;

                        InwLTransform3f3 fragmentTransform = (InwLTransform3f3)inwOaFragment.GetLocalToWorldMatrix();
                        // navGeometryCallback.localToWorldMatrix =  inwOaFragment.GetLocalToWorldMatrix();
                        navGeometryCallback.FragmentTransform = fragmentTransform;
                        inwOaFragment.GenerateSimplePrimitives(nwEVertexProperty.eNORMAL, navGeometryCallback);
                    }
                }
                Color    originalColor = mi.Geometry.OriginalColor;
                NavColor color         = new NavColor((float)originalColor.R, (float)originalColor.G, (float)originalColor.B, 1f - (float)mi.Geometry.ActiveTransparency);
                navGeometryCallback.Geometry.Color = color;
                this.Geometries.Add(navGeometryCallback.Geometry);
                this.currentTriangleCount_ += navGeometryCallback.Geometry.Triangles.Count / 3;
                node.GeometryId             = string.Concat(navGeometryCallback.Geometry.Id);
                bool flag2 = this.currentTriangleCount_ >= this.maxTriangleCount_;
                if (flag2)
                {
                    this.WriteModel();
                }
            }
            foreach (ModelItem modelItem in mi.Children)
            {
                bool isHidden = modelItem.IsHidden;
                if (!isHidden)
                {
                    NavModelNode navModelNode = new NavModelNode();
                    node.Children.Add(navModelNode);
                    this.VisitModelItem(model, modelItem, navModelNode);
                }
            }
        }
        public static int Execute(/*params string[] parameters*/)
        {
            ComApi.InwOpState3 oState = ComApiBridge.ComApiBridge.State;

            Document doc = Application.ActiveDocument;

            ModelItemCollection currSelectionColl = doc.CurrentSelection.SelectedItems;

            if (currSelectionColl.Count > 0)
            {
                foreach (ModelItem item in currSelectionColl.DescendantsAndSelf)
                {
                    if (item.HasGeometry)
                    {
                        ComApi.InwOaPath oPath = ComApiBridge.ComApiBridge.ToInwOaPath(item);

                        Transform3D tr = item.Transform;//TODO: учитывать уже добавленную трансформацию!!!
                        //tr.Factor()
                        Transform3DComponents transform3DComponents = tr.Factor();
                        //transform3DComponents.ScaleOrientation
                        Point3D center = item.Geometry.BoundingBox.Center;

                        double z               = center.Z;
                        double zTransformed    = z * 1.1;
                        double correctionTrans = (z - zTransformed) /*/ 2*/;

                        ComApi.InwOpSelection comSelectionOut =
                            ComApiBridge.ComApiBridge.ToInwOpSelection(new ModelItemCollection()
                        {
                            item
                        });

                        ComApi.InwLTransform3f3 oTrans1
                            = (ComApi.InwLTransform3f3)oState
                              .ObjectFactory(ComApi.nwEObjectType.eObjectType_nwLTransform3f, null, null);
                        //растяжение по Z
                        ComApi.InwLVec3f scale
                            = (ComApi.InwLVec3f)oState
                              .ObjectFactory(ComApi.nwEObjectType.eObjectType_nwLVec3f, null, null);
                        scale.SetValue(1, 1, 1.1);
                        //смещение по Z
                        ComApi.InwLVec3f trans
                            = (ComApi.InwLVec3f)oState
                              .ObjectFactory(ComApi.nwEObjectType.eObjectType_nwLVec3f, null, null);
                        trans.SetValue(0, 0, correctionTrans);

                        //ComApi.InwLRotation3f scaleOrientation
                        //    = (ComApi.InwLRotation3f)oState
                        //    .ObjectFactory(ComApi.nwEObjectType.eObjectType_nwLRotation3f, null, null);
                        //ComApi.InwLUnitVec3f axis
                        //    = (ComApi.InwLUnitVec3f)oState
                        //    .ObjectFactory(ComApi.nwEObjectType.eObjectType_nwLUnitVec3f, null, null);
                        //axis.SetValue(0, 0, 1);
                        //scaleOrientation.SetValue(axis, 0);

                        //ComApi.InwLRotation3f Rotation
                        //    = (ComApi.InwLRotation3f)oState
                        //    .ObjectFactory(ComApi.nwEObjectType.eObjectType_nwLRotation3f, null, null);
                        //Rotation.SetValue(axis, 0);

                        //oTrans1.factor(scale, scaleOrientation, Rotation, trans);
                        //double[] matrix = ConvertDoubleArray((Array)((object)oTrans1.Matrix));

                        //oTrans1.MakeScale(scale);
                        //double[] matrix1 = ConvertDoubleArray((Array)((object)oTrans1.Matrix));
                        //oTrans1.MakeTranslation(trans);
                        //double[] matrix2 = ConvertDoubleArray((Array)((object)oTrans1.Matrix));

                        oTrans1.SetMatrix(new double[]
                        {
                            1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1.1, 0, 0, 0, correctionTrans, 1
                        });


                        //oTrans1.MakeScale(scaleVec);
                        oState.OverrideTransform(comSelectionOut, oTrans1);
                    }
                }
            }

            return(0);
        }