Esempio n. 1
0
        public override void Start()
        {
            // shaft1Direction = new Vector3(0, 0, 1);
            // shaft2Direction = new Vector3(0, 0, 1);

            // line1 = new GameObject().AddComponent<LineRenderer>();
            // line2 = new GameObject().AddComponent<LineRenderer>();

            ChCoordsys csys = new ChCoordsys(Utils.ToChrono(transform.position), Utils.ToChrono(transform.rotation));

            Initialize(body1, body2, csys);

            //// TODO: Check that this is correct.
            var rot1 = UnityEngine.Quaternion.Euler(shaft1Direction);

            //var rot1 = Quaternion.LookRotation(shaft1Direction.normalized);
            Set_local_shaft1(new ChFrame <double>(Utils.ToChrono(shaft1Origin), Utils.ToChrono(rot1)));
            var rot2 = UnityEngine.Quaternion.Euler(shaft2Direction);

            //var rot2 = Quaternion.LookRotation(shaft2Direction.normalized);
            Set_local_shaft2(new ChFrame <double>(Utils.ToChrono(shaft2Origin), Utils.ToChrono(rot2)));

            var height        = 2 * transform.localScale.y;
            var pulley2height = Body2.GetType();

            Set_r1(4);
            Set_r2(2);

            //ChSystem msystem = FindObjectOfType<ChSystem>();
            // msystem.AddLink(this);
            ChSystem.system.AddLink(this);
        }
Esempio n. 2
0
        //判断是否为多实体零件或钣金件
        private bool isMutiBodyOrSheetMetal(ref bool isBlank, ref bool isSM, ref bool isSolidBody, ref string strError)
        {
            if (m_ModelDoc != null)
            {
                PartDoc swPartDoc = (PartDoc)m_ModelDoc;
                if (swPartDoc != null)
                {
                    object[] vBodies = (object[])swPartDoc.GetBodies2((int)swBodyType_e.swAllBodies, false);
                    if (vBodies == null)
                    {
                        strError = "空白图纸";
                        isBlank  = true;
                        return(false);
                    }
                    if (vBodies.Length > 1)
                    {
                        return(true);
                    }
                    else if (vBodies.Length == 1)
                    {
                        Body2 body = (Body2)vBodies[0];
                        isSM = body.IsSheetMetal();

                        //识别文件类型体
                        isSolidBody = false;
                        switch (body.GetType())
                        {
                        case (int)swBodyType_e.swSolidBody:
                            strError    = "实体文件";
                            isSolidBody = true;
                            break;

                        case (int)swBodyType_e.swSheetBody:
                            strError = "板体文件";
                            break;

                        case (int)swBodyType_e.swEmptyBody:
                            strError = "空白体文件";
                            break;

                        case (int)swBodyType_e.swGeneralBody:
                            strError = "一般,非流形体文件";
                            break;

                        case (int)swBodyType_e.swMinimumBody:
                            strError = "点体文件";
                            break;

                        case (int)swBodyType_e.swWireBody:
                            strError = "线体文件";
                            break;
                        }
                    }
                }
            }

            return(false);
        }
        /// <summary>
        /// generateToken
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="body"></param>
        /// <param name="portalWebAdaptor"></param>
        /// <returns>Task of ApiResponse (TokenResponse)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <TokenResponse> > PortalWebAdaptorSharingRestGenerateTokenPostAsyncWithHttpInfo(Body2 body, string portalWebAdaptor)
        {
            // verify the required parameter 'body' is set
            if (body == null)
            {
                throw new ApiException(400, "Missing required parameter 'body' when calling UtilityNetworkServiceApi->PortalWebAdaptorSharingRestGenerateTokenPost");
            }
            // verify the required parameter 'portalWebAdaptor' is set
            if (portalWebAdaptor == null)
            {
                throw new ApiException(400, "Missing required parameter 'portalWebAdaptor' when calling UtilityNetworkServiceApi->PortalWebAdaptorSharingRestGenerateTokenPost");
            }

            var    localVarPath         = "/{PortalWebAdaptor}/sharing/rest/generateToken";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json"
            };
            String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json"
            };
            String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (portalWebAdaptor != null)
            {
                localVarPathParams.Add("PortalWebAdaptor", this.Configuration.ApiClient.ParameterToString(portalWebAdaptor));                           // path parameter
            }
            if (body != null && body.GetType() != typeof(byte[]))
            {
                localVarPostBody = this.Configuration.ApiClient.Serialize(body); // http body (model) parameter
            }
            else
            {
                localVarPostBody = body; // byte array
            }

            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await this.Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                            Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                            localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("PortalWebAdaptorSharingRestGenerateTokenPost", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <TokenResponse>(localVarStatusCode,
                                                   localVarResponse.Headers.ToDictionary(x => x.Name, x => string.Join(",", x.Value)),
                                                   (TokenResponse)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(TokenResponse))));
        }
Esempio n. 4
0
        /// Convert a SolidWorks component to Wavefront OBJ mesh
        ///
        public static void Convert(Component2 swComp, ref string asciitext, bool saveUV, ref UserProgressBar swProgress)
        {
            StringBuilder textbuilder = new StringBuilder();
            Body2         swBody      = default(Body2);

            object[] vBodies      = null;
            object[] vBodiesSolid = null;
            object[] vBodiesSheet = null;
            object   vBodyInfo;

            int[]     BodiesInfo = null;
            int       j          = 0;
            ModelDoc2 swModel;


            swModel = (ModelDoc2)swComp.GetModelDoc();

            vBodiesSolid = (object[])swComp.GetBodies3((int)swBodyType_e.swSolidBody, out vBodyInfo);
            vBodiesSheet = (object[])swComp.GetBodies3((int)swBodyType_e.swSheetBody, out vBodyInfo);
            BodiesInfo   = (int[])vBodyInfo;

            if (vBodiesSolid != null && vBodiesSheet == null)
            {
                vBodies = vBodiesSolid;
            }

            if (vBodiesSolid == null && vBodiesSheet != null)
            {
                vBodies = vBodiesSheet;
            }

            if (vBodiesSolid != null && vBodiesSheet != null)
            {
                vBodies = vBodiesSheet.Concat(vBodiesSolid).ToArray();
            }

            // vBodies = (object[])swComp.GetBodies3((int)swBodyType_e.swSolidBody, out vBodyInfo);


            if (vBodies != null)
            {
                int iNumBodies           = vBodies.Length;
                int iNumSolidBodies      = 0;
                int iNumSheetBodies      = 0;
                int iNumTesselatedBodies = 0;


                if (iNumBodies > 0)
                {
                    asciitext += "# Wavefront .OBJ file for tesselated shape: " + swComp.Name2 + " path: " + swModel.GetPathName() + "\n\n";
                }

                int group_vstride = 0;
                int group_nstride = 0;

                // Loop through bodies
                for (j = 0; j <= vBodies.Length - 1; j++)
                {
                    swBody = (Body2)vBodies[j];

                    int nBodyType = (int)swBody.GetType();

                    if (nBodyType == (int)swBodyType_e.swSheetBody)
                    {
                        iNumSheetBodies++;
                    }

                    if (nBodyType == (int)swBodyType_e.swSolidBody)
                    {
                        iNumSolidBodies++;
                    }

                    if ((nBodyType == (int)swBodyType_e.swSheetBody ||
                         nBodyType == (int)swBodyType_e.swSolidBody) &&
                        !swBody.Name.StartsWith("COLL.") &&
                        swBody.Visible)
                    {
                        iNumTesselatedBodies++;

                        CultureInfo bz = new CultureInfo("en-BZ");

                        //asciitext += "g body_" + iNumTesselatedBodies + "\n";
                        textbuilder.Append("g body_" + iNumTesselatedBodies + "\n");

                        Face2        swFace         = null;
                        Tessellation swTessellation = null;

                        bool bResult = false;

                        // Pass in null so the whole body will be tessellated
                        swTessellation = (Tessellation)swBody.GetTessellation(null);

                        // Set up the Tessellation object
                        swTessellation.NeedFaceFacetMap = true;
                        swTessellation.NeedVertexParams = true;
                        swTessellation.NeedVertexNormal = true;
                        swTessellation.ImprovedQuality  = true;

                        // How to handle matches across common edges
                        swTessellation.MatchType = (int)swTesselationMatchType_e.swTesselationMatchFacetTopology;

                        // Do it
                        if (swProgress != null)
                        {
                            swProgress.UpdateTitle("Exporting (tesselate process) ...");
                        }
                        bResult = swTessellation.Tessellate();

                        // Get the number of vertices and facets
                        //System.Windows.Forms.MessageBox.Show("Body n." + j + " vert.num=" + swTessellation.GetVertexCount());
                        //Debug.Print("Number of vertices: " + swTessellation.GetVertexCount());
                        //Debug.Print("Number of facets: " + swTessellation.GetFacetCount());

                        // Now get the facet data per face
                        int[]    aFacetIds;
                        int      iNumFacetIds;
                        int[]    aFinIds;
                        int[]    aVertexIds;
                        double[] aNormal;
                        double[] aVertexCoords1;
                        double[] aVertexCoords2;
                        double[] aVertexParams;

                        int numv = swTessellation.GetVertexCount();

                        // Write all vertexes
                        string mline;

                        for (int iv = 0; iv < numv; iv++)
                        {
                            if ((swProgress != null) && (iv % 200 == 0))
                            {
                                swProgress.UpdateTitle("Exporting (write " + iv + "-th vertex in .obj) ...");
                            }
                            aVertexCoords1 = (double[])swTessellation.GetVertexPoint(iv);
                            mline          = "v " + (aVertexCoords1[0] * ChScale.L).ToString("f6", bz)
                                             + " " + (aVertexCoords1[1] * ChScale.L).ToString("f6", bz)
                                             + " " + (aVertexCoords1[2] * ChScale.L).ToString("f6", bz)
                                             + "\n";
                            textbuilder.Append(mline);
                        }

                        // Write all normals
                        for (int iv = 0; iv < numv; iv++)
                        {
                            if ((swProgress != null) && (iv % 200 == 0))
                            {
                                swProgress.UpdateTitle("Exporting (write " + iv + "-th normal in .obj) ...");
                            }
                            aNormal = (double[])swTessellation.GetVertexNormal(iv);
                            mline   = "vn " + aNormal[0].ToString("f3", bz)
                                      + " " + aNormal[1].ToString("f3", bz)
                                      + " " + aNormal[2].ToString("f3", bz)
                                      + "\n";
                            textbuilder.Append(mline);
                        }
                        if (nBodyType == (int)swBodyType_e.swSheetBody)  // for sheets, save two-sided triangles
                        {
                            for (int iv = 0; iv < numv; iv++)
                            {
                                if ((swProgress != null) && (iv % 200 == 0))
                                {
                                    swProgress.UpdateTitle("Exporting (write " + iv + "-th normal in .obj) ...");
                                }
                                aNormal = (double[])swTessellation.GetVertexNormal(iv);
                                mline   = "vn " + (-aNormal[0]).ToString("f3", bz)
                                          + " " + (-aNormal[1]).ToString("f3", bz)
                                          + " " + (-aNormal[2]).ToString("f3", bz)
                                          + "\n";
                                textbuilder.Append(mline);
                            }
                        }

                        // Write all UV (also with '0' as third value, for compatibility with some OBJ reader)
                        if (saveUV)
                        {
                            for (int iv = 0; iv < numv; iv++)
                            {
                                if ((swProgress != null) && (iv % 200 == 0))
                                {
                                    swProgress.UpdateTitle("Exporting (write " + iv + "-th UV in .obj) ...");
                                }
                                aVertexParams = (double[])swTessellation.GetVertexParams(iv);
                                mline         = "vt " + aVertexParams[0].ToString("f4", bz)
                                                + " " + aVertexParams[1].ToString("f4", bz)
                                                + " " + "0"
                                                + "\n";
                                textbuilder.Append(mline);
                            }
                        }


                        // Loop over faces
                        swFace = (Face2)swBody.GetFirstFace();
                        while (swFace != null)
                        {
                            aFacetIds = (int[])swTessellation.GetFaceFacets(swFace);

                            iNumFacetIds = aFacetIds.Length;

                            for (int iFacetIdIdx = 0; iFacetIdIdx < iNumFacetIds; iFacetIdIdx++)
                            {
                                if ((swProgress != null) && (iFacetIdIdx % 100 == 0))
                                {
                                    swProgress.UpdateTitle("Exporting (write " + iFacetIdIdx + "-th face in .obj) ...");
                                }

                                mline = "f";

                                aFinIds = (int[])swTessellation.GetFacetFins(aFacetIds[iFacetIdIdx]);

                                // There should always be three fins per facet
                                for (int iFinIdx = 0; iFinIdx < 3; iFinIdx++)
                                {
                                    aVertexIds = (int[])swTessellation.GetFinVertices(aFinIds[iFinIdx]);

                                    // Three fins per face, two vertexes each fin,
                                    // only the 1st vertex of two is needed (because of sharing)
                                    if (saveUV)
                                    {
                                        mline += " " + (aVertexIds[0] + group_vstride + 1) + "/"
                                                 + (aVertexIds[0] + group_vstride + 1) + "/"
                                                 + (aVertexIds[0] + group_nstride + 1);
                                    }
                                    else
                                    {
                                        mline += " " + (aVertexIds[0] + group_vstride + 1) + "//"
                                                 + (aVertexIds[0] + group_nstride + 1);
                                    }
                                }

                                mline += "\n";
                                textbuilder.Append(mline);
                            }
                            swFace = (Face2)swFace.GetNextFace();
                        }

                        swFace = (Face2)swBody.GetFirstFace();
                        if (nBodyType == (int)swBodyType_e.swSheetBody)  // for sheets, save two-sided triangles
                        {
                            while (swFace != null)
                            {
                                aFacetIds = (int[])swTessellation.GetFaceFacets(swFace);

                                iNumFacetIds = aFacetIds.Length;

                                for (int iFacetIdIdx = 0; iFacetIdIdx < iNumFacetIds; iFacetIdIdx++)
                                {
                                    if ((swProgress != null) && (iFacetIdIdx % 100 == 0))
                                    {
                                        swProgress.UpdateTitle("Exporting (write " + iFacetIdIdx + "-th face in .obj) ...");
                                    }

                                    mline = "f";

                                    aFinIds = (int[])swTessellation.GetFacetFins(aFacetIds[iFacetIdIdx]);

                                    for (int iFinIdx = 2; iFinIdx >= 0; iFinIdx--)
                                    {
                                        aVertexIds = (int[])swTessellation.GetFinVertices(aFinIds[iFinIdx]);

                                        if (saveUV)
                                        {
                                            mline += " " + (aVertexIds[0] + group_vstride + 1) + "/"
                                                     + (aVertexIds[0] + group_vstride + 1) + "/"
                                                     + (aVertexIds[0] + swTessellation.GetVertexCount() + group_nstride + 1);
                                        }
                                        else
                                        {
                                            mline += " " + (aVertexIds[0] + group_vstride + 1) + "//"
                                                     + (aVertexIds[0] + swTessellation.GetVertexCount() + group_nstride + 1);
                                        }
                                    }

                                    mline += "\n";
                                    textbuilder.Append(mline);
                                }
                                swFace = (Face2)swFace.GetNextFace();
                            }
                        }

                        group_vstride += swTessellation.GetVertexCount();
                        group_nstride += swTessellation.GetVertexCount();

                        if (nBodyType == (int)swBodyType_e.swSheetBody)  // for sheets: two-sided triangles
                        {
                            group_nstride += swTessellation.GetVertexCount();
                        }
                    }
                } // end loop on bodies
            }     // not null body

            asciitext += textbuilder.ToString();
        }