当前位置: 首页>>代码示例>>C#>>正文


C# Part.FindModelComponents方法代码示例

本文整理汇总了C#中Part.FindModelComponents方法的典型用法代码示例。如果您正苦于以下问题:C# Part.FindModelComponents方法的具体用法?C# Part.FindModelComponents怎么用?C# Part.FindModelComponents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Part的用法示例。


在下文中一共展示了Part.FindModelComponents方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CalculateExtents

        public static Vector3 CalculateExtents(Part p, Quaternion alignment)
        {
            Vector3 maxBounds = new Vector3(-100, -100, -100);
            Vector3 minBounds = new Vector3(100, 100, 100);

            // alignment transforms from our desired rotation to the local coordinates, so inverse needed
            Matrix4x4 rotation = Matrix4x4.TRS(Vector3.zero, Quaternion.Inverse(alignment), Vector3.one);
            Matrix4x4 base_matrix = rotation * p.transform.worldToLocalMatrix;

            foreach (Transform t in p.FindModelComponents<Transform>())         //Get the max boundaries of the part
            {
                MeshFilter mf = t.GetComponent<MeshFilter>();
                if (mf == null)
                    continue;
                Mesh m = mf.sharedMesh;

                if (m == null)
                    continue;

                Matrix4x4 matrix = base_matrix * t.transform.localToWorldMatrix;

                foreach (Vector3 vertex in m.vertices)
                {
                    Vector3 v = matrix.MultiplyPoint3x4(vertex);

                    maxBounds.x = Mathf.Max(maxBounds.x, v.x);
                    minBounds.x = Mathf.Min(minBounds.x, v.x);
                    maxBounds.y = Mathf.Max(maxBounds.y, v.y);
                    minBounds.y = Mathf.Min(minBounds.y, v.y);
                    maxBounds.z = Mathf.Max(maxBounds.z, v.z);
                    minBounds.z = Mathf.Min(minBounds.z, v.z);
                }
            }

            if (maxBounds == new Vector3(-100, -100, -100) && minBounds == new Vector3(100, 100, 100))
            {
                Debug.LogWarning("KerbalJointReinforcement: extents could not be properly built for part " + p.partInfo.title);
                maxBounds = minBounds = Vector3.zero;
            }
            else if (debug)
                Debug.Log("Extents: " + minBounds + " .. " + maxBounds + " = " + (maxBounds - minBounds));

            //attachNodeLoc = p.transform.worldToLocalMatrix.MultiplyVector(p.parent.transform.position - p.transform.position);
            return maxBounds - minBounds;
        }
开发者ID:Boris-Barboris,项目名称:Kerbal-Joint-Reinforcement,代码行数:45,代码来源:KJRJointUtils.cs

示例2: IgnoreModelTransformList

        private static List<Transform> IgnoreModelTransformList(Part p)
        {
            PartModule module;
            string transformString;
            List<Transform> Transform = new List<Transform>();
            //Transform[] tmp1, tmp2;
            //tmp1 = tmp2 = new Transform[0];

            if (p.Modules.Contains("FSplanePropellerSpinner"))
            {
                module = p.Modules["FSplanePropellerSpinner"];
                transformString = (string)module.GetType().GetField("propellerName").GetValue(module);
                if (transformString != "")
                {
                    Transform.AddRange(p.FindModelComponents<Transform>(transformString));
                }
                transformString = (string)module.GetType().GetField("rotorDiscName").GetValue(module);
                if (transformString != "")
                {
                    Transform.AddRange(p.FindModelComponents<Transform>(transformString));
                }

                transformString = (string)module.GetType().GetField("blade1").GetValue(module);
                if (transformString != "")
                {
                    Transform.AddRange(p.FindModelComponents<Transform>(transformString));
                }

                transformString = (string)module.GetType().GetField("blade2").GetValue(module);
                if (transformString != "")
                {
                    Transform.AddRange(p.FindModelComponents<Transform>(transformString));
                }

                transformString = (string)module.GetType().GetField("blade3").GetValue(module);
                if (transformString != "")
                {
                    Transform.AddRange(p.FindModelComponents<Transform>(transformString));
                }

                transformString = (string)module.GetType().GetField("blade4").GetValue(module);
                if (transformString != "")
                {
                    Transform.AddRange(p.FindModelComponents<Transform>(transformString));
                }
                transformString = (string)module.GetType().GetField("blade5").GetValue(module);
                if (transformString != "")
                {
                    Transform.AddRange(p.FindModelComponents<Transform>(transformString));
                }
            }
            if (p.Modules.Contains("FScopterThrottle"))
            {
                module = p.Modules["FScopterThrottle"];
                transformString = (string)module.GetType().GetField("rotorparent").GetValue(module);
                if (transformString != "")
                {
                    Transform.AddRange(p.FindModelComponents<Transform>(transformString));
                }
            }
            if (p.Modules.Contains("ModuleParachute"))
            {
                module = p.Modules["ModuleParachute"];
                transformString = (string)module.GetType().GetField("canopyName").GetValue(module);
                if (transformString != "")
                {
                    Transform.AddRange(p.FindModelComponents<Transform>(transformString));
                }
            }
            if (p.Modules.Contains("RealChuteModule"))
            {
                module = p.Modules["RealChuteModule"];
                transformString = (string)module.GetType().GetField("parachuteName").GetValue(module);
                if (transformString != "")
                {
                    Transform.AddRange(p.FindModelComponents<Transform>(transformString));
                }
                transformString = (string)module.GetType().GetField("secParachuteName").GetValue(module);
                if (transformString != "")
                {
                    Transform.AddRange(p.FindModelComponents<Transform>(transformString));
                }
            }
            foreach (Transform t in p.FindModelComponents<Transform>())
            {
                if (Transform.Contains(t))
                    continue;

                string tag = t.tag.ToLowerInvariant();
                if (tag == "ladder" || tag == "airlock")
                    Transform.Add(t);
            }

            return Transform;
        }
