Пример #1
0
        // Use this for initialization
        void Start()
        {
            if (parent)
            {
                TelescopeElement parentElement = parent.getChildElement(parentElementNum);
                transform.parent = parentElement.transform;

                if (!keepLocalPositionOnStart)
                {
                    transform.localPosition = parentElement.getAttachmentLocation(offsetAlongParent);
                    transform.localRotation = parentElement.getAttachmentRotation(offsetAlongParent);
                }
            }

            /*
             * GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
             * sphere.transform.parent = transform;
             * sphere.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
             * sphere.transform.localPosition = Vector3.zero; */

            line = gameObject.AddComponent <LineRenderer>();
            line.useWorldSpace = false;
            line.material      = DesignerController.instance.defaultLineMaterial;
            line.SetWidth(0.1f, 0.1f);

            List <Vector3> points       = new List <Vector3>();
            int            numNeighbors = 0;

            if (parentSegment)
            {
                points.Add(parentSegment.LastShell.transform.position - transform.position);
                points.Add(Vector3.zero);
                numNeighbors++;
            }

            foreach (TelescopeSegment seg in childSegments)
            {
                points.Add(seg.FirstShell.transform.position - transform.position);
                points.Add(Vector3.zero);
            }

            numNeighbors += childSegments.Count;

            line.SetVertexCount(points.Count);
            line.SetPositions(points.ToArray());

            // If this bulb is a dead end, make it a sphere.
            junctureType = (numNeighbors <= 1) ? JunctureType.Sphere : JunctureType.ConvexHull;
            previousType = JunctureType.None;

            if (!mFilter)
            {
                mFilter = gameObject.AddComponent <MeshFilter>();
            }
            if (!meshRenderer)
            {
                meshRenderer          = gameObject.AddComponent <MeshRenderer>();
                meshRenderer.material = DesignerController.instance.defaultTelescopeMaterial;
            }
        }
Пример #2
0
        void Update()
        {
            if (Input.GetKeyDown("h"))
            {
                MakeConvexHull();
            }

            if (Input.GetKeyDown("]"))
            {
                bool done = CollisionIteration(0.5f);
                MakeMesh();
                Debug.Log("No more collisions = " + done);
            }

            if (Input.GetKeyDown("end"))
            {
                ExportJunctureToOBJ();
            }

            /*
             * if (Input.GetKey("left shift") && Input.GetKeyDown("enter"))
             * {
             *  Vector3 minPoint = meshRenderer.bounds.min;
             *
             *  if (parentSegment)
             *  {
             *      minPoint = TelescopeUtils.VectorMin(minPoint, parentSegment.LastShell.WorldSpaceBounds.min);
             *  }
             *
             *  foreach (TelescopeSegment childSegment in childSegments)
             *  {
             *      minPoint = TelescopeUtils.VectorMin(minPoint, childSegment.FirstShell.WorldSpaceBounds.min);
             *  }
             *
             *  WriteSTLOfJuncture(minPoint, name);
             * }*/

            if (previousType != junctureType)
            {
                // Clear mesh data for the old juncture type
                switch (previousType)
                {
                case JunctureType.None:
                    break;

                case JunctureType.ConvexHull:
                case JunctureType.Sphere:
                case JunctureType.CustomMesh:
                    mFilter.mesh.Clear();
                    break;

                default:
                    break;
                }

                previousType = junctureType;

                MakeMesh();
            }
        }