Пример #1
0
        public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool renderToOutputParameter)
        {
            if (inputs != null && inputs.Count > 0)
            {
                float bayw = 2f;

                List <Vector3> verts = new List <Vector3>();
                List <Vector2> uvs   = new List <Vector2>();

                List <int> tris = new List <int>();

                shiftIndices.Add(0);


                Paths paths = new Paths();
                Path  path  = null;

                int prevPathCount = 0;


                for (int c = 0; c < inputs.Count; c++)
                {
                    if (inputs[c].DependsOn == null)
                    {
                        continue;
                    }

                    path = inputs[c].DependsOn.getPaths()[0];

                    paths.Add(path);

                    verts.AddRange(AXGeometryTools.Utilities.path2Vec3s(path, AXGeometryTools.Axis.Y, (c * bayw)));


                    if (c > 0)
                    {
                        shiftIndices.Add(shiftIndices[shiftIndices.Count - 1] + prevPathCount);
                    }

                    prevPathCount = path.Count;
                }

                for (int u = 0; u < verts.Count; u++)
                {
                    uvs.Add(Vector2.zero);
                }



                for (int a = 0; a < inputs.Count - 1; a++)
                {
                    int b = a + 1;

                    //				foreach (Vector3 vert in verts)
                    //					Debug.Log(vert);
                    if (inputs[a].DependsOn == null)
                    {
                        a++;
                        continue;
                    }
                    if (inputs[b].DependsOn == null)
                    {
                        return(null);
                    }
                    Path pathA = inputs[a].DependsOn.getPaths()[0];
                    Path pathB = inputs[b].DependsOn.getPaths()[0];

                    int av = 0;
                    int bv = 0;


                    // Step through...
                    // each loop is a triangle

                    int gov = 0;
                    while (av < pathA.Count - 1)
                    {
                        if (gov > 25)
                        {
                            break;
                        }

                        // add the first two points of the triangle
                        tris.Add(getIndex(a, av));
                        tris.Add(getIndex(b, bv));

                        IntPoint aa1 = pathA[av];
                        IntPoint aa2 = pathA[av + 1];

                        IntPoint bb1 = pathB[bv];
                        IntPoint bb2 = pathB[bv + 1];



                        //Debug.Log(aa1.X + ", " + aa1.Y + "  --- " + bb1.X + ", " + bb1.Y);

                        // if dist(aa1, bb1) < dist(bb1, aa2), uadd the former to the triabgle.
                        if (Pather.DistanceSquared(aa1, bb2) < Pather.DistanceSquared(bb1, aa2))
                        {
                            //Debug.Log("use bb2");

                            bv++;
                            tris.Add(getIndex(b, bv));
                        }
                        else
                        {
                            //Debug.Log("use aa2");
                            av++;
                            tris.Add(getIndex(a, av));
                        }

                        gov++;
                    }
                }

//				foreach (int t in tris)
//					Debug.Log(t);


                // create mesh and GameObject
                Mesh mesh = new Mesh();

                mesh.vertices  = verts.ToArray();
                mesh.triangles = tris.ToArray();
                mesh.uv        = uvs.ToArray();


                mesh.RecalculateNormals();
                mesh.RecalculateTangents();


                AXMesh axmesh = new AXMesh(mesh);
                ax_meshes = new List <AXMesh>();
                ax_meshes.Add(axmesh);

                // FINISH AX_MESHES

                parametricObject.finishMultiAXMeshAndOutput(ax_meshes, true);                //renderToOutputParameter);

                // FINISH BOUNDING

                setBoundaryFromAXMeshes(ax_meshes);


                if (makeGameObjects)
                {
                    return(parametricObject.makeGameObjectsFromAXMeshes(ax_meshes));
                }
            }



            return(null);
        }