Пример #1
0
    //methods
    #region
    public Connection(AlignPlane _plane, string _type, string _part, int _id)
    {
        pln     = _plane;
        conType = _type;
        part    = _part;
        conId   = _id;

        rulesTable  = new List <Rule>();
        activeRules = new List <int>();
    }
Пример #2
0
 //static methods
 #region
 public static bool Orient(AlignPlane from, AlignPlane to, GameObject geo)
 {
     if (TryOrient(from, to, geo))
     {
         return(true);
     }
     else
     {
         return(TryOrient(from, to, geo));
     }
 }
Пример #3
0
    public void Right()
    {
        if (choseChild && !choseChildConnection)
        {
            if (childIndex == -1)
            {
                return;
            }

            childProxies[childIndex].SetActive(false);
            ++childIndex;
            if (childIndex >= childProxies.Count)
            {
                childIndex = 0;
            }

            childProxies[childIndex].SetActive(true);
            childProxies[childIndex].GetComponent <MeshRenderer>().material = MaterialHolder.SelectedMat;
        }
        else if (choseChildConnection)
        {
            Part childPart = childProxies[childIndex].GetComponent <Part>();
            ++conIndex;
            if (conIndex >= childPart.ActiveConnections.Count)
            {
                conIndex = 0;
            }

            if (ConnectionScanning.RuleActive(chosenConnection, childPart.Connections[childPart.ActiveConnections[conIndex]]))
            {
                bool orientCheck = false;
                for (int i = 0; i < 10; ++i)
                {
                    orientCheck = AlignPlane.Orient(childPart.Connections[childPart.ActiveConnections[conIndex]].Pln, chosenConnection.Pln, childProxies[childIndex]);
                    if (orientCheck)
                    {
                        break;
                    }
                }
                if (!orientCheck)
                {
                    Right();
                }
            }
            else
            {
                Right();
            }

            childProxies[childIndex].GetComponent <MeshRenderer>().material = MaterialHolder.SelectedMat;
        }
    }
Пример #4
0
    public void Left()
    {
        if (choseChild && !choseChildConnection)
        {
            if (childIndex == -1)
            {
                return;
            }

            childProxies[childIndex].SetActive(false);
            --childIndex;
            if (childIndex < 0)
            {
                childIndex = childProxies.Count - 1;
            }

            childProxies[childIndex].SetActive(true);
        }
        else if (choseChildConnection)
        {
            Part childPart = childProxies[childIndex].GetComponent <Part>();
            --conIndex;
            if (conIndex < 0)
            {
                conIndex = childPart.ActiveConnections.Count - 1;
            }

            if (ConnectionScanning.RuleActive(chosenConnection, childPart.Connections[childPart.ActiveConnections[conIndex]]))
            {
                bool orientCheck = false;
                for (int i = 0; i < 10; ++i)
                {
                    orientCheck = AlignPlane.Orient(childPart.Connections[childPart.ActiveConnections[conIndex]].Pln, chosenConnection.Pln, childProxies[childIndex]);
                    if (orientCheck)
                    {
                        break;
                    }
                }
                if (!orientCheck)
                {
                    Left();
                }
            }
            else
            {
                Left();
            }
        }
    }
Пример #5
0
    private void RealizeConnection()
    {
        if (lastDistAngle < connectionThreshold && ConnectionVoxelContainer.RevealConnections(bestOnPart).Contains(closestConnection))
        {
            Vector3    pos = gameObject.transform.position;
            Quaternion rot = gameObject.transform.rotation;

            AlignPlane.Orient(bestOnPart.Pln, closestConnection.Pln, gameObject);

            if (!CollisionDetection())
            {
                Part p = gameObject.GetComponent <Part>();
                p.FreezePart();
                p.Parent    = closestConnection.ParentPart.ID;
                p.ParentCon = closestConnection.ParentPart.Connections.IndexOf(closestConnection);

                ConnectionVoxelContainer.RemoveConnection(closestConnection);
                ConnectionVoxelContainer.RemoveConnection(bestOnPart);

                bestOnPart.ParentPart.SetInactive(bestOnPart);
                closestConnection.ParentPart.SetInactive(closestConnection);
                closestConnection.ParentPart.ChildCons.Add(bestOnPart.ParentPart.Connections.IndexOf(bestOnPart));

                closestConnection.ParentPart.Children.Add((int)p.ID);

                GameObject _g = PartsHolder.SpawnPart(p.TemplateID);
                _g.SetActive(true);
                if (GlobalReferences.PlacementType == PlacementTypeTool.PlaceChoreo.Choreo)
                {
                    GlobalReferences.AffectPart(_g);
                    GlobalReferences.FreeParts.Remove(_g);
                }

                ConnectionScanningHandler handler = gameObject.GetComponent <ConnectionScanningHandler>();
                if (handler != null)
                {
                    handler.TerminateConnection();
                }
            }
            else
            {
                gameObject.transform.position = pos;
                gameObject.transform.rotation = rot;
            }
        }
    }