开发者ID:vosechu,项目名称:Ferram-Aerospace-Research,代码行数:95,代码来源:FARGeoUtil.cs

示例3: renderPart


//.........这里部分代码省略.........
                            {
                                partColor.r = partColor.r / 2;
                                partColor.g = partColor.g / 2;
                                partColor.b = partColor.b / 2;
                            } break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.STATIC:
                            if (customMode.staticSettings.colorModeWireDull)
                            {
                                partColor.r = partColor.r / 2;
                                partColor.g = partColor.g / 2;
                                partColor.b = partColor.b / 2;
                            } break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.FUNCTION:
                            if (customMode.wireColorDullDelegate(customMode))
                            {
                                partColor.r = partColor.r / 2;
                                partColor.g = partColor.g / 2;
                                partColor.b = partColor.b / 2;
                            } break;
                    }
                }
            }
            
            //now we need to get all meshes in the part
            List<MeshFilter> meshFList = new List<MeshFilter>();
            foreach (MeshFilter mf in part.transform.GetComponentsInChildren<MeshFilter>())
            {
                meshFList.Add(mf);
            }
            
            //MeshFilter[] meshFilters = (MeshFilter[])part.FindModelComponents<MeshFilter>();
            MeshFilter[] meshFilters = meshFList.ToArray();
            //used to determine the part bounding box
            Vector3 minVec = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
            Vector3 maxVec = new Vector3(float.MinValue, float.MinValue, float.MinValue);
            foreach (MeshFilter meshF in meshFilters)
            {
                if (!(meshF.renderer == null))
                {
                    //only render those meshes that are active
                    //examples of inactive meshes seem to include
                    //parachute canopies, engine fairings...
                    
                    if (meshF.renderer.gameObject.activeInHierarchy)
                    {
                        Mesh mesh = meshF.mesh;
                        //create the trans. matrix for this mesh (also update the bounds)
                        Matrix4x4 transMatrix = genTransMatrix(meshF.transform, FlightGlobals.ActiveVessel,false);
                        updateMinMax(mesh.bounds, transMatrix, ref minVec, ref maxVec);
                        transMatrix = scrnMatrix * transMatrix;
                        //now render it
                        if(!partColor.Equals(Color.black))
                            //renderMesh(mesh, transMatrix, partColor);
                            renderMesh(mesh.triangles, mesh.vertices, transMatrix, partColor);
                    }
                }
            }

            SkinnedMeshRenderer[] skinnedMeshes = (SkinnedMeshRenderer[])part.FindModelComponents<SkinnedMeshRenderer>();
            foreach (SkinnedMeshRenderer smesh in skinnedMeshes)
            {
                if (smesh.gameObject.activeInHierarchy)
                {
                    //skinned meshes seem to be not nearly as conveniently simple
                    //luckily, I can apparently ask them to do all the work for me
                    smesh.BakeMesh(bakedMesh);
                    //create the trans. matrix for this mesh (also update the bounds)
                    Matrix4x4 transMatrix = genTransMatrix(part.transform, FlightGlobals.ActiveVessel,false);
                    updateMinMax(bakedMesh.bounds, transMatrix, ref minVec, ref maxVec);
                    transMatrix = scrnMatrix * transMatrix;
                    //now render it
                    if (!partColor.Equals(Color.black))
                        //renderMesh(bakedMesh, transMatrix, partColor);
                        renderMesh(bakedMesh.triangles, bakedMesh.vertices, transMatrix, partColor);
                }
                
            }
            bool addToTotals = false;
            if (customMode == null) addToTotals = true;
            else if (customMode.focusSubset.Count == 0) addToTotals = true;
            else if (customMode.focusSubset.Contains(part)) addToTotals = true;

            if(addToTotals)
            {
                //finally, update the vessel "bounding box"
                if (minVecG.x > minVec.x) minVecG.x = minVec.x;
                if (minVecG.y > minVec.y) minVecG.y = minVec.y;
                if (minVecG.z > minVec.z) minVecG.z = minVec.z;
                if (maxVecG.x < maxVec.x) maxVecG.x = maxVec.x;
                if (maxVecG.y < maxVec.y) maxVecG.y = maxVec.y;
                if (maxVecG.z < maxVec.z) maxVecG.z = maxVec.z;
            }
            if (!fill) 
            {
                //and draw a box around the part (later)
                rectQueue.Enqueue(new ViewerConstants.RectColor(new Rect((minVec.x), (minVec.y), (maxVec.x - minVec.x), (maxVec.y - minVec.y)), boxColor));
            }
            
            
        }
开发者ID:icedown,项目名称:VesselViewer,代码行数:101,代码来源:VesselViewer.cs

示例4: PartModelTransformList

        public static List<Transform> PartModelTransformList(Part p)
        {
            List<Transform> returnList = new List<Transform>();

            //Very hacky, but is necessary for root parts with broken transforms
            if (p.partTransform == null)
            {
                bool root = p == p.vessel.rootPart;
                Debug.Log("This one is busted: " + p.partInfo.title + " root? " + root);
                if (root)
                    p.partTransform = p.vessel.vesselTransform;
            }

            Transform[] propellersToIgnore = IgnoreModelTransformArray(p);

            returnList.AddRange(p.FindModelComponents<Transform>());

            if (p.Modules.Contains("ModuleJettison"))
            {
                ModuleJettison[] jettisons = p.GetComponents<ModuleJettison>();
                foreach (ModuleJettison j in jettisons)
                {
                    if (j.isJettisoned || j.jettisonTransform == null)
                        continue;

                    returnList.Add(j.jettisonTransform);
                }
            }

            foreach (Transform t in propellersToIgnore)
                returnList.Remove(t);

            //foreach (Transform t in returnList)
            //    Debug.Log(t.name);
            Debug.Log("Part: " + p.partInfo.title + " Transforms: " + returnList.Count);
            return returnList;
        }
开发者ID:kevin-ye,项目名称:Ferram-Aerospace-Research,代码行数:37,代码来源:FARGeoUtil.cs

示例5: PartModelTransformList

        public static List<Transform> PartModelTransformList(Part p)
        {
            List<Transform> returnList = new List<Transform>();

            Transform[] propellersToIgnore = IgnoreModelTransformArray(p);

            returnList.AddRange(p.FindModelComponents<Transform>());

            if (p.Modules.Contains("ModuleJettison"))
            {
                ModuleJettison[] jettisons = p.GetComponents<ModuleJettison>();
                foreach (ModuleJettison j in jettisons)
                {
                    if (j.isJettisoned || j.jettisonTransform == null)
                        continue;

                    returnList.Add(j.jettisonTransform);
                }
            }

            foreach (Transform t in propellersToIgnore)
                returnList.Remove(t);

            //foreach (Transform t in returnList)
            //    Debug.Log(t.name);
            Debug.Log("Part: " + p.partInfo.title + " Transforms: " + returnList.Count);
            return returnList;
        }
开发者ID:vosechu,项目名称:Ferram-Aerospace-Research,代码行数:28,代码来源:FARGeoUtil.cs

