Exemplo n.º 1
0
        public void GeneratingMeshesAreNotDequeued()
        {
            var generating = new Dictionary <LegacyMeshId, MeshInfo>();
            var queue      = new MeshQueue();

            for (int i = 0; i < 100; ++i)
            {
                var meshId   = GetRandomMeshId();
                var meshInfo = new MeshInfo
                {
                    MeshId       = meshId,
                    ChangeState  = MeshChangeState.Added,
                    PriorityHint = Random.Range(0, 100)
                };

                queue.EnqueueUnique(meshInfo);

                if (Random.Range(0f, 1f) < .5f)
                {
                    generating[meshId] = meshInfo;
                }
            }

            while (generating.Count < queue.count)
            {
                bool result = queue.TryDequeue(generating, out MeshInfo meshInfo);
                Assert.That(result, "Could not dequeue a mesh info even though there are more items to dequeue.");
                Assert.That(!generating.ContainsKey(meshInfo.MeshId), "Should not dequeue a mesh info while it is generating.");
            }
        }
Exemplo n.º 2
0
        public void QueueIsUnique()
        {
            var generating    = new Dictionary <LegacyMeshId, MeshInfo>();
            var queue         = new MeshQueue();
            var uniqueMeshIds = new List <LegacyMeshId>();

            for (int i = 0; i < 100; ++i)
            {
                LegacyMeshId meshId;
                if (i == 0 || Random.Range(0f, 1f) < .5f)
                {
                    meshId = MakeMeshId((ulong)i, (ulong)i);
                    uniqueMeshIds.Add(meshId);
                }
                else
                {
                    meshId = uniqueMeshIds[Random.Range(0, uniqueMeshIds.Count - 1)];
                }

                var meshInfo = new MeshInfo
                {
                    MeshId       = meshId,
                    ChangeState  = MeshChangeState.Added,
                    PriorityHint = Random.Range(0, 100)
                };

                queue.EnqueueUnique(meshInfo);
                Assert.That(uniqueMeshIds.Count == queue.count);
            }
        }
    private GameObject InstantiateObject(Tile tile, MeshInfo info, Material material, GameObject prefab)
    {
        Vector3 position = Vector3.zero;

        foreach (var v in info.Vertices)
        {
            position += v;
        }

        position /= info.Vertices.Length;

        for (int i = 0; i < info.Vertices.Length; i++)
        {
            info.Vertices[i] -= position;
        }

        GameObject building = Instantiate(prefab, position, Quaternion.identity);
        MeshFilter filter   = building.GetComponent <MeshFilter>();
        Mesh       mesh     = new Mesh();

        mesh.vertices  = info.Vertices;
        mesh.triangles = info.Triangles;
        mesh.SetUVs(0, new List <Vector2>(info.UVs));
        mesh.RecalculateTangents();
        mesh.RecalculateNormals();
        mesh.RecalculateBounds();
        mesh.Optimize();
        filter.mesh = mesh;
        MeshRenderer renderer = building.GetComponent <MeshRenderer>();

        renderer.material = material;
        gameObjectTilemap.AttachObjectToTile(tile, building);
        return(building);
    }
Exemplo n.º 4
0
            /// <summary>
            /// Export the mesh's UVs using layer 0.
            /// </summary>
            ///
            public void ExportUVs(MeshInfo mesh, FbxMesh fbxMesh)
            {
                using (var fbxLayerElement = FbxLayerElementUV.Create(fbxMesh, "UVSet"))
                {
                    fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByPolygonVertex);
                    fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eIndexToDirect);

                    // set texture coordinates per vertex
                    FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray();

                    for (int n = 0; n < mesh.UV.Length; n++)
                    {
                        fbxElementArray.Add(new FbxVector2(mesh.UV [n] [0],
                                                           mesh.UV [n] [1]));
                    }

                    // For each face index, point to a texture uv
                    FbxLayerElementArray fbxIndexArray = fbxLayerElement.GetIndexArray();
                    fbxIndexArray.SetCount(mesh.Indices.Length);

                    for (int vertIndex = 0; vertIndex < mesh.Indices.Length; vertIndex++)
                    {
                        fbxIndexArray.SetAt(vertIndex, mesh.Indices [vertIndex]);
                    }
                    GetBaseLayer(fbxMesh).SetUVs(fbxLayerElement, FbxLayerElement.EType.eTextureDiffuse);
                }
            }
Exemplo n.º 5
0
    /// <summary>
    /// Rebuilds the mesh
    /// </summary>
    public void Refresh()
    {
        StartMeshInfo = null;
        EndMeshInfo   = null;
        mMesh.Clear();
        //Debug.Log("Refresh Mesh at " + Time.realtimeSinceStartup);
        if (!Spline || !Spline.IsInitialized)
        {
            return;
        }

        BuildCaps();
        Prepare();

        if (StartMesh && StartMeshInfo != null && ToTF - FromTF != 0)
        {
            mVerts = new Vector3[getTotalVertexCount()];
            mUV    = new Vector2[mVerts.Length];
            mTris  = new int[getTotalTriIndexCount()];
            Extrude();

            mMesh.vertices  = mVerts;
            mMesh.uv        = mUV;
            mMesh.triangles = mTris;
            mMesh.RecalculateNormals();
        }
    }