Пример #6
0
    List <GameObject> SpawnChildProxies(Connection c)
    {
        List <GameObject> childPartsProxies = new List <GameObject>();

        for (int i = 0; i < GlobalReferences.TemplateParts.Count; ++i)
        {
            GameObject go = PartsHolder.Holder.SpawnGhostPart(i);
            go.AddComponent <CheckGrowCollision>();
            Destroy(go.GetComponent <ConnectionScanning>());

            List <Connection> templateCons = new List <Connection>();
            Part templatePart = go.GetComponent <Part>();

            foreach (int id in templatePart.ActiveConnections)
            {
                templateCons.Add(templatePart.Connections[id]);
            }

            foreach (Connection templateC in templateCons)
            {
                if (ConnectionScanning.RuleActive(templateC, c))
                {
                    AlignPlane.Orient(templateC.Pln, c.Pln, go);
                    go.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
                    childPartsProxies.Add(go);
                    go.SetActive(false);
                    break;
                }
            }

            if (!childPartsProxies.Contains(go))
            {
                Destroy(go);
            }
        }

        if (childPartsProxies.Count > 0)
        {
            childPartsProxies[0].SetActive(true);
            childIndex = 0;
        }

        return(childPartsProxies);
    }
Пример #7
0
    //static methods
    #region
    public static void Orient(AlignPlane from, AlignPlane to, GameObject geo)
    {
        Vector3 posMove = to.Origin - from.Origin;

        geo.transform.position += posMove;

        while (Vector3.Angle(from.XVector, to.XVector) > 0.1)
        {
            geo.transform.RotateAround(to.Origin, Vector3.Cross(from.XVector, to.XVector), Vector3.Angle(from.XVector, to.XVector));
        }

        while (Vector3.Angle(from.YVector, to.YVector) > 0.1)
        {
            geo.transform.RotateAround(to.Origin, to.XVector, Vector3.Angle(from.YVector, to.YVector));
        }


        geo.transform.RotateAround(to.Origin, to.XVector, 180);
    }
Пример #8
0
    static bool TryOrient(AlignPlane from, AlignPlane to, GameObject geo)
    {
        float epsilon   = 0.001f;
        bool  returnVal = true;

        geo.transform.position += to.Origin - from.Origin;

        float angleX = (float)(Math.Acos(Vector3.Dot(from.XVector, to.XVector)) / Math.PI * 180);

        returnVal = TryRotate(to.Origin, Vector3.Cross(from.XVector, to.XVector), angleX, geo);

        if (Vector3.Distance(to.XVector.normalized, from.XVector.normalized) > epsilon)
        {
            returnVal = TryRotate(to.Origin, Vector3.Cross(from.XVector, to.XVector), -2 * angleX, geo);
        }

        float angleY = (float)(Math.Acos(Vector3.Dot(from.YVector, to.YVector)) / Math.PI * 180);

        returnVal = TryRotate(to.Origin, to.XVector, angleY, geo);

        if (Vector3.Distance(to.YVector.normalized, from.YVector.normalized) > epsilon)
        {
            returnVal = TryRotate(to.Origin, to.XVector, -2 * angleY, geo);
        }

        if (Vector3.Distance(to.XVector.normalized, from.XVector.normalized) > epsilon ||
            Vector3.Distance(to.YVector.normalized, from.YVector.normalized) > epsilon)
        {
            returnVal = false;
        }

        geo.transform.RotateAround(to.Origin, to.XVector, 180);

        if (Vector3.Distance(to.Origin, from.Origin) > epsilon)
        {
            //Debug.Log("Too Far Apart: " + Vector3.Distance(to.Origin, from.Origin));
            returnVal = false;
        }

        return(returnVal);
    }
Пример #9
0
    bool CheckWithoutJobs(Connection c, List <Connection> foundC)
    {
        if (foundC.Count > 0)
        {
            foreach (Connection _c in foundC)
            {
                if (_c.Pln.Parent != null && RuleActive(_c, c))
                {
                    distAngle = Vector3.Distance(c.Pln.Origin, _c.Pln.Origin);
                    if (distAngle > lastDistAngle || distAngle > connectionThreshold)
                    {
                        continue;
                    }

                    angle      = AlignPlane.BuildAngle(c.Pln.ZVector, _c.Pln.ZVector, true);
                    distAngle += AngleTightening(angle);
                    if (distAngle > lastDistAngle || distAngle > connectionThreshold)
                    {
                        continue;
                    }

                    rot        = AlignPlane.BuildAngle(c.Pln.XVector, _c.Pln.XVector, false) * 10 * connectionThreshold;
                    distAngle += rot / 1000 * connectionThreshold;


                    if (distAngle < lastDistAngle && _c.CheckForRule(c) != -1)
                    {
                        closestConnection = _c;
                        bestOnPart        = c;
                        lastDistAngle     = distAngle;
                        if (lastDistAngle < connectionThreshold / 5)
                        {
                            return(true);
                        }
                    }
                }
            }
        }
        return(false);
    }
