// Start is called before the first frame update
    void Start()
    {
        ControlFactors.SetDefaults();
        PopulateMap(true);
        //Background.transform.position = new Vector3(-2 * Expansion_Distance, 2 * Expansion_Distance, 0);
        //Background.GetComponent<SpriteRenderer>().size = new Vector3(2 * Expansion_Distance, 2 * Expansion_Distance, 0);
        //Debug.Log("Map Generated");


        Land = transform.Find("MeshHandler").GetComponent <MeshHandler>();
        //mapGrid = new MapGrid(mapWidth, mapHeight, gridNodeWidth, gridNodeHeight);
        population = new Population(this);
        //PopulateGrid();
        aPath.transform.position = new Vector3(aPath.transform.position.x - (Expansion_Distance), aPath.transform.position.y - (Expansion_Distance), 0);
        GridGraph g = aPath.data.gridGraph;

        g.SetDimensions((int)(Expansion_Distance * 2), (int)(Expansion_Distance * 2), 1f);
        g.nodeSize             = .5f;
        g.collision.heightMask = LayerMask.GetMask("TileGrid");
        //aPath.batchGraphUpdates = true;


        StartCoroutine(StartGrid(.5f));
        //g.drawGizmos = true;
    }
Beispiel #2
0
 private void Awake()
 {
     if (instance != null && instance != this)
     {
         Destroy(gameObject);
         return;
     }
     instance = this;
 }
    void BuildShipsSpaceMesh(MeshFilter shipFilter)
    {
        List <Vector3> outerHullVertices     = new List <Vector3>();
        List <Vector3> outerVertexDirections = new List <Vector3> ();

        RetrieveOuterHullVertices(outerHullVertices, outerVertexDirections);
        MeshHandler mH = new MeshHandler();

        mH.AssignOuterHullMeshData(outerHullVertices, outerVertexDirections, hullHeight, shellDepth, shellInset);
        mH.ReturnCompleteMesh(shipFilter);
    }
    bool ValidateMeshShape(Shape shape, Shape referenceShape, MessageHandler handler)
    {
        MeshHandler meshHandler = (MeshHandler)handler;

        MeshHandler.MeshEntry meshEntry          = meshHandler.ShapeCache.GetShapeData <MeshHandler.MeshEntry>(shape.ID);
        MeshShape             meshShapeReference = (MeshShape)referenceShape;
        bool ok = true;

        ok = ValidateVectors("Vertex", meshEntry.Mesh.Vertices, meshShapeReference.Vertices) && ok;
        if (meshEntry.Mesh.HasNormals)
        {
            Vector3[] normals = meshEntry.Mesh.Normals;
            if (meshShapeReference.Normals.Length == 1)
            {
                // Single uniform normal will have been expanded. Extract just the first normal.
                normals = new Vector3[] { meshEntry.Mesh.Normals[0] };
            }
            ok = ValidateVectors("Normal", normals, meshShapeReference.Normals) && ok;
        }
        else
        {
            if (meshShapeReference.Normals != null && meshShapeReference.Normals.Length > 0)
            {
                Debug.LogError("Missing normals.");
                ok = false;
            }
        }
        if (meshEntry.Mesh.IndexCount > 0)
        {
            ok = ValidateIndices("Index", meshEntry.Mesh.Indices, meshShapeReference.Indices) && ok;
        }
        else
        {
            if (meshShapeReference.Indices != null && meshShapeReference.Indices.Length > 0)
            {
                Debug.LogError("Missing indices.");
                ok = false;
            }
        }

        return(ok);
    }
    public void Refresh()
    {
        if (meshFilter == null)
        {
            Debug.LogError("Error, the meshs are null");
            return;
        }

        GameObject river = GameObject.FindGameObjectWithTag("River");

        if (river != null)
        {
            DestroyImmediate(river);
        }

        meshRenderer = meshFilter.GetComponent <MeshRenderer>();

        handler = new MeshHandler(meshFilter, this);
        handler.GenerateMap();
        meshRenderer.sharedMaterials[1].mainTexture = topIsland.colorTexture;
    }
    MeshHandler[] _captureShape(int index)
    {
        List <MeshHandler> items = new List <MeshHandler>();

        for (int i = 0; i < _meshs.Length; i++)
        {
            Mesh        mesh    = _meshs[i].sharedMesh;
            MeshHandler handler = new MeshHandler();
            handler.skinnedMeshRenderer = _meshs[i];
            List <ShapeTarget> targets = new List <ShapeTarget>();

            for (int j = 0; j < mesh.blendShapeCount; j++)
            {
                if (_meshs[i].GetBlendShapeWeight(j) > 0)
                {
                    var target = new ShapeTarget();
                    target.index  = j;
                    target.weight = _meshs[i].GetBlendShapeWeight(j);
                    targets.Add(target);
                }
            }

            if (targets.Count == 0)
            {
                handler = null;
                targets = null;
            }
            else
            {
                handler.targets = targets.ToArray();
                items.Add(handler);
            }
        }

        return(items.ToArray());
    }
        public static ProxyStateMachine New(string location, string serviceName)
        {
            ProxyStateMachine stateMachine;
            var nodeConfig      = RoleEnvironment.GetConfigurationSettingValue(serviceName + ".Nodes");
            var nodeDescriptors = nodeConfig.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            var nodes           = new Dictionary <string, Uri>();

            foreach (var d in nodeDescriptors)
            {
                var n = d.Split('=');
                try
                {
                    nodes.Add(n[0], new UriBuilder()
                    {
                        Host = n[1]
                    }.Uri);
                }
                catch (Exception x)
                {
                    Trace.TraceError(x.ToString());
                }
            }
            Uri host;

            if (nodes.TryGetValue(location, out host))
            {
                var preferedLeaders = RoleEnvironment.GetConfigurationSettingValue(serviceName + ".PreferedActiveMembers").Split(';');
                var localStorage    = RoleEnvironment.GetLocalResource("LocalStorage").RootPath;
                var storagePath     = Path.Combine(localStorage, serviceName);

                if (!Directory.Exists(storagePath))
                {
                    Directory.CreateDirectory(storagePath);
                }
                var storage       = new EsentStorage <string, SerialilzableWebRequest>(storagePath, new Counters(location));
                var configuration = new Configuration <string>(preferedLeaders, preferedLeaders, nodes.Keys);
                storage.TryInitialize(configuration);
                Trace.WriteLine("Local Storage Initialized");

                var meshPath = serviceName + "Mesh.ashx";
                var uri      = new UriBuilder(host)
                {
                    Path = meshPath
                }.Uri;
                X509Certificate2 cert = Utility.GetCert();
                var mesh = new MeshHandler <Message>(uri, null, cert);
                RouteTable.Routes.Add(new Route(meshPath, new FuncRouteHandler(_ => mesh)));

                FUSE.Weld.Azure.Configuration.SetConfigurationSettingPublisher();
                var s2        = Utility.GetStorageAccount(true);
                var container = s2.CreateCloudBlobClient().GetContainerReference("root");
                container.CreateIfNotExist();

                Trace.Write("Remote Storage Loaded");

                stateMachine = new ProxyStateMachine(location, nodes, mesh, storage, serviceName, preferedLeaders);

                stateMachine.Paxos.WhenDiverged.Subscribe(d =>
                {
                    Utility.DisableService(stateMachine.ServiceName);
                });

                Global.lastMessages[serviceName]  = new Queue <Timestamped <Tuple <string, Message, string> > >();
                Global.stateMachines[serviceName] = stateMachine;

                var o = stateMachine.Mesh
                        .Where(m => Interesting(m.Item2))
                        .Where(m => stateMachine.EndpointUrisToNames.ContainsKey(m.Item1))
                        .Select(m => Tuple.Create(stateMachine.EndpointUrisToNames[m.Item1], m.Item2, "To"))
                        .Timestamp();

                var i = mesh
                        .Where(m => Interesting(m.Item2))
                        .Where(m => stateMachine.EndpointUrisToNames.ContainsKey(m.Item1))
                        .Select(m => Tuple.Create(stateMachine.EndpointUrisToNames[m.Item1], m.Item2, "From"))
                        .Timestamp();

                i
                .Merge(o)
                .Subscribe(m =>
                {
                    try
                    {
                        lock (Global.lastMessages)
                        {
                            var lastMessages = Global.lastMessages[serviceName];
                            lastMessages.Enqueue(m);
                            while (lastMessages.Count > 1000)
                            {
                                lastMessages.Dequeue();
                            }
                        }
                    }
                    catch
                    {
                    }
                });
                var enabled      = false;
                var enabledState = container.GetBlobReference(serviceName + "EnabledState.txt");
                try
                {
                    enabled = Boolean.Parse(enabledState.DownloadText());
                }
                catch
                {
                }

                mesh.enabled = enabled;
                return(stateMachine);
            }
            else
            {
                throw new ArgumentException("Location not found");
            }
        }