Exemplo n.º 6
0
        private void button28_Click(object sender, EventArgs e)
        {
            m = new Mem("ePSXe");

            uint levPtr      = 0x80083a48;
            uint lev         = m.ReadPSXUInt32(levPtr);
            uint size        = m.ReadPSXUInt32(lev - 4);
            uint ptrMeshInfo = m.ReadPSXUInt32(lev - 4);

            byte[] meshinfodata = m.ReadArray(ptrMeshInfo, 8 * 4);

            MeshInfo mi;

            using (BinaryReaderEx br = new BinaryReaderEx(new MemoryStream(meshinfodata)))
            {
                mi = new MeshInfo(br);
            }

            ushort ind = m.ReadPSXUInt16(mi.ptrQuadBlockArray);

            textBox5.Text += ind.ToString("X8");

            m.WritePSXUInt32((uint)(mi.ptrVertexArray + ind * 16 + 8), 0, textBox5);
            m.WritePSXUInt32((uint)(mi.ptrVertexArray + ind * 16 + 12), 0, textBox5);


            //m.WriteArray(lev, b);
        }
Exemplo n.º 7
0
            private void ModelUpdated()
            {
                if (model != null)
                {
                    // Create mesh-per-entity state
                    meshInfos.Clear();
                    foreach (var mesh in model.Meshes)
                    {
                        var meshData = new MeshInfo();
                        meshInfos.Add(meshData);

                        if (mesh.Skinning != null)
                        {
                            meshData.BlendMatrices = new Matrix[mesh.Skinning.Bones.Length];
                        }
                    }

                    if (skeleton != null)
                    {
                        // Reuse previous ModelViewHierarchy
                        skeleton.Initialize(model.Skeleton);
                    }
                    else
                    {
                        skeleton = new SkeletonUpdater(model.Skeleton);
                    }
                }
            }
Exemplo n.º 8
0
    private bool Initialize()
    {
        bool returnFalse = false;

        _mesheFilters = GetComponentsInChildren <MeshFilter>();
        foreach (MeshFilter meshFilter in _mesheFilters)
        {
            CurvatureFilter.DuplicateMeshVertices(meshFilter.sharedMesh);
        }
        if (_meshInfosMerged == null)
        {
            Mesh[] smoothMesh;
            GetAllSmoothMeshes(out smoothMesh, out _mapFromNew);
            _meshInfosMerged     = new MeshInfo[smoothMesh.Length];
            _meshInfosDuplicated = new MeshInfo[smoothMesh.Length];
            _curvatureDatas      = new CurvatureData[smoothMesh.Length];
            for (int i = 0; i < _mesheFilters.Length; i++)
            {
                _meshInfosMerged[i] = new MeshInfo(smoothMesh[i]);
                _curvatureDatas[i]  = new CurvatureData(smoothMesh[i].vertexCount);
            }
            returnFalse = true;
        }

        if (returnFalse)
        {
            return(false);
        }
        return(true);
    }
Exemplo n.º 9
0
        public virtual Case_Load CreateCaseLoad(BaseCaseData caseData)
        {
            MeshInfo boxInfo = new MeshInfo()
            {
                color    = caseData.colour,
                filename = Case_Load.GraphicsMesh,
                length   = caseData.Length,
                width    = caseData.Width,
                height   = caseData.Height
            };

            Case_Load   load        = new Case_Load(boxInfo);
            DCICaseData caseDataDCi = caseData as DCICaseData;

            if (caseDataDCi == null)
            {
                Log.Write("ERROR: Bad cast to DCICaseData in CreateCaseLoad", Color.Red);
                return(null);
            }

            load.Weight         = caseData.Weight;
            load.Identification = caseDataDCi.TUIdent;
            load.SSCCBarcode    = caseDataDCi.TUIdent;
            load.Case_Data      = caseData;
            return(load);
        }
    private void GetTriangles(object obj)
    {
        MeshInfo meshInfo = (MeshInfo)obj;

        Vector3[]      vertices  = meshInfo.vertices;
        int[]          tris      = meshInfo.tris;
        TriangleInfo[] triangles = new TriangleInfo[tris.Length / 3];
        for (int i = 0; i < tris.Length; i += 3)
        {
            Vector3 v1 = GetVertexWorldPosition(vertices[tris[i]], meshInfo.matrix);
            Vector3 v2 = GetVertexWorldPosition(vertices[tris[i + 1]], meshInfo.matrix);
            Vector3 v3 = GetVertexWorldPosition(vertices[tris[i + 2]], meshInfo.matrix);
            triangles[i / 3] = new TriangleInfo
            {
                p1 = v1,
                p2 = v2,
                p3 = v3,
            };
        }
        lock (_locker)
        {
            for (int i = 0; i < triangles.Length; i++)
            {
                _triangleList.Add(triangles[i]);
            }
            _completeCount++;
        }
    }
