Exemple #1
0
 public override void Start()
 {
     base.Start();
     constructor     = GetComponent <MeshConstructor> ();
     verticesManager = GetComponent <VerticesManager> ();
     verticesManager.AllVerticesSetState(false);
 }
Exemple #2
0
 public virtual void Start()
 {
     meshConstructor = GetComponent <MeshConstructor> ();
     AddVerticeDraggables();
     AddFaceVertices();
     character             = World.Instance.character;
     Events.DraggReleased += DraggReleased;
 }
 public void Init(MeshConstructor mc, int _id, Vector3 _vectorToModify)
 {
     this.element         = mc.GetComponent <ElementCube> ();
     this.meshConstructor = mc;
     this.id = _id;
     transform.localPosition = _vectorToModify;
     gameObject.layer        = 8;
 }
Exemple #4
0
 void AddSpan(MeshConstructor mc, MeshVertex[,] mx, int latitudeSpanIndex, int longitudeSpanIndex, int submesh = 0)
 {
     MeshVertex topLeft = mx[latitudeSpanIndex + 1, longitudeSpanIndex];
     MeshVertex topRight = mx[latitudeSpanIndex + 1, longitudeSpanIndex + 1];
     MeshVertex bottomLeft = mx[latitudeSpanIndex, longitudeSpanIndex];
     MeshVertex bottomRight = mx[latitudeSpanIndex, longitudeSpanIndex + 1];
     mc.AddTriangle(topLeft, topRight, bottomLeft, submesh);
     mc.AddTriangle(bottomRight, bottomLeft, topRight, submesh);
 }
Exemple #5
0
        protected override bool Load(string virtualFileName, Mesh mesh)
        {
            currentFileName     = virtualFileName;
            currentMesh         = mesh;
            globalScale         = 1;
            yAxisUp             = true;
            generatedMaterials  = new Dictionary <string, MySceneMaterial>();
            generatedGeometries = new Dictionary <string, GeometryItem>();
            generatedSubMeshes  = new List <MySceneSubMesh>();

            //load file
            XmlNode colladaNode;

            {
                try
                {
                    using (Stream stream = VirtualFile.Open(virtualFileName))
                    {
                        string fileText = new StreamReader(stream).ReadToEnd();
                        colladaNode = XmlUtils.LoadFromText(fileText);
                    }
                }
                catch (Exception ex)
                {
                    Error(ex.Message);
                    return(false);
                }
            }

            //parse
            if (!ParseColladaNode(colladaNode))
            {
                ClearTemporaryFields();
                return(false);
            }

            //generate mesh
            const bool      tangents            = true;
            const bool      edgeList            = true;
            const bool      allowMergeSubMeshes = true;
            MeshConstructor meshConstructor     = new MeshConstructor(tangents, edgeList, allowMergeSubMeshes);

            MyMeshSceneObject meshSceneObject = new MyMeshSceneObject(generatedSubMeshes.ToArray());

            if (!meshConstructor.DoExport(meshSceneObject, mesh))
            {
                ClearTemporaryFields();
                return(false);
            }

            ClearTemporaryFields();

            return(true);
        }
Exemple #6
0
    Mesh GenerateMesh()
    {
        var mc = new MeshConstructor();
        mc.mesh.name = name;
        mc.SetSubmeshCount(2);

        latitudes = latitudeSpans + 1;
        longitudes = longitudeSpans + 1;
        pictureLatitudeSpans = 2 * halfLatitudePictureSpans;
        pictureLongitudeSpans = 2 * halfLongitudePictureSpans;
        pictureLatitudes = pictureLatitudeSpans + 1;
        pictureLongitudes = pictureLongitudeSpans + 1;

        pictureSpans = new bool[latitudeSpans, longitudeSpans];
        baseMatrix = new MeshVertex[latitudes, longitudes];
        pictureMatrix = new MeshVertex[latitudes, longitudes];

        for (int latitudePictureSpanIndex = 0; latitudePictureSpanIndex < pictureLatitudeSpans; latitudePictureSpanIndex++) {
            for (int longitudePictureSpanIndex = 0; longitudePictureSpanIndex < pictureLongitudeSpans; longitudePictureSpanIndex++) {
                int latitudeSpanIndex = latitudes/2-halfLatitudePictureSpans+latitudePictureSpanIndex;
                int longitudeSpanIndex = Extensions.Modulo(-halfLongitudePictureSpans+longitudePictureSpanIndex, longitudeSpans);
                pictureSpans[latitudeSpanIndex, longitudeSpanIndex] = true;
            }
        }

        for (int latitudeIndex = 0; latitudeIndex <= latitudeSpans; latitudeIndex++) {
            for (int longitudeIndex = 0; longitudeIndex <= longitudeSpans; longitudeIndex++) {
                baseMatrix[latitudeIndex, longitudeIndex] = new MeshVertex(
                    position: getSpherePoint(latitudeIndex, longitudeIndex),
                    uv: new Vector2(1f * longitudeIndex / longitudeSpans, 1f * latitudeIndex / latitudeSpans),
                    normal: getSpherePoint(latitudeIndex, longitudeIndex).normalized
                );
            }
        }

        for (int pictureLatitudeIndex = 0; pictureLatitudeIndex <= 2 * halfLatitudePictureSpans; pictureLatitudeIndex++) {
            for (int pictureLongitudeIndex = 0; pictureLongitudeIndex <= 2 * halfLongitudePictureSpans; pictureLongitudeIndex++) {
                int latitudeIndex = latitudes/2 -halfLatitudePictureSpans + pictureLatitudeIndex;
                int longitudeIndex = Extensions.Modulo(-halfLongitudePictureSpans + pictureLongitudeIndex, longitudeSpans);

                //Debug.LogFormat("Adding picture vertex {0}, {1}", latitudeIndex, longitudeIndex);
                pictureMatrix[latitudeIndex, longitudeIndex] = new MeshVertex(
                    position: getSpherePoint(latitudeIndex, longitudeIndex),
                    uv: new Vector2(1f * pictureLongitudeIndex / pictureLongitudeSpans, 1f * pictureLatitudeIndex / pictureLatitudeSpans),
                    normal: getSpherePoint(latitudeIndex, longitudeIndex).normalized
                );

                if (longitudeIndex == 0) {
                    longitudeIndex = longitudes - 1;
                    //Debug.LogFormat("Adding picture vertex {0}, {1}", latitudeIndex, longitudeIndex);
                    pictureMatrix[latitudeIndex, longitudeIndex] = new MeshVertex(
                        position: getSpherePoint(latitudeIndex, longitudeIndex),
                        uv: new Vector2(1f * pictureLongitudeIndex / pictureLongitudeSpans, 1f * pictureLatitudeIndex / pictureLatitudeSpans),
                        normal: getSpherePoint(latitudeIndex, longitudeIndex).normalized
                    );
                }
            }
        }

        for (int latitudeSpanIndex = 0; latitudeSpanIndex < latitudeSpans; latitudeSpanIndex++) {
            for (int longitudeSpanIndex = 0; longitudeSpanIndex < longitudeSpans; longitudeSpanIndex++) {
                if (isPictureSpan(latitudeSpanIndex, longitudeSpanIndex)) {
                    AddSpan(mc, pictureMatrix, latitudeSpanIndex, longitudeSpanIndex, 1);
                }
                AddSpan(mc, baseMatrix, latitudeSpanIndex, longitudeSpanIndex);
            }
        }

        return mc.Done();
    }
Exemple #7
0
 public int GetIndex(MeshConstructor mc)
 {
     return index;
 }