Пример #10
0
    //methods
    #region
    private void CheckForCloseConnections()
    {
        distAngle     = 100;
        lastDistAngle = 1000;
        rot           = 1000;
        foreach (Connection c in connections)
        {
            foundC = ConnectionVoxelContainer.RevealConnections(c);

            if (foundC.Count > 0)
            {
                foreach (Connection _c in foundC)
                {
                    if (_c.Pln.Parent != null)
                    {
                        dist      = Vector3.Distance(c.Pln.Origin, _c.Pln.Origin);
                        angle     = AlignPlane.BuildAngle(c.Pln.LocalZVector, _c.Pln.LocalZVector, true);
                        rot       = AlignPlane.BuildAngle(c.Pln.XVector, _c.Pln.XVector, false) * 10 * connectionThreshold;
                        distAngle = dist + AngleTightening(angle) + rot / 1000 * connectionThreshold;

                        string grammer = _c.ConType + ">" + c.ConType;
                        if (distAngle < lastDistAngle && _c.CheckForRule(c) != -1 && RuleActive(grammer))
                        {
                            closestConnection = _c;
                            bestOnPart        = c;
                            lastDistAngle     = distAngle;
                            if (lastDistAngle < connectionThreshold / 5)
                            {
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
Пример #11
0
    public static AlignPlane FlipCopy(AlignPlane pln)
    {
        AlignPlane pl = new AlignPlane(pln.origin, pln.xVector, pln.yVector * -1, pln.parent);

        return(pl);
    }
Пример #12
0
    public object Clone()
    {
        AlignPlane cloneAlign = new AlignPlane(origin, xVector, yVector, parent);

        return(cloneAlign);
    }
Пример #13
0
    private void RealizeConnection()
    {
        if (lastDistAngle < connectionThreshold && ConnectionVoxelContainer.RevealConnections(bestOnPart).Contains(closestConnection))
        {
            Vector3    pos = gameObject.transform.position;
            Quaternion rot = gameObject.transform.rotation;

            if (!AlignPlane.Orient(bestOnPart.Pln, closestConnection.Pln, gameObject))
            {
                gameObject.transform.position = pos;
                gameObject.transform.rotation = rot;
                return;
            }

            //PlacementBehaviour.ReleasePart(true);


            Destroy(gameObject.GetComponent <ConstantForce>());
            Destroy(gameObject.GetComponent <PartBehaviour>());
            Destroy(gameObject.GetComponent <ConnectionScanning>());

            gameObject.layer = 13;


            var check = gameObject.AddComponent <CheckCollision>();
            check.respawnPosition   = pos;
            check.respawnRotation   = rot;
            check.closestConnection = closestConnection;
            check.bestOnPart        = bestOnPart;

            if (transform.parent != null)
            {
                transform.parent = null;
            }

            GetComponent <Rigidbody>().constraints            = RigidbodyConstraints.FreezeAll;
            GetComponent <Rigidbody>().collisionDetectionMode = CollisionDetectionMode.Continuous;
            Destroy(this);

            /*
             * if (BoltNetwork.IsRunning)
             * {
             *  var checkFreeze = CheckBlockFreeze.Create(gameObject.GetComponent<NetworkBlockBehaviour>().entity);
             *  checkFreeze.BlockPosition = gameObject.transform.position;
             *  checkFreeze.BlockRotation = gameObject.transform.rotation;
             *
             *  checkFreeze.OldBlockPosition = pos;
             *  checkFreeze.OldBlockRotation = rot;
             *
             *  if (closestConnection.ParentPart.ID != null)
             *  {
             *      checkFreeze.ParentID = (int)closestConnection.ParentPart.ID;
             *  }
             *  else
             *  {
             *      checkFreeze.ParentID = -1;
             *  }
             *
             *  checkFreeze.ParentCon = closestConnection.ParentPart.Connections.IndexOf(closestConnection);
             *  checkFreeze.ConnectionID = gameObject.GetComponent<Part>().Connections.IndexOf(bestOnPart);
             *
             *  checkFreeze.Send();
             * }
             */
        }
    }