Beispiel #8
0
    public void DoExport()
    {
        Directory.CreateDirectory(Manager.exportPath);

        // Main model
        if (Manager.meshes.Count != 0)
        {
            string[]      exportExclusionArray = File.ReadAllLines(Application.streamingAssetsPath + "\\Color Export Exclusion.txt");
            List <string> exportExclusion      = new List <string>(exportExclusionArray);

            // obj
            MeshHandler.Start();
            StringBuilder meshString = new StringBuilder();
            meshString.Append("mtllib ").Append(Manager.exportFileName).Append(".mtl\n");

            // New feature hacked in - this is the part where I stop caring again
            if (Manager.whatMeshesToMerge == WhatMeshesToMerge.OpaqueOnly)
            {
                List <CustomMesh> meshesTransparent = new List <CustomMesh>();

                bool dumbOpaqueFlag = false;
                for (int i = 0; i < Manager.meshes.Count; i++)
                {
                    if (!exportExclusion.Contains(Manager.colors[Manager.meshes[i].material].id.ToString()))
                    {
                        if (Manager.colors[Manager.meshes[i].material].rgba.a == 1)
                        {
                            // So we don't write this group definition if no opaque geometry exists
                            if (dumbOpaqueFlag == false)
                            {
                                meshString.Append("\ng Opaque\n");
                                dumbOpaqueFlag = true;
                            }
                            meshString.Append("\nusemtl ").Append(Manager.colors[Manager.meshes[i].material].legoName).Append("\n\n");
                            meshString.Append(MeshHandler.MeshToString(Manager.meshes[i]));
                        }
                        else
                        {
                            meshesTransparent.Add(Manager.meshes[i]);
                        }
                    }
                }
                for (int i = 0; i < meshesTransparent.Count; i++)
                {
                    meshString.Append("\ng Transparent").Append(i).Append("\n");
                    meshString.Append("\nusemtl ").Append(Manager.colors[meshesTransparent[i].material].legoName).Append("\n\n");
                    meshString.Append(MeshHandler.MeshToString(meshesTransparent[i]));
                }
            }
            // The old behavior - export all as one group with the file name, or individual groups/meshes as they were in the original 3DXML
            else
            {
                if (Manager.whatMeshesToMerge == WhatMeshesToMerge.All)
                {
                    meshString.Append("\ng ").Append(Manager.exportFileName).Append("\n");
                }
                for (int i = 0; i < Manager.meshes.Count; i++)
                {
                    if (!exportExclusion.Contains(Manager.colors[Manager.meshes[i].material].id.ToString()))
                    {
                        if (Manager.whatMeshesToMerge == WhatMeshesToMerge.None)
                        {
                            meshString.Append("\ng Mesh").Append(i).Append("\n");
                        }
                        meshString.Append("\nusemtl ").Append(Manager.colors[Manager.meshes[i].material].legoName).Append("\n\n");
                        meshString.Append(MeshHandler.MeshToString(Manager.meshes[i]));
                    }
                }
            }

            File.WriteAllText(Manager.exportPath + "\\" + Manager.exportFileName + ".obj", meshString.ToString());
            Debug.Log("Saved file " + Manager.exportFileName + ".obj");

            // mtl
            StringBuilder mtlString = new StringBuilder();
            for (int i = 0; i < Manager.sortedColors.Count; i++)
            {
                if (!exportExclusion.Contains(Manager.sortedColors[i].id.ToString()))
                {
                    mtlString.Append("newmtl ").Append(Manager.sortedColors[i].legoName).Append("\n");
                    mtlString.Append("Kd ").Append(Manager.sortedColors[i].rgba.r).Append(" ").Append(Manager.sortedColors[i].rgba.g).Append(" ").Append(Manager.sortedColors[i].rgba.b).Append("\n");
                    mtlString.Append("d ").Append(Manager.sortedColors[i].rgba.a).Append("\n");
                }
            }
            File.WriteAllText(Manager.exportPath + "\\" + Manager.exportFileName + ".mtl", mtlString.ToString());
            Debug.Log("Saved file " + Manager.exportFileName + ".mtl");
        }

        // Decal model
        if (Manager.meshesUV.Count != 0)
        {
            // obj
            MeshHandler.Start();
            StringBuilder meshStringUV = new StringBuilder();
            meshStringUV.Append("mtllib ").Append(Manager.exportFileName).Append("_UV.mtl\n");
            if (Manager.whatMeshesToMerge == WhatMeshesToMerge.All)
            {
                meshStringUV.Append("\ng ").Append(Manager.exportFileName).Append("_UV\n");
            }
            for (int i = 0; i < Manager.meshesUV.Count; i++)
            {
                if (Manager.whatMeshesToMerge == WhatMeshesToMerge.None || Manager.whatMeshesToMerge == WhatMeshesToMerge.OpaqueOnly)
                {
                    meshStringUV.Append("\ng MeshUV").Append(i).Append("\n");
                }
                // asdasjdhkjfsfgkjlh
                meshStringUV.Append("\nusemtl ").Append(Manager.textures[Manager.meshesUV[i].material].textureName).Append("\n\n");
                meshStringUV.Append(MeshHandler.MeshToString(Manager.meshesUV[i]));
                if (!Manager.usedTextures.Contains(Manager.textures[Manager.meshesUV[i].material]))
                {
                    Manager.usedTextures.Add(Manager.textures[Manager.meshesUV[i].material]);
                }
            }
            File.WriteAllText(Manager.exportPath + "\\" + Manager.exportFileName + "_UV.obj", meshStringUV.ToString());
            Debug.Log("Saved file " + Manager.exportFileName + "_UV.obj");

            // mtl
            StringBuilder mtlStringUV = new StringBuilder();
            for (int i = 0; i < Manager.usedTextures.Count; i++)
            {
                mtlStringUV.Append("newmtl ").Append(Manager.usedTextures[i].textureName).Append("\n");
                mtlStringUV.Append("Kd 1 1 1\n");
                mtlStringUV.Append("map_Kd ").Append(Manager.usedTextures[i].textureName).Append(".png\n");
                mtlStringUV.Append("map_d ").Append(Manager.usedTextures[i].textureName).Append(".png\n");
                File.WriteAllBytes(Manager.exportPath + "\\" + Manager.usedTextures[i].textureName + ".png", Manager.usedTextures[i].png);
                Debug.Log("Saved file " + Manager.usedTextures[i].textureName + ".png");
            }
            File.WriteAllText(Manager.exportPath + "\\" + Manager.exportFileName + "_UV.mtl", mtlStringUV.ToString());
            Debug.Log("Saved file " + Manager.exportFileName + "_UV.mtl");
        }
    }