Exemplo n.º 1
0
        public void CreateMeshGameObject(CreateRoadMeshScripts.MeshSet meshset, string objName, string materialName)
        {
            var materials = new Dictionary <string, string>()
            {
                { "TileMaterial", "Models/Background/Materials/RoadMaterial" },
                { "CurveTileMaterial", "Models/Background/Materials/CrossRoadMaterial" },
                { "CrossTileMaterial", "Models/Background/Materials/CrossRoadMaterial" },
            };
            var obj = new GameObject(objName);

            obj.transform.parent = this.parentTransform;
            var meshFilter = obj.AddComponent <MeshFilter>();
            var mesh       = meshset.CreateMesh();

            meshFilter.sharedMesh = mesh;
            var meshRenderer = obj.AddComponent <MeshRenderer>();

            meshRenderer.lightProbeUsage            = UnityEngine.Rendering.LightProbeUsage.Off;
            meshRenderer.reflectionProbeUsage       = UnityEngine.Rendering.ReflectionProbeUsage.Off;
            meshRenderer.shadowCastingMode          = UnityEngine.Rendering.ShadowCastingMode.Off;
            meshRenderer.receiveShadows             = false;
            meshRenderer.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion;
            var id = materials[materialName] + Liver.RaceWindow.RoadMaterial.ToString();

            meshRenderer.sharedMaterial = Resources.Load <Material>(id);
        }
Exemplo n.º 2
0
        /// <summary>
        /// メッシュを持つゲームオブジェクトを生成する。
        /// </summary>
        /// <param name="meshset">Meshset.</param>
        /// <param name="objName">Object name.</param>
        /// <param name="materialName">Material name.</param>
        private static void CreateMeshGameObject(CreateRoadMeshScripts.MeshSet meshset, string objName, string materialName)
        {
            Mesh mesh         = meshset.CreateMesh();
            var  obj          = new GameObject(objName);
            var  meshFilter   = obj.AddComponent <MeshFilter>();
            var  meshRenderer = obj.AddComponent <MeshRenderer>();

            meshFilter.sharedMesh       = mesh;
            meshRenderer.sharedMaterial = Resources.Load <Material>(materialName);
        }
Exemplo n.º 3
0
            public CreateRoadMeshScripts.MeshSet GetMeshSet()
            {
                var yBuf         = GetYoffset(0);
                var verticesList = new List <Vector3>();

                verticesList.Add(positionList[0] + Vector3.up * yBuf);
                verticesList.Add(positionList[1] + Vector3.up * yBuf);
                verticesList.Add(positionList[2] + Vector3.up * yBuf);
                verticesList.Add(positionList[3] + Vector3.up * yBuf);
                var trianglesList = new List <int>();
                var index         = 0;

                CreateRoadMeshScripts.AddTrianglesList(verticesList, trianglesList, index + 0, index + 1, index + 2, Vector3.up);
                CreateRoadMeshScripts.AddTrianglesList(verticesList, trianglesList, index + 1, index + 2, index + 3, Vector3.up);
                var uvList   = new List <Vector2>();
                var leftdown = new Vector2(1f / 8, 0f);
                var rightup  = new Vector2(1f - 1f / 8, 1f * num);

                uvList.Add(new Vector2(leftdown.x, leftdown.y));
                uvList.Add(new Vector2(rightup.x, leftdown.y));
                uvList.Add(new Vector2(leftdown.x, rightup.y));
                uvList.Add(new Vector2(rightup.x, rightup.y));
                var meshSet = new CreateRoadMeshScripts.MeshSet();

                meshSet.VerticesList  = verticesList;
                meshSet.TrianglesList = trianglesList;
                meshSet.UvList        = uvList;
                {
                    {
                        verticesList.Add(verticesList[index + 0] + Vector3.down);
                        verticesList.Add(verticesList[index + 2] + Vector3.down);
                        uvList.Add(new Vector2(0, leftdown.y));
                        uvList.Add(new Vector2(0, rightup.y));
                        var nextIndex = index + 4;
                        var left      = Quaternion.AngleAxis(-90, Vector3.up) * direction;
                        CreateRoadMeshScripts.AddTrianglesList(verticesList, trianglesList, index + 0, index + 2, nextIndex + 0, left);
                        CreateRoadMeshScripts.AddTrianglesList(verticesList, trianglesList, index + 2, nextIndex + 0, nextIndex + 1, left);
                    }
                    {
                        verticesList.Add(verticesList[index + 1] + Vector3.down);
                        verticesList.Add(verticesList[index + 3] + Vector3.down);
                        uvList.Add(new Vector2(1, leftdown.y));
                        uvList.Add(new Vector2(1, rightup.y));
                        var nextIndex = index + 4 + 2;
                        var right     = Quaternion.AngleAxis(90, Vector3.up) * direction;
                        CreateRoadMeshScripts.AddTrianglesList(verticesList, trianglesList, index + 1, index + 3, nextIndex + 0, right);
                        CreateRoadMeshScripts.AddTrianglesList(verticesList, trianglesList, index + 3, nextIndex + 0, nextIndex + 1, right);
                    }
                }
                return(meshSet);
            }
Exemplo n.º 4
0
    private static GameObject CreateRoadGameObject(string objectName, CreateRoadMeshScripts.MeshSet meshSet)
    {
        var obj        = new GameObject(objectName);
        var meshFilter = obj.AddComponent <MeshFilter>();
        var mesh       = meshSet.CreateMesh();

        meshFilter.sharedMesh = mesh;
        var meshRenderer = obj.AddComponent <MeshRenderer>();

        meshRenderer.sharedMaterial = Resources.Load <Material>("Demo/StandardGray");
        var meshCollider = obj.AddComponent <MeshCollider>();

        meshCollider.sharedMesh = mesh;
        return(obj);
    }
Exemplo n.º 5
0
        /// <summary>
        /// UV 設定を 左下 (0,0) 右上 (1,1) となるように変更する。
        /// </summary>
        /// <returns>The uv setting.</returns>
        /// <param name="input">Input.</param>
        public static CreateRoadMeshScripts.MeshSet ConvertUvSetting(CreateRoadMeshScripts.MeshSet input)
        {
            var leftDown = new Vector2(
                input.VerticesList.Min((point) => point.x),
                input.VerticesList.Min((point) => point.z)
                );
            var rightUp = new Vector2(
                input.VerticesList.Max((point) => point.x),
                input.VerticesList.Max((point) => point.z)
                );

            for (int i = 0; i < input.VerticesList.Count; i++)
            {
                var point = input.VerticesList[i];
                var x     = (point.x - leftDown.x) / (rightUp.x - leftDown.x);
                var y     = (point.z - leftDown.y) / (rightUp.y - leftDown.y);
                input.UvList[i] = new Vector2(x, y);
            }

            return(input);
        }