Exemplo n.º 11
0
        internal static void MakeText(MeshInfo meshInfo, Vector2 offset, MeshBuilder.AllocMeshData meshAlloc)
        {
            int           num           = MeshBuilder.LimitTextVertices(meshInfo.vertexCount, true);
            int           num2          = num / 4;
            MeshWriteData meshWriteData = meshAlloc.Allocate((uint)(num2 * 4), (uint)(num2 * 6));
            int           i             = 0;
            int           num3          = 0;
            int           num4          = 0;

            while (i < num2)
            {
                meshWriteData.SetNextVertex(MeshBuilder.ConvertTextVertexToUIRVertex(meshInfo, num3, offset));
                meshWriteData.SetNextVertex(MeshBuilder.ConvertTextVertexToUIRVertex(meshInfo, num3 + 1, offset));
                meshWriteData.SetNextVertex(MeshBuilder.ConvertTextVertexToUIRVertex(meshInfo, num3 + 2, offset));
                meshWriteData.SetNextVertex(MeshBuilder.ConvertTextVertexToUIRVertex(meshInfo, num3 + 3, offset));
                meshWriteData.SetNextIndex((ushort)num3);
                meshWriteData.SetNextIndex((ushort)(num3 + 1));
                meshWriteData.SetNextIndex((ushort)(num3 + 2));
                meshWriteData.SetNextIndex((ushort)(num3 + 2));
                meshWriteData.SetNextIndex((ushort)(num3 + 3));
                meshWriteData.SetNextIndex((ushort)num3);
                i++;
                num3 += 4;
                num4 += 6;
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Rebuilds the mesh
        /// </summary>
        public void Refresh()
        {
            StartMeshInfo = null;
            EndMeshInfo   = null;
            if (mMesh)
            {
                mMesh.Clear();
            }

            if (!mMesh || !Spline || !Spline.IsInitialized || Spline.Length == 0)
            {
                return;
            }

            BuildCaps();
            Prepare();
            if (StartMesh && StartMeshInfo != null && ToTF - FromTF != 0)
            {
                mVerts = new Vector3[getTotalVertexCount()];
                mUV    = new Vector2[mVerts.Length];
                mTris  = new int[getTotalTriIndexCount()];
                Extrude();

                mMesh.vertices  = mVerts;
                mMesh.uv        = mUV;
                mMesh.triangles = mTris;
                mMesh.RecalculateNormals();
                if (CalculateTangents)
                {
                    MeshHelper.CalculateMeshTangents(mMesh);
                }
            }
        }
Exemplo n.º 13
0
    static void Init()
    {
        // Get existing open window or if none, make a new one:
        MeshInfo window = (MeshInfo)EditorWindow.GetWindow(typeof(MeshInfo));

        window.titleContent.text = "Mesh Info";
    }
Exemplo n.º 14
0
    public static void ComputeCurvature(ref MeshInfo meshInfo, out CurvatureData outData)
    {
        int n = meshInfo.vertexCount;

        outData = new CurvatureData(n);

        int[] cornerTable = BuildCornerTable(meshInfo.mesh);

        for (int i = 0; i < n; i++)
        {
            List <int> neighboors = GetOrderedNeighboors(meshInfo.mesh, i, cornerTable);
            meshInfo.neighboohood.Add(neighboors);
            float[] r, phi;

            Matrix <float> F;
            MakeExponentialMap(meshInfo.mesh, i, neighboors, out r, out phi);
            GetUVF(meshInfo.mesh, r, phi, neighboors.ToArray(), i, out F);
            GetCurvatures(F, i, ref outData, meshInfo.mesh.normals[i]);
            Vector3[] pds = GetTransformedValues(F, ref outData, i);
            FixPdsOrder(ref pds, outData.normal);
            meshInfo.approximatedNormals[i] = outData.normal;
            meshInfo.principalDirections[i] = pds[0];
            for (int j = 0; j < 4; j++)
            {
                meshInfo.AllPrincipalDirections[i, j] = pds[j];
            }
            //Debug.Log(String.Format("Vert: {0}, Curv: {1}, {2}", meshInfo.mesh.vertices[i],
            //    meshInfo.AllPrincipalDirections[i, 0], meshInfo.AllPrincipalDirections[i, 1]));
        }
        meshInfo.curvatureRatios = ComputeCurvatureRatio(outData.k1, outData.k2);
    }
        void UpdateMeshInfo(ref MeshInfo info)
        {
            Profiler.BeginSample("upd-mesh-inf");
            if (meshBuffers == null)
            {
                info.valid = false;
            }
            else
            {
                info.meshBuffers = meshBuffers;

                const bool weldedAdjacency = false;                //TODO enable for more reliable poses along uv seams

                if (info.meshAdjacency == null)
                {
                    info.meshAdjacency = new MeshAdjacency(meshBuffers, weldedAdjacency);
                }
                else if (info.meshAdjacency.vertexCount != meshBuffers.vertexCount)
                {
                    info.meshAdjacency.LoadFrom(meshBuffers, weldedAdjacency);
                }

                if (info.meshVertexBSP == null)
                {
                    info.meshVertexBSP = new KdTree3(meshBuffers.vertexPositions, meshBuffers.vertexCount);
                }
                else
                {
                    info.meshVertexBSP.BuildFrom(meshBuffers.vertexPositions, meshBuffers.vertexCount);
                }

                info.valid = true;
            }
            Profiler.EndSample();
        }
Exemplo n.º 16
0
        public ArcMeshInfo(int sides, float width, int arcAngle, float radius, float arcHeight)
        {
            vertices  = new Vector3[0];
            triangles = new int[0];

            bool  isCircle  = arcAngle == 360;
            float angleStep = arcAngle / sides;
            //int steps = isCircle ? sides : sides + 1;
            int steps = sides + 1;

            MeshInfo top    = GetArcMesh(angleStep, sides, width, radius, steps, arcHeight, false, isCircle);
            MeshInfo bottom = GetArcMesh(angleStep, sides, width, radius, steps, 0, true, isCircle);

            for (int i = 0; i < bottom.triangles.Length; i++)
            {
                bottom.triangles[i] += top.vertices.Length;
            }

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

            tris.AddRange(top.triangles);
            tris.AddRange(bottom.triangles);
            int[] _tris = tris.ToArray();

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

            verts.AddRange(top.vertices);
            verts.AddRange(bottom.vertices);
            Vector3[] _verts = verts.ToArray();


            vertices  = _verts;
            triangles = _tris;
        }
Exemplo n.º 17
0
            /// <summary>
            /// set weight vertices to cluster
            /// </summary>
            protected void SetVertexWeights(MeshInfo meshInfo, Dictionary <int, FbxCluster> boneCluster)
            {
                // set the vertex weights for each bone
                for (int i = 0; i < meshInfo.BoneWeights.Length; i++)
                {
                    var   boneWeights = meshInfo.BoneWeights;
                    int[] indices     =
                    {
                        boneWeights [i].boneIndex0,
                        boneWeights [i].boneIndex1,
                        boneWeights [i].boneIndex2,
                        boneWeights [i].boneIndex3
                    };
                    float[] weights =
                    {
                        boneWeights [i].weight0,
                        boneWeights [i].weight1,
                        boneWeights [i].weight2,
                        boneWeights [i].weight3
                    };

                    for (int j = 0; j < indices.Length; j++)
                    {
                        if (weights [j] <= 0)
                        {
                            continue;
                        }
                        if (!boneCluster.ContainsKey(indices [j]))
                        {
                            continue;
                        }
                        boneCluster [indices [j]].AddControlPointIndex(i, weights [j]);
                    }
                }
            }
Exemplo n.º 18
0
        public async Task TappedSave()
        {
            if (SpatialUnderstanding.Instance.ScanState == SpatialUnderstanding.ScanStates.Done)
            {
                SpatialUnderstandingState.Instance.MeshSaving = true;
                // Save the file temporarily
                DebugDialog.Instance.PrimaryText = "Saving Mesh...";
                string rowkey = DateTime.Now.ToString("yyyyMMdd");
                string fn     = "mesh_" + rowkey + "T" + DateTime.Now.ToString("HHmm");
                RoomSaver.Instance.fileName        = fn;
                RoomSaver.Instance.anchorStoreName = "mesh_test_anchor";
                string metadata  = RoomSaver.Instance.GetStatsAsString();
                string localpath = await RoomSaver.Instance.SaveRoomAsync(metadata);

                Debug.Log("File Name: " + localPath);
                Debug.Log("MeshInfo " + fn);
                // Prepare file for push to Azure Storage
                MeshInfo tempInfo = new MeshInfo(rowkey)
                {
                    playspaceStats = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticPlayspaceStats(),
                    metadata       = metadata,
                    localpath      = localpath,
                    filename       = fn + ".obj" //Not working Path.GetFileName(localPath)
                };
                Debug.Log(tempInfo.filename);
                //Debug.Log("Wall Area " + SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticPlayspaceStats().WallSurfaceArea);
                StorageService.Instance.PutObjectToBlob(tempInfo);
            }
        }
Exemplo n.º 19
0
        private void UpdateMeshInfoRecursively(FbxSDK.Node node, ref Matrix4 parentMatrix)
        {
            int childCount = node.GetChildCount();

            Matrix4 globalTransform = GetGlobalTransform(node, parentMatrix);

            FbxSDK.Mesh mesh = node.GetAttribute() as FbxSDK.Mesh;
            if (mesh != null)
            {
                Matrix4 meshTransform = GetGeometry(node) * globalTransform;

                MeshInfo meshInfo = FindMeshInfo(mesh);
                if (meshInfo == null)
                {
                    meshInfo = LoadMesh(mesh);
                }

                meshInfo.geometryToWorld = meshTransform;
            }

            for (int i = 0; i < childCount; ++i)
            {
                UpdateMeshInfoRecursively(node.GetChild(i), ref globalTransform);
            }
        }
Exemplo n.º 20
0
    public void UpdateTextInfo(int id, InlineText key, List <SpriteTagInfo> value)
    {
        if (!_indexSpriteGraphic.ContainsKey(id) || !_textMeshInfo.ContainsKey(id) || value.Count <= 0)
        {
            return;
        }
        int     spriteTagCount = value.Count;
        Vector3 textPos        = key.transform.position;
        Vector3 spritePos      = _indexSpriteGraphic[id].SpriteGraphic.transform.position;
        Vector3 disPos         = (textPos - spritePos) * (1.0f / key.pixelsPerUnit);

        //新增摄像机模式的位置判断
        if (key.canvas != null)
        {
            if (key.canvas.renderMode != RenderMode.ScreenSpaceOverlay)
            {
                Vector3 scale = key.canvas.transform.localScale;
                disPos  = new Vector3(disPos.x / scale.x, disPos.y / scale.y, disPos.z / scale.z);
                disPos /= (1.0f / key.pixelsPerUnit);
            }
        }

        MeshInfo meshInfo = new MeshInfo();

        meshInfo.Tag       = new string[spriteTagCount];
        meshInfo.Vertices  = new Vector3[spriteTagCount * 4];
        meshInfo.Uv        = new Vector2[spriteTagCount * 4];
        meshInfo.Triangles = new int[spriteTagCount * 6];
        for (int i = 0; i < value.Count; i++)
        {
            int m = i * 4;
            //标签
            meshInfo.Tag[i] = value[i].Tag;
            //顶点位置
            meshInfo.Vertices[m + 0] = value[i].Pos[0] + disPos;
            meshInfo.Vertices[m + 1] = value[i].Pos[1] + disPos;
            meshInfo.Vertices[m + 2] = value[i].Pos[2] + disPos;
            meshInfo.Vertices[m + 3] = value[i].Pos[3] + disPos;
            //uv
            meshInfo.Uv[m + 0] = value[i].Uv[0];
            meshInfo.Uv[m + 1] = value[i].Uv[1];
            meshInfo.Uv[m + 2] = value[i].Uv[2];
            meshInfo.Uv[m + 3] = value[i].Uv[3];
        }
        if (_textMeshInfo[id].ContainsKey(key))
        {
            MeshInfo oldMeshInfo = _textMeshInfo[id][key];
            if (!meshInfo.Equals(oldMeshInfo))
            {
                _textMeshInfo[id][key] = meshInfo;
            }
        }
        else
        {
            _textMeshInfo[id].Add(key, meshInfo);
        }

        //更新图片
        DrawSprites(id);
    }
Exemplo n.º 21
0
        public static Case_Load FeedCaseLoad(ITransportSection transportSection, float distance, float length, float width, float height, float weight, Color color, int barcodeLength, BaseCaseData caseData)
        {
            try
            {
                string SSCCBarcode = "";

                MeshInfo boxInfo = new MeshInfo();
                boxInfo.color    = color;
                boxInfo.filename = Case_Load.GraphicsMesh;

                SSCCBarcode    = GetSSCCBarcode();// GetSSCCBarcode(barcodeLength);
                boxInfo.length = length;
                boxInfo.width  = width;
                boxInfo.height = height;

                Case_Load boxLoad = new Case_Load(boxInfo);
                boxLoad.Case_Data        = caseData;
                boxLoad.Case_Data.Weight = weight;
                transportSection.Route.Add(boxLoad, distance);
                Experior.Core.Loads.Load.Items.Add(boxLoad);

                if (SSCCBarcode != "")
                {
                    boxLoad.SSCCBarcode = SSCCBarcode;
                }
                return(boxLoad);
            }
            catch (Exception se)
            {
                Core.Environment.Log.Write(se);
                Core.Environment.Scene.Pause();
                return(null);
            }
        }
    private static MeshInfo NaiveCube(Chunk _chunk, int _x, int _y, int _z, MeshInfo _mesh_info, Voxel _voxel)
    {
        //determine face to create based on adjacency
        if (ShouldMakeFace(_chunk, _x, _y + 1, _z))
        {
            _mesh_info = CreateTopFace(_x, _y, _z, _mesh_info, _voxel);
        }

        if (ShouldMakeFace(_chunk, _x, _y - 1, _z))
        {
            _mesh_info = CreateBottomFace(_x, _y, _z, _mesh_info, _voxel);
        }

        if (ShouldMakeFace(_chunk, _x, _y, _z + 1))
        {
            _mesh_info = CreateBackFace(_x, _y, _z, _mesh_info, _voxel);
        }

        if (ShouldMakeFace(_chunk, _x, _y, _z - 1))
        {
            _mesh_info = CreateFrontFace(_x, _y, _z, _mesh_info, _voxel);
        }

        if (ShouldMakeFace(_chunk, _x + 1, _y, _z))
        {
            _mesh_info = CreateRightFace(_x, _y, _z, _mesh_info, _voxel);
        }

        if (ShouldMakeFace(_chunk, _x - 1, _y, _z))
        {
            _mesh_info = CreateLeftFace(_x, _y, _z, _mesh_info, _voxel);
        }

        return(_mesh_info);
    }
Exemplo n.º 23
0
    public void SetDrawMesh(MeshFilter filter, string key)
    {
        MeshInfo drawMesh = null;

        meshes.TryGetValue(key, out drawMesh);
        filter.mesh = drawMesh.mesh;
    }
Exemplo n.º 24
0
        public Case_Load CreateCaseLoad(BaseCaseData caseData)
        {
            MeshInfo boxInfo = new MeshInfo()
            {
                color    = caseData.colour,
                filename = Case_Load.GraphicsMesh,
                length   = caseData.Length,
                width    = caseData.Width,
                height   = caseData.Height
            };

            Case_Load load       = new Case_Load(boxInfo);
            CaseData  DatComData = caseData as CaseData;

            if (DatComData == null)
            {
                Log.Write("ERROR: Bad cast to CaseData in CreateCaseLoad", Color.Red);
                return(null);
            }

            load.Weight         = caseData.Weight;
            load.Identification = DatComData.ULID;
            load.Case_Data      = DatComData;
            return(load);
        }
Exemplo n.º 25
0
    public void Generate(List <Tile> tileList, TileSet tileSet)
    {
        currentTiles       = new List <Tile>(tileList);
        meshes             = new Dictionary <string, MeshInfo>();
        meshes["ground"]   = new MeshInfo();
        meshes["platform"] = new MeshInfo();
        foreach (var t in tileList)
        {
            string type = "";
            switch (t.data.collisions)
            {
            case TileData.CollisionType.Platform:
            {
                type = "platform";
            } break;

            case TileData.CollisionType.Solid:
            {
                type = "ground";
            } break;
            }

            if (!string.IsNullOrEmpty(type))
            {
                meshes[type].tiles.Add(t);
            }
        }
        GenerateDrawMesh(meshes["ground"].tiles, "ground");
        GenerateDrawMesh(meshes["platform"].tiles, "platform");
        BuildEdgeGraph();
        GenerateColliderPaths();
    }
Exemplo n.º 26
0
    private void Start()
    {
        meshInfo = gameManager.meshInfo;

        meshInfo.deep = meshInfo.squareAmount - (meshInfo.squareAmount * meshInfo.perCentDeep) / 100;
        CreatePlane().CreateMesh();
    }
Exemplo n.º 27
0
        private Mesh CreateMesh()
        {
            MeshInfo meshInfo = SelectMeshInfo();

            if (internalMesh != null)
            {
                internalMesh.Clear();
            }
            else
            {
                internalMesh = new Mesh();
            }
            var vertices  = meshInfo.Vertices;
            var triangles = meshInfo.Triangles;

            Vector3[] newVertices = new Vector3[vertices.Length];
            for (int i = 0; i < newVertices.Length; i++)
            {
                var x = vertices[i].x;
                var y = vertices[i].y;
                var z = vertices[i].z;
//                newVertices[i] = Isometric.IsoToUnitySpace(new Vector3(x,y,z)-Vector3.one/2 );
                newVertices[i] = new Vector3(x, y, z) - Vector3.one / 2;
            }
            internalMesh.Clear();
            internalMesh.vertices  = newVertices;
            internalMesh.triangles = triangles;
            internalMesh.RecalculateNormals();
//            GetComponent<MeshCollider>().sharedMesh = mesh;
            return(internalMesh);
        }
Exemplo n.º 28
0
    void Start()
    {
        var path = Path.Combine(Application.dataPath, fontDataPath);

        if (File.Exists(path))
        {
            var source = File.ReadAllText(path);

            fontData = JsonConvert.DeserializeObject <MSDFFontData>(source);

            MeshInfo info = MSDFTextMesh.GetMeshInfo("hello", fontData, true);
            Debug.Log(info.uvs.Length);
        }

        //numTextGroups = GetTextGroupCount();

        textSettings = new TextSettings[1];

        var text = "";

        for (var i = 0; i < textSettings.Length; ++i)
        {
            text            = quotes[Random.Range(0, quotes.Count)];
            textSettings[i] = new TextSettings(text, MSDFTextMesh.GetMeshInfo(text, fontData, true));
        }

        instanceMesh = CreateMesh();

        instanceMaterial = new Material(Shader.Find("Unlit/InstanceShader"));
        instanceMaterial.SetColor("_Color", Random.ColorHSV());
        instanceMaterial.SetTexture("_MainTex", msdfTexture);

        argsBuffer = new ComputeBuffer(1, args.Length * sizeof(uint), ComputeBufferType.IndirectArguments);
        UpdateBuffers();
    }
Exemplo n.º 29
0
    public override void OnInspectorGUI()
    {
        MeshInfo info = (MeshInfo)target;

        MeshFilter filter = info.GetComponent <MeshFilter>();

        if (filter == null)
        {
            GUILayout.Label("No MeshFilter found.");
            return;
        }

        Mesh mesh = filter.sharedMesh;

        if (mesh == null)
        {
            GUILayout.Label("No Mesh found.");
            return;
        }

        foreach (var vertex in mesh.vertices)
        {
            GUILayout.Label(vertex.x.ToString("0.000") + ", " + vertex.y.ToString("0.00000000") + ", " + vertex.z.ToString("0.000"));
        }

        GUILayout.Label("UVs");

        foreach (var uv in mesh.uv)
        {
            GUILayout.Label(uv.x.ToString("0.000") + ", " + uv.y.ToString("0.000"));
        }

        GUILayout.Label("Vert Count: " + mesh.vertexCount);
    }
Exemplo n.º 30
0
        private static void setMedium(SimulationParameters parameters, MeshInfo meshInfo)
        {
            var factory = new MediumSolverFactory(parameters.TimeStep);

            //parameters.Medium = setSphere(parameters, silver, drudeLorentzParam, vacuum);
            parameters.Medium = setObject(parameters, meshInfo.Voxels, factory);
        }
    void Prepare()
    {
#if UNITY_EDITOR
        mPerfWatch.Reset();
        mPerfWatch.Start();
#endif
        if (Spline && StartMesh && ExtrusionParameter > 0) {
            StartMeshInfo = new MeshInfo(StartMesh, true, false);
            if (EndMesh)
                EndMeshInfo = new MeshInfo(EndMesh, false, true);
            else
                EndMeshInfo = new MeshInfo(StartMesh, false, true);

            

            // Calculate Steps
            float tf = FromTF;
            mSegmentInfo.Clear();
            FromTF = Mathf.Clamp01(FromTF);
            ToTF = Mathf.Max(FromTF, Mathf.Clamp01(ToTF));
            Vector3 scale;
            if (FromTF != ToTF) {
                switch (Extrusion) {
                    case MeshExtrusion.FixedF:
                        while (tf < ToTF) {
                            scale = getScale(tf);
                            mSegmentInfo.Add(new CurvyMeshSegmentInfo(this, tf,scale));
                            tf += ExtrusionParameter;
                        }
                        break;
                    case MeshExtrusion.FixedDistance:
                        float d = Spline.TFToDistance(FromTF);
                        tf = Spline.DistanceToTF(d);
                        while (tf < ToTF) {
                            scale = getScale(tf);
                            mSegmentInfo.Add(new CurvyMeshSegmentInfo(this, tf, d, scale));
                            d += ExtrusionParameter;
                            tf = Spline.DistanceToTF(d);
                        }
                        break;
                    case MeshExtrusion.Adaptive:
                        while (tf < ToTF) {
                            scale = getScale(tf);
                            mSegmentInfo.Add(new CurvyMeshSegmentInfo(this, tf, scale));
                            int dir = 1;
                            Spline.MoveByAngle(ref tf, ref dir, ExtrusionParameter, CurvyClamping.Clamp, 0.001f);
                        }
                        break;
                }
                if (!Mathf.Approximately(tf, ToTF))
                    tf = ToTF;
                scale = getScale(tf);
                mSegmentInfo.Add(new CurvyMeshSegmentInfo(this, tf, scale));
            }
        }
#if UNITY_EDITOR
        mPerfWatch.Stop();
        DebugPerfPrepare = mPerfWatch.ElapsedTicks / (double)System.TimeSpan.TicksPerMillisecond;
        mPerfWatch.Reset();
#endif
    }
Exemplo n.º 32
0
        private void ModelUpdated()
        {
            if (model != null)
            {
                // Create mesh-per-entity state
                meshInfos.Clear();
                foreach (var mesh in model.Meshes)
                {
                    var meshData = new MeshInfo();
                    meshInfos.Add(meshData);

                    if (mesh.Skinning != null)
                        meshData.BlendMatrices = new Matrix[mesh.Skinning.Bones.Length];
                }

                if (skeleton != null)
                {
                    // Reuse previous ModelViewHierarchy
                    skeleton.Initialize(model.Skeleton);
                }
                else
                {
                    skeleton = new SkeletonUpdater(model.Skeleton);
                }
            }
        }
    /// <summary>
    /// Rebuilds the mesh
    /// </summary>
    public void Refresh()
    {
        StartMeshInfo = null;
        EndMeshInfo = null;
        mMesh.Clear();
        //Debug.Log("Refresh Mesh at " + Time.realtimeSinceStartup);
        if (!Spline || !Spline.IsInitialized) return;
        
        BuildCaps();
        Prepare();
        
        if (StartMesh && StartMeshInfo!=null && ToTF - FromTF != 0) {
            mVerts = new Vector3[getTotalVertexCount()];
            mUV = new Vector2[mVerts.Length];
            mTris = new int[getTotalTriIndexCount()];
            Extrude();

            mMesh.vertices = mVerts;
            mMesh.uv = mUV;
            mMesh.triangles = mTris;
            mMesh.RecalculateNormals();
        }
    }
Exemplo n.º 34
0
        private static void TransformForPluginMode(DynamicRenderMesh mesh, MeshInfo meshInfo)
        {
            if (!ProgramCore.PluginMode)
                return;

            var scaleCoef = 1f;
            if (mesh.meshType == MeshType.Accessory)
                scaleCoef = 246f;
            else if (mesh.meshType == MeshType.Head)
                scaleCoef = PickingController.GetHeadScale(ProgramCore.Project.ManType);
            else
                scaleCoef = PickingController.GetHairScale(ProgramCore.Project.ManType);

            var d = ProgramCore.MainForm.ctrlRenderControl.pickingController.ObjExport.Delta;
            d.Y -= 0.0060975609f;
            var tempTransform = mesh.Transform * Matrix4.CreateTranslation(d * scaleCoef);
            var dp = new Vector3(mesh.Transform[3, 0], mesh.Transform[3, 1], mesh.Transform[3, 2]) -
                new Vector3(tempTransform[3, 0], tempTransform[3, 1], tempTransform[3, 2]);

            for (int i = 0; i < meshInfo.Positions.Count; ++i)
            {
                var position = meshInfo.Positions[i];
                position += dp;
                meshInfo.Positions[i] = position;
            }
        }
    // Update is called once per frame
    void Update()
    {
        //at the start, or if more objects have been added to the scene
        //initialize the meshObjects array and set the rotations
        //and positions of each meshObject
        if(GameObject.FindObjectsOfType(typeof(MeshFilter)).Length != meshObjects.Length) {
            MeshFilter[] meshFilters = GameObject.FindObjectsOfType(typeof(MeshFilter))
                as MeshFilter[];
            meshObjects = new MeshInfo[meshFilters.Length];
            for(int i = 0; i <  meshFilters.Length; i++) {
                meshObjects[i] = new MeshInfo(
                    meshFilters[i].transform.position,
                    meshFilters[i].transform.rotation,
                    meshFilters[i]);
            }
        }

        //false if the plane has not moved since last update
        bool planeMoved = false;

        //if the plane has moved or rotated since last update,
        //update it's location variables and set planeMoved to false
        if(transform.position != lastPos || transform.rotation != lastRot) {
            lastPos = transform.position;
            lastRot = transform.rotation;
            planeMoved = true;
        }

        //Main loop; checks if mesh objects are intersecting with the plane,
        //and if they have moved or rotated since last update
        for(int i = 0; i < meshObjects.Length; i++) {
            MeshFilter meshObject = meshObjects[i].meshObject;

            if(meshObject.GetComponent<Renderer>() == GetComponent<Renderer>())
                continue; //to not check the plane against itself
            meshObject.GetComponent<Renderer>().enabled = showMesh;

            //continue if object intersects with plane
            if(GetComponent<Renderer>().bounds.Intersects(meshObject.GetComponent<Renderer>().bounds)) {
                //update mesh info if the plane has been moved, or if the mesh's position
                //or rotation has been changed, or if the mesh has no intersection points.
                if(planeMoved || !meshObject.transform.position.Equals(meshObjects[i].position) ||
                !meshObject.transform.rotation.Equals(meshObjects[i].rotation) ||
                meshObjects[i].points == null) {
                    meshObjects[i].position = meshObject.transform.position;
                    meshObjects[i].rotation = meshObject.transform.rotation;

                    FindIntersectionPoints(i);
                }
            } else meshObjects[i].points = null; //set intersection points to null if the object is
                                                 //no longer intersecting with the plane
        }

        //draws the points found by FindIntersectionPoints()
        for(int i = 0; i < meshObjects.Length; i++) {
            List<Vector3> points = meshObjects[i].points;
            if(points != null) {
                for(int j = 0; j < points.Count; j += 2) {
                    if(points[j] == points[j + 1]) continue; //skip if points were discarded earlier
                    Debug.DrawLine(points[j], points[j+1], lineColor);
                }
            }
        }
    }
    /// <summary>
    /// Rebuilds the mesh
    /// </summary>
    public void Refresh()
    {
        StartMeshInfo = null;
        EndMeshInfo = null;
        if (mMesh)
            mMesh.Clear();
        
        if (!mMesh || !Spline || !Spline.IsInitialized || Spline.Length==0) return;
        
        BuildCaps();
        Prepare();
        if (StartMesh && StartMeshInfo!=null && ToTF - FromTF != 0) {
            mVerts = new Vector3[getTotalVertexCount()];
            mUV = new Vector2[mVerts.Length];
            mTris = new int[getTotalTriIndexCount()];
            Extrude();

            mMesh.vertices = mVerts;
            mMesh.uv = mUV;
            mMesh.triangles = mTris;
            mMesh.RecalculateNormals();
            if (CalculateTangents)
                MeshHelper.CalculateMeshTangents(mMesh);
        }
    }