示例6: CalculatePartBounds

        private void CalculatePartBounds(Part p)
        {
            Vector3 minBoundVec, maxBoundVec;
            minBoundVec = maxBoundVec = Vector3.zero;
            foreach (Transform t in p.FindModelComponents<Transform>())
            {
                MeshFilter mf = t.GetComponent<MeshFilter>();
                if (mf == null)
                    continue;
                Mesh m = mf.mesh;

                if (m == null)
                    continue;

                var matrix = part.transform.worldToLocalMatrix * t.localToWorldMatrix;

                foreach (Vector3 vertex in m.vertices)
                {
                    Vector3 v = matrix.MultiplyPoint3x4(vertex);

                    maxBoundVec.x = Mathf.Max(maxBoundVec.x, v.x);
                    minBoundVec.x = Mathf.Min(minBoundVec.x, v.x);
                    maxBoundVec.y = Mathf.Max(maxBoundVec.y, v.y);
                    minBoundVec.y = Mathf.Min(minBoundVec.y, v.y);
                    maxBoundVec.z = Mathf.Max(maxBoundVec.z, v.z);
                    minBoundVec.z = Mathf.Min(minBoundVec.z, v.z);
                }
                minBoundVec.x *= 1.05f;
                maxBoundVec.x *= 1.05f;
                minBoundVec.z *= 1.05f;
                maxBoundVec.z *= 1.05f;
            }
            minBounds.Add(minBoundVec);
            maxBounds.Add(maxBoundVec);
        }
开发者ID:kevin-ye,项目名称:Ferram-Aerospace-Research,代码行数:35,代码来源:FARPayloadFairingModule.cs

示例7: ResetColor

        private void ResetColor( Part part )
        {
            if ( _useCustomShader )
            {
                if ( _managedParts.ContainsKey( part ) )
                {
                    List<SavedMaterial> savedMaterials = _managedParts[part];
                    if ( savedMaterials.Count == 0 )
                    {
                        _managedParts.Remove( part );
                        return;
                    }

                    Renderer[] renderers = part.FindModelComponents<Renderer>();
                    if ( renderers.Length > 0 )
                    {
                        for ( int i = 0; i < renderers.Length; ++i )
                        {
                            renderers[i].sharedMaterial.shader = savedMaterials[i].Shader;
                            renderers[i].sharedMaterial.SetColor( "_Color", savedMaterials[i].Color );
                        }
                    }

                    if ( _managedParts.ContainsKey( part ) )
                    {
                        _managedParts.Remove( part );
                    }
                }
            }
            else
            {
                part.SetHighlight( false, true );
                if ( _managedParts.ContainsKey( part ) )
                {
                    _managedParts.Remove( part );
                }
            }
        }
开发者ID:shepheb,项目名称:KSP,代码行数:38,代码来源:IntakeBuildAid.cs

示例8: ColorPart

        private void ColorPart( Part part, Color color )
        {
            if ( !_managedParts.ContainsKey( part ) )
            {
                if ( _useCustomShader )
                {
                    List<SavedMaterial> savedMaterials = new List<SavedMaterial>();
                    Renderer[] renderers = part.FindModelComponents<Renderer>();

                    if ( renderers.Length > 0 )
                    {
                        for ( int i = 0; i < renderers.Length; ++i )
                        {
                            savedMaterials.Insert( i, new SavedMaterial() { Shader = renderers[i].sharedMaterial.shader, Color = renderers[i].sharedMaterial.GetColor( "_Color" ) } );
                            renderers[i].sharedMaterial.shader = _material.shader;
                            renderers[i].sharedMaterial.SetColor( "_Color", color );
                        }

                        _managedParts.Add( part, savedMaterials );
                    }
                }
                else
                {
                    part.SetHighlight( true, false );
                    part.SetHighlightColor( color );
                    part.SetHighlightType( Part.HighlightType.AlwaysOn );
                }
            }
        }
开发者ID:shepheb,项目名称:KSP,代码行数:29,代码来源:IntakeBuildAid.cs

示例9: renderPart

        /// <summary>
        /// Renders a single part and adds all its children to the draw queue.
        /// Also adds its bounding box to the bounding box queue.
        /// </summary>
        /// <param name="part">Part to render</param>
        /// <param name="scrnMatrix">Screen transform</param>
        private void renderPart(Part part, Matrix4x4 scrnMatrix, bool fill)
        {
            //first off, add all the parts children to the queue
            foreach (Part child in part.children)
            {
                if (!child.Equals(part.parent))
                {
                    partQueue.Enqueue(child);
                }
            }

            //get the appropriate colors
            Color partColor;
            Color boxColor;

            if (!settings.partSelectMode)
            {
                if (!fill) partColor = getPartColor(part, settings.colorModeMesh);
                else partColor = getPartColor(part, settings.colorModeFill);
                boxColor = getPartColor(part, settings.colorModeBox);
            }
            else {
                partColor = getPartColorSelectMode(part, settings);
                boxColor = getPartColorSelectMode(part, settings);
            }
            if (settings.colorModeBoxDull) {
                boxColor.r = boxColor.r / 2;
                boxColor.g = boxColor.g / 2;
                boxColor.b = boxColor.b / 2;
            }
            if (fill)
            {
                if (settings.colorModeFillDull)
                {
                    partColor.r = partColor.r / 2;
                    partColor.g = partColor.g / 2;
                    partColor.b = partColor.b / 2;
                }
            }
            else
            {
                if (settings.colorModeMeshDull)
                {
                    partColor.r = partColor.r / 2;
                    partColor.g = partColor.g / 2;
                    partColor.b = partColor.b / 2;
                }
            }

            //now we need to get all meshes in the part
            List<MeshFilter> meshFList = new List<MeshFilter>();
            foreach (MeshFilter mf in part.transform.GetComponentsInChildren<MeshFilter>())
            {
                meshFList.Add(mf);
            }

            //MeshFilter[] meshFilters = (MeshFilter[])part.FindModelComponents<MeshFilter>();
            MeshFilter[] meshFilters = meshFList.ToArray();
            //used to determine the part bounding box
            Vector3 minVec = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
            Vector3 maxVec = new Vector3(float.MinValue, float.MinValue, float.MinValue);
            foreach (MeshFilter meshF in meshFilters)
            {
                if (!(meshF.renderer == null))
                {
                    //only render those meshes that are active
                    //examples of inactive meshes seem to include
                    //parachute canopies, engine fairings...

                    if (meshF.renderer.gameObject.activeInHierarchy)
                    {
                        Mesh mesh = meshF.mesh;
                        //create the trans. matrix for this mesh (also update the bounds)
                        Matrix4x4 transMatrix = genTransMatrix(meshF.transform, settings.ship,false);
                        updateMinMax(mesh.bounds, transMatrix, ref minVec, ref maxVec);
                        transMatrix = scrnMatrix * transMatrix;
                        //now render it
                        if(!partColor.Equals(Color.black))
                            //renderMesh(mesh, transMatrix, partColor);
                            renderMesh(mesh.triangles, mesh.vertices, transMatrix, partColor);
                    }
                }
            }

            SkinnedMeshRenderer[] skinnedMeshes = (SkinnedMeshRenderer[])part.FindModelComponents<SkinnedMeshRenderer>();
            foreach (SkinnedMeshRenderer smesh in skinnedMeshes)
            {
                if (smesh.gameObject.activeInHierarchy)
                {
                    //skinned meshes seem to be not nearly as conveniently simple
                    //luckily, I can apparently ask them to do all the work for me
                    smesh.BakeMesh(bakedMesh);
                    //create the trans. matrix for this mesh (also update the bounds)
                    Matrix4x4 transMatrix = genTransMatrix(part.transform, settings.ship,false);
//.........这里部分代码省略.........
开发者ID:pcwilcox,项目名称:GoAtThrottleUp,代码行数:101,代码来源:VesselView.cs

示例10: RenderPart

		/// <summary>
		/// Render a part.
		/// </summary>
		/// <param name="vesselPart"></param>
		private void RenderPart(Part vesselPart)
		{
			var meshFilters = vesselPart.FindModelComponents<MeshFilter>();

			foreach (MeshFilter mesh in meshFilters) {
				if(mesh.renderer != null && mesh.renderer.gameObject != null && mesh.renderer.material != null)
				if(mesh.renderer.gameObject.activeInHierarchy) {
					Matrix4x4 localXform = vessel.vesselTransform.localToWorldMatrix.inverse * mesh.transform.localToWorldMatrix;
					localXform = postfixTransform * (localXform * screenTransform);
					if (useWireframe) {
						DrawWireframe(mesh.mesh.triangles, mesh.mesh.vertices, localXform);
					} else {
						DrawTriangles(mesh.mesh.triangles, mesh.mesh.vertices, localXform);
					}
				}
			}
		}
开发者ID:dreadicon,项目名称:RasterPropMonitor,代码行数:21,代码来源:JSIVesselView.cs


注:本文中的Part.FindModelComponents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。