public override void Import(ref MeshModel mesh)
        {
            using (BufferedStream sr = new BufferedStream(File.OpenRead(mesh.FilePath))) {
                int             byteCount;
                PlyObjectHeader headerObj = this.GetPlyObjectHeader(sr, out byteCount);

                sr.Position = byteCount;
                switch (headerObj.Format)
                {
                case PlyFormat.ascii:
                    this.ParserASCII(headerObj, sr, ref mesh);
                    break;

                case PlyFormat.binary_big_endian:
                    using (EndianessBinaryReader br = new EndianessBinaryReader(sr, Endianess.BigEndian)) {
                        this.ParserBinary(headerObj, br, ref mesh);
                    }
                    break;

                case PlyFormat.binary_little_endian:
                    using (EndianessBinaryReader br = new EndianessBinaryReader(sr, Endianess.LittleEndian)) {
                        this.ParserBinary(headerObj, br, ref mesh);
                    }
                    break;

                default:
                    throw new FormatException("Invalid File format!");
                    break;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Index
        /// </summary>
        /// <returns>return Index View</returns>
        public async Task <IActionResult> Index()
        {
            Client c = new Client(_appSettings.RestApiUrl, new HttpClient());

            MeshModel mm = new MeshModel();

            try
            {
                //Load scripts from API
                mm.Scripts = await c.GetScriptsAsync();

                //Load supported export formats from the api
                mm.SupportedExportFormats = await c.GetSupportedExportFormatsAsync();
            }
            catch (Exception e)
            {
                ViewBag.Error = $"API {_appSettings.RestApiUrl} currently not available.";
                ViewBag.Code  = "";

                return(View("Error"));
            }


            return(View(mm));
        }
Example #3
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            // Uses the IWindowsFormsEditorService to display a
            // drop-down UI in the Properties window.
            IWindowsFormsEditorService edSvc =
                (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (edSvc != null)
            {
                // Display an angle selection control and retrieve the value.
                //view.DefaultExt = "ply";
                this.view.Filter =
                    "All Know Files|*.ply;*.byu;*.obj;*.off;*.noff;*.cnoff|Ply Files|*.ply|Byu Files|*.byu|Wave Obj Files|*.obj|Off Files|*.off;*.noff;*.cnoff";
                if (this.view.ShowDialog() == DialogResult.OK)
                {
                    MeshModel model = context.Instance as MeshModel;
                    if (model != null)
                    {
                        model.FilePath = this.view.FileName;
                        LoadingMeshModelDialog modelDlg = new LoadingMeshModelDialog(model);
                        if (modelDlg.ShowDialog() == DialogResult.OK)
                        {
                            return(this.view.FileName);
                        }
                        else
                        {
                            model = new MeshModel();
                        }
                    }
                }
            }
            return("");
        }
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     // Uses the IWindowsFormsEditorService to display a
     // drop-down UI in the Properties window.
     IWindowsFormsEditorService edSvc =
         (IWindowsFormsEditorService) provider.GetService(typeof (IWindowsFormsEditorService));
     if (edSvc != null) {
         // Display an angle selection control and retrieve the value.
         //view.DefaultExt = "ply";
         this.view.Filter =
             "All Know Files|*.ply;*.byu;*.obj;*.off;*.noff;*.cnoff|Ply Files|*.ply|Byu Files|*.byu|Wave Obj Files|*.obj|Off Files|*.off;*.noff;*.cnoff";
         if (this.view.ShowDialog() == DialogResult.OK) {
             MeshModel model = context.Instance as MeshModel;
             if (model != null) {
                 model.FilePath = this.view.FileName;
                 LoadingMeshModelDialog modelDlg = new LoadingMeshModelDialog(model);
                 if (modelDlg.ShowDialog() == DialogResult.OK) {
                     return this.view.FileName;
                 } else {
                     model = new MeshModel();
                 }
             }
         }
     }
     return "";
 }
Example #5
0
 public bool TryGetMeshModel(long id, out MeshModel meshModel)
 {
     if (_meshDic is null)
     {
         meshModel = default;
         return(false);
     }
     return(_meshDic.TryGetValue(id, out meshModel));
 }
Example #6
0
    IEnumerator UpdateShapeState(float pix_to_world_scale)
    {
        foreach (var shape_go in shapes)
        {
            MeshModel.highlightShape(shape_go, MeshModel.PickingState.Normal, pix_to_world_scale);
            //CityLayoutMesh.updateShapeLines(tile_go, CityLayoutMesh.PickingState.Normal, pix_to_world_scale);
        }

        yield return(null);
    }
Example #7
0
 public static MeshGeometry3D ToSharpDxMeshGeometry3D(this MeshModel meshModel)
 {
     return(new MeshGeometry3D
     {
         Positions = new Vector3Collection(meshModel.Positions),
         Normals = new Vector3Collection(meshModel.Normals),
         TextureCoordinates = new Vector2Collection(meshModel.TextureCoordinates),
         TriangleIndices = new IntCollection(meshModel.TriangleIndices)
     });
 }
Example #8
0
        public BimGeometry3DModel(MeshModel geometry, MaterialModel material, Matrix3D transform)
        {
            Id        = Guid.NewGuid();
            Geometry  = geometry;
            Material  = material;
            Transform = transform.ToMatrix();
            Transform.Decompose(out scale, out rotation, out translation);

            //Add owner to material
            Material.Owners.Add(Id);
        }
 private void MeshModel_OnInitBuild(MeshModel mesh)
 {
     if (this.InvokeRequired)
     {
         this.Invoke(new Action(delegate {
             this.lblInfo.Text =
                 string.Format("Optimize Model for fast intersections... Wait.. ");
             this.lblTrianglesInfo.Text = "Triangles: " + mesh.Triangles.Length;
         }));
     }
 }
        public JsonResult List()
        {
            var mongo = new MongoHelper();

            // 获取所有类别
            var filter = Builders <BsonDocument> .Filter.Eq("Type", "Mesh");

            var categories = mongo.FindMany(Constant.CategoryCollectionName, filter);

            var meshes = mongo.FindAll(Constant.MeshCollectionName);

            var list = new List <MeshModel>();

            foreach (var i in meshes)
            {
                var categoryID   = "";
                var categoryName = "";

                if (i.Contains("Category") && !i["Category"].IsBsonNull && !string.IsNullOrEmpty(i["Category"].ToString()))
                {
                    var doc = categories.Where(n => n["_id"].ToString() == i["Category"].ToString()).FirstOrDefault();
                    if (doc != null)
                    {
                        categoryID   = doc["_id"].ToString();
                        categoryName = doc["Name"].ToString();
                    }
                }

                var info = new MeshModel
                {
                    ID           = i["_id"].ToString(),
                    Name         = i["Name"].ToString(),
                    CategoryID   = categoryID,
                    CategoryName = categoryName,
                    TotalPinYin  = i["TotalPinYin"].ToString(),
                    FirstPinYin  = i["FirstPinYin"].ToString(),
                    Type         = i["Type"].ToString(),
                    Url          = i["Url"].ToString(),
                    Thumbnail    = i.Contains("Thumbnail") && !i["Thumbnail"].IsBsonNull ? i["Thumbnail"].ToString() : null
                };

                list.Add(info);
            }

            list.Reverse();

            return(Json(new
            {
                Code = 200,
                Msg = "获取成功!",
                Data = list
            }));
        }
Example #11
0
        public ModelList(FbxNode objectsNode)
        {
            var meshDic = new BufferPooledDictionary <long, MeshModel>();
            var limbDic = new BufferPooledDictionary <long, LimbNode>();
            var nullDic = new BufferPooledDictionary <long, NullModel>();

            try {
                using var indexBuf = new ValueTypeRentMemory <int>(objectsNode.Children.Count, false);
                var modelCount = objectsNode.FindChildIndexAll(FbxConstStrings.Model(), indexBuf.AsSpan());
                foreach (var i in indexBuf.AsSpan(0, modelCount))
                {
                    var modelNode = objectsNode.Children[i];
                    var modelType = modelNode.Properties[2].AsString().ToModelType();

                    switch (modelType)
                    {
                    case ModelType.LimbNode: {
                        var limb = new LimbNode(modelNode);
                        limbDic.Add(limb.ID, limb);
                        break;
                    }

                    case ModelType.Mesh: {
                        var meshModel = new MeshModel(modelNode);
                        meshDic.Add(meshModel.ID, meshModel);
                        break;
                    }

                    case ModelType.Null: {
                        var nullModel = new NullModel(modelNode);
                        nullDic.Add(nullModel.ID, nullModel);
                        break;
                    }

                    case ModelType.Unknown:
                    default:
                        break;
                    }
                }
                _meshDic = meshDic;
                _limbDic = limbDic;
                _nullDic = nullDic;
            }
            catch {
                meshDic.Dispose();
                limbDic.Dispose();
                nullDic.Dispose();
                throw;
            }
        }
    void PickObjects(Vector3 position)
    {
        // prepare ray to cast based on the screen and mouse input
        Ray ray = Camera.main.ScreenPointToRay(position);

        RaycastHit hit;
        GameObject to_unpick = null;

        if (Physics.Raycast(ray, out hit))
        {
            // collided at hit.point

            // a new different object hit!
            if (picked != hit.collider.gameObject)
            {
                // unpick previoius object; can be null
                to_unpick = picked;

                // set new picked object!
                picked = hit.collider.gameObject;

                // highligh (select) picked object
                if (picked != selected)
                {
                    MeshModel.highlightShape(picked, MeshModel.PickingState.Picking, PixToWorld);
                }
            }
            //else { Debug.Log("**same object hit!"); }
        }
        else
        {
            // de-highlight object
            if (picked)
            {
                to_unpick = picked;
                picked    = null;
            }
            //else { Debug.Log("**nothing hit!"); }
        }

        if (to_unpick)
        {
            if (to_unpick != selected)
            {
                MeshModel.highlightShape(to_unpick, MeshModel.PickingState.Normal, PixToWorld);
            }

            to_unpick = null;
        }
    }
        public LoadingMeshModelDialog(MeshModel meshModel)
        {
            this.InitializeComponent();
            this.DialogResult = DialogResult.Cancel;

            this.DialogResult = DialogResult.Cancel;
            this.meshModel = meshModel;
            if (meshModel.FilePath != null && File.Exists(meshModel.FilePath)) {
                MeshModelLoader.OnElementLoaded += MeshModel_OnElementLoaded;
                MeshModelLoader.OnInitBuild += this.MeshModel_OnInitBuild;
                MeshModelLoader.OnEndBuild += this.MeshModel_OnEndBuild;
            } else {
                this.Close();
            }
        }
    void HandleMouse()
    {
        // On mouse down, capture it's position.
        // Otherwise, if the mouse is still down, pan the camera.
        if (Input.GetMouseButtonDown(PAN_BUTTON))
        {
            lastPanPosition = Input.mousePosition;
        }
        else if (Input.GetMouseButton(PAN_BUTTON))
        {
            PanCamera(Input.mousePosition);
        }
        else if (Input.GetMouseButtonDown(SELECT_BUTTON))
        {
            if (picked)
            {
                // de-select any existing object
                if (selected)
                {
                    MeshModel.highlightShape(selected, MeshModel.PickingState.Normal, PixToWorld);
                }

                // select the curently picked object
                selected = picked;
                MeshModel.highlightShape(selected, MeshModel.PickingState.Selected, PixToWorld);

                // TODO do something after the object has been selected!
                Debug.Log("selected object with properties: " + selected.GetComponent <ShapeProperties>().ToString());
            }
            else
            {
                if (selected)
                {
                    // deselect object
                    MeshModel.highlightShape(selected, MeshModel.PickingState.Normal, PixToWorld);
                    selected = null;
                }
            }
        }

        // Check for scrolling to zoom the camera
        float scroll = Input.GetAxis("Mouse ScrollWheel");

        ZoomCamera(scroll, ZoomSpeedMouse);

        // pick object all the time!
        PickObjects(Input.mousePosition);
    }
        public LoadingMeshModelDialog(MeshModel meshModel)
        {
            this.InitializeComponent();
            this.DialogResult = DialogResult.Cancel;

            this.DialogResult = DialogResult.Cancel;
            this.meshModel    = meshModel;
            if (meshModel.FilePath != null && File.Exists(meshModel.FilePath))
            {
                MeshModelLoader.OnElementLoaded += MeshModel_OnElementLoaded;
                MeshModelLoader.OnInitBuild     += this.MeshModel_OnInitBuild;
                MeshModelLoader.OnEndBuild      += this.MeshModel_OnEndBuild;
            }
            else
            {
                this.Close();
            }
        }
Example #16
0
    IEnumerator AddGeoJsonGeometry()
    {
        // 1) get serialised textual geometry data (e.g. read from file)
        var seralised_geometry = InputModel.GetSerialisedGeometry();

        // 2) read serialised geometry (e.g. GeoJson) into list/collection of Vector2[]
        var polygon_dataset = GeoJsonModel.GetPolygonDatasetFromSerialised(seralised_geometry, BOX_RADIUS);

        yield return(null);

        // 3) create GameObjects with meshes from each polygon
        //TODO single gameobject/mesh here...??
        shapes = new List <GameObject>(polygon_dataset.Count);
        var       yield_counter   = 0;
        const int UNITS_PER_YIELD = 64;

        foreach (var polygon_data in polygon_dataset)
        {
            var shape = new GameObject();

            // set shape properties
            var shape_properties = shape.AddComponent <ShapeProperties>();
            shape_properties.PropertiesDict = polygon_data.Item2;
            // can get the name ONLY after dictionary is set
            shape.name = shape_properties.Name;

            // create gameobject including the mesh
            MeshModel.createMeshFromPolygonData(shape, polygon_data.Item1, enable_lighting);

            shape.transform.parent = transform;
            shapes.Add(shape);

            ++yield_counter;
            if (yield_counter >= UNITS_PER_YIELD)
            {
                yield_counter = 0;
                yield return(null);
            }
        }


        yield return(UpdateShapeState(cam_controller.PixToWorld));
    }
Example #17
0
    void AddSquareTest()
    {
        // get data
        var r   = BOX_RADIUS * 0.5f;
        var vxs = new Vector2[] { new Vector3(0, 0), new Vector3(0, r), new Vector3(r, r), new Vector3(r, 0) };


        var go = new GameObject("<test_square>");

        // create mesh
        MeshModel.createMeshFromPolygonData(go, new List <Vector2[]> {
            vxs
        }, enable_lighting);

        // add locally
        shapes = new List <GameObject>(1);
        go.transform.parent = transform;
        shapes.Add(go);
    }
Example #18
0
        protected void ProcessNormalsPerVertex(int[] indices, ref MeshModel mesh, int verticesCount)
        {
            Vector3D[] normalsPerVertex = new Vector3D[verticesCount];
            int        ptr = 0;

            for (int i = 0; i < mesh.Triangles.Length; i++)
            {
                normalsPerVertex[indices[ptr++]] += mesh.Triangles[i].Normal;
                normalsPerVertex[indices[ptr++]] += mesh.Triangles[i].Normal;
                normalsPerVertex[indices[ptr++]] += mesh.Triangles[i].Normal;

                int percent = (int)(((float)i / mesh.Triangles.Length) * 100.0f);


                if ((percent % 20) == 0)
                {
                    this.OnElementLoaded(percent, ElementMesh.VertexNormal);
                }
            }
            ptr = 0;
            for (int i = 0; i < mesh.Triangles.Length; i++)
            {
                mesh.Triangles[i].Vertex1.Normal = normalsPerVertex[indices[ptr++]];
                mesh.Triangles[i].Vertex1.Normal.Normalize();

                mesh.Triangles[i].Vertex2.Normal = normalsPerVertex[indices[ptr++]];
                mesh.Triangles[i].Vertex2.Normal.Normalize();

                mesh.Triangles[i].Vertex3.Normal = normalsPerVertex[indices[ptr++]];
                mesh.Triangles[i].Vertex3.Normal.Normalize();

                int percent = (int)(((float)i / mesh.Triangles.Length) * 100.0f);
                if ((percent % 20) == 0)
                {
                    this.OnElementLoaded(percent / 2 + 50, ElementMesh.VertexNormal);
                }
            }
            normalsPerVertex = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Example #19
0
    public IEnumerator UpdateLines()
    {
        float pix_to_world_scale = cam_controller.PixToWorld;

        foreach (var shape_go in shapes)
        {
            if (shape_go == cam_controller.Selected)
            {
                MeshModel.updateShapeLines(shape_go, MeshModel.PickingState.Selected, pix_to_world_scale);
            }
            else if (shape_go == cam_controller.Picked)
            {
                MeshModel.updateShapeLines(shape_go, MeshModel.PickingState.Picking, pix_to_world_scale);
            }
            else
            {
                MeshModel.updateShapeLines(shape_go, MeshModel.PickingState.Normal, pix_to_world_scale);
            }
        }

        yield return(null);
    }
Example #20
0
        BlitzObject readObject(BlitzObject parent)
        {
            BlitzObject obj = null;

            string name = readString();

            float[] pos, scl, rot;
            pos = readFloatArray(3);
            scl = readFloatArray(3);
            rot = readFloatArray(4);

            Animation keys = new Animation();
            int       anim_len = 0;
            MeshModel mesh = null;
            int       mesh_flags, mesh_brush;

            while (chunkSize() > 0)
            {
                switch (readChunk())
                {
                case "MESH":
                    obj        = mesh = MeshLoader.CreateMesh();
                    mesh_brush = readInt();
                    //mesh_flags=readMesh();
                    break;

                case "BONE":
                    obj = readBone();
                    break;

                case "KEYS":
                    readKeys(ref keys);
                    break;

                case "ANIM":
                    readInt();
                    anim_len = readInt();
                    readFloat();
                    break;

                case "NODE":
                    if (obj == null)
                    {
                        obj = new MeshModel();
                    }
                    readObject(obj);
                    break;
                }
                exitChunk();
            }

            if (obj == null)
            {
                obj = new MeshModel();
            }

            obj.Name          = name;
            obj.LocalPosition = (new Vector(pos[0], pos[1], pos[2]));
            obj.LocalScale    = (new Vector(scl[0], scl[1], scl[2]));
            obj.LocalRotation = (new Quat(rot[0], new Vector(rot[1], rot[2], rot[3])));
            obj.setAnimation(keys);

            if (mesh != null)
            {
                //MeshLoader::endMesh(mesh);
                //if (!(mesh_flags & 1)) mesh->updateNormals();
                //if (mesh_brush != -1) mesh->setBrush(brushes[mesh_brush]);
            }

            if (mesh != null && mesh.Bones.Any())
            {
                mesh.Bones.Insert(0, mesh);
                mesh.setAnimator(new Animator(mesh.Bones, anim_len));
            }
            else if (anim_len > 0)
            {
                obj.setAnimator(new Animator(obj, anim_len));
            }
            if (parent != null)
            {
                obj.Parent = (parent);
            }
            LoadedObjects.Add(obj);
            return(obj);
        }
Example #21
0
    /// <summary>
    /// このシーンがコントロールにセットされたときに呼び出されます。
    /// </summary>
    /// <param name="e"></param>
    protected override void OnSetToRenderingControl(EventArgs e)
    {
        //この時点でthis.Contextプロパティから
        //レンダリングコンテキストが取得できるようになるので、
        //ここでOpenGLの初期化などを行うことを推奨します。

        this.Context.MakeCurrent();

        ///////////////////////////////////

        renderingParams = new EmptyRenderingParams();

        ///////////////////////////////////
        // カメラ、ライトの初期化、設定
        cam = new Camera(0f, 0f, 600f,
                          0f, 0f, 0f,
                          0f, 1f, 0f);
        cam.fovy = 60f;
        cam.zFar = 10000f;
        cam.zNear = 0.1f;

        light0 = new Light(LightName.Light0, LightType.DirectionalLight,
                            0f, 0f, 7f,
                            -0.3f, -0.3f, -1f);

        this.glyphDictionaly = new BitmapGlyphDictionary(this.Context.HDC);

        //AntiAliasFormat.Noneを指定した場合、色は何を指定しても無視される。
        this.textFont = new BitmapGlyphFont(this.RenderingControl.Font, AntiAliasFormat.None, Color.Empty);

        ///////////////////////////////////
        //初期画面で表示しておくメッセージを作成

        //TextModel startMessage = new TextModel("Simple MQO viewer",
        //                                        this.RenderingControl.Font, 50f, 5f, this.Context.HDC,
        //                                        TextLayout.Center, Material.GetWhiteDefaultMaterial());

        //startMessage.AddText("\n\n右ダブルクリックでメニューを表示します。",
        //                      this.RenderingControl.Font, 20f, 10f, 4, new Material("", Color.Gray, 0.6f));

        //startMessage.Layout();
        ////テキストの位置を中央へ移動
        //startMessage.Position.TranslateOnLocal(Vector.GetScaled(startMessage.AABB.center, -1f));

        //this.AddMqo(startMessage);

        ///////////////////////////////////

        //画面クリア時に使用する色(背景色)を指定。
        gl.ClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);

        gl.Enable(EnableCap.DepthTest);
        gl.DepthFunc(DepthFunction.Lequal);

        gl.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);

        //陰面消去設定
        gl.Enable(EnableCap.CullFace);
        gl.CullFace(CullFaceMode.Back);

        //アルファブレンディング設定
        gl.Enable(EnableCap.Blend);
        gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

        //ライティングの設定
        gl.LightModel(LightModelParameter.LightModelLocalViewer, 1);    //ライティングの計算を正確に行う。

        gl.LightModel(LightModelParameter.LightModelColorControl, (int)LightModelColorControl.SeparateSpecularColor);

        //プロジェクション行列の設定
        SetProjection();

        try
        {
            string fileName = Application.StartupPath + @"\data\default.mqo";
            MeshModel mqo = new MeshModel(fileName, Path.GetFileNameWithoutExtension(fileName),
                                           1f, true, new MeshModel.MQOLoadingParams());

            this.AddMqo(mqo);
            this.cam.Zoom(0.6f);
            this.RenderingControl.Invalidate();
        }
        catch (Exception ex)
        {
            string errMessage = ex.Message;
            if (ex.InnerException != null)
            {
                errMessage += Environment.NewLine + ex.InnerException.Message;
            }

            MessageBox.Show(errMessage);
        }
    }
Example #22
0
 public void AddGeometry(MeshModel geometry, MaterialModel material, Matrix3D transform)
 {
     Geometries.Add(new BimGeometry3DModel(geometry, material, transform));
 }
 private void MeshModel_OnInitBuild(MeshModel mesh)
 {
     if (this.InvokeRequired) {
         this.Invoke(new Action(delegate {
                                    this.lblInfo.Text =
                                        string.Format("Optimize Model for fast intersections... Wait.. ");
                                    this.lblTrianglesInfo.Text = "Triangles: " + mesh.Triangles.Length;
                                }));
     }
 }
Example #24
0
        public JsonResult List()
        {
            var mongo = new MongoHelper();

            // 获取所有类别
            var filter = Builders <BsonDocument> .Filter.Eq("Type", "Mesh");

            var categories = mongo.FindMany(Constant.CategoryCollectionName, filter).ToList();

            var docs = new List <BsonDocument>();

            if (ConfigHelper.EnableAuthority)
            {
                var user = UserHelper.GetCurrentUser();

                if (user != null)
                {
                    var filter1 = Builders <BsonDocument> .Filter.Eq("UserID", user.ID);

                    if (user.Name == "Administrator")
                    {
                        var filter2 = Builders <BsonDocument> .Filter.Exists("UserID");

                        var filter3 = Builders <BsonDocument> .Filter.Not(filter2);

                        filter1 = Builders <BsonDocument> .Filter.Or(filter1, filter3);
                    }
                    docs = mongo.FindMany(Constant.MeshCollectionName, filter1).SortByDescending(n => n["_id"]).ToList();
                }
            }
            else
            {
                docs = mongo.FindAll(Constant.MeshCollectionName).SortByDescending(n => n["_id"]).ToList();
            }

            var list = new List <MeshModel>();

            foreach (var i in docs)
            {
                var categoryID   = "";
                var categoryName = "";

                if (i.Contains("Category") && !i["Category"].IsBsonNull && !string.IsNullOrEmpty(i["Category"].ToString()))
                {
                    var doc = categories.Where(n => n["_id"].ToString() == i["Category"].ToString()).FirstOrDefault();
                    if (doc != null)
                    {
                        categoryID   = doc["_id"].ToString();
                        categoryName = doc["Name"].ToString();
                    }
                }

                var info = new MeshModel
                {
                    ID           = i["_id"].ToString(),
                    Name         = i["Name"].ToString(),
                    CategoryID   = categoryID,
                    CategoryName = categoryName,
                    TotalPinYin  = i["TotalPinYin"].ToString(),
                    FirstPinYin  = i["FirstPinYin"].ToString(),
                    Type         = i["Type"].ToString(),
                    Url          = i["Url"].ToString(),
                    Thumbnail    = i.Contains("Thumbnail") && !i["Thumbnail"].IsBsonNull ? i["Thumbnail"].ToString() : null
                };

                list.Add(info);
            }

            return(Json(new
            {
                Code = 200,
                Msg = "Get Successfully!",
                Data = list
            }));
        }
 public abstract void Import(ref MeshModel mesh);
Example #26
0
 public MeshModel CreateMesh() => CurrentMesh = AddMesh(new MeshModel());
Example #27
0
        private MeshModel ParserBinary(PlyObjectHeader header, BinaryReader ebr, ref MeshModel mesh)
        {
            //MeshModel mesh = new MeshModel(header.Elements["face"].Count * 3, header.Elements["vertex"].Count);
            //for (int i = 0; i < header.Elements.Count; i++)
            //{
            //    ElementDescription element = header.Elements[i];
            //    for (int e = 0; e < element.Count; e++)
            //    {
            //        for (int p = 0; p < element.Properties.Count; p++)
            //        {
            //            PropertyDescription property = element.Properties[p];

            //            if (property.IsList)
            //            {
            //                int listCount = 0;
            //                if (property.CountType == PropertyType.uchar || property.CountType == PropertyType.uint8)
            //                {
            //                    listCount = ebr.ReadByte();
            //                }
            //                else
            //                {
            //                    throw new ArgumentException("The type expected for List Count is 'uchar'. Type in file: '" + property.CountType + "'");
            //                }

            //                if (property.TypeOfList == PropertyType.@int || property.TypeOfList == PropertyType.int32)
            //                {
            //                    if (element.Name == "face")
            //                    {
            //                        for (int j = 0; j < listCount; j += 3)
            //                        {
            //                            mesh.Indices[e] = ebr.ReadInt32();
            //                            mesh.Indices[e + 1] = ebr.ReadInt32();
            //                            mesh.Indices[e + 2] = ebr.ReadInt32();

            //                            int percent = (int)(((float)e / mesh.Indices.Length) * 100.0f);
            //                            if ((percent % 20) == 0)
            //                            {
            //                                this.OnElementLoaded(percent, ElementMesh.VextexIndice);
            //                            }
            //                        }
            //                    }
            //                    else if (element.Name == "vertex")
            //                    {
            //                        #region Ignore other properties for vertex
            //                        for (int j = 0; j < listCount; j += 3)
            //                        {
            //                            ebr.ReadInt32();
            //                            ebr.ReadInt32();
            //                            ebr.ReadInt32();
            //                        }
            //                        #endregion
            //                    }
            //                }
            //                else
            //                {
            //                    throw new ArgumentException("The type expected for List elements is 'int'. Type in file: '" + property.TypeOfList + "'");
            //                }
            //            }
            //            else
            //            {
            //                if (element.Name == "face")
            //                {
            //                    #region Ignore other properties for face
            //                    switch (property.Type)
            //                    {
            //                        case PropertyType.@char:
            //                        case PropertyType.int8:
            //                            ebr.ReadSByte();
            //                            break;
            //                        case PropertyType.uchar:
            //                        case PropertyType.uint8:
            //                            ebr.ReadByte();
            //                            break;
            //                        case PropertyType.@short:
            //                        case PropertyType.int16:
            //                            ebr.ReadInt16();
            //                            break;
            //                        case PropertyType.@ushort:
            //                        case PropertyType.uint16:
            //                            ebr.ReadUInt16();
            //                            break;
            //                        case PropertyType.@int:
            //                        case PropertyType.int32:
            //                            ebr.ReadInt32();
            //                            break;
            //                        case PropertyType.@uint:
            //                        case PropertyType.uint32:
            //                            ebr.ReadUInt32();
            //                            break;
            //                        case PropertyType.@float:
            //                        case PropertyType.float32:
            //                            ebr.ReadSingle();
            //                            break;
            //                        case PropertyType.@double:
            //                        case PropertyType.float64:
            //                            ebr.ReadDouble();
            //                            break;
            //                        default:
            //                            break;
            //                    }
            //                    #endregion
            //                }
            //                else if (element.Name == "vertex")
            //                {

            //                    switch (property.Type)
            //                    {
            //                        case PropertyType.@char:
            //                        case PropertyType.int8:
            //                            ebr.ReadSByte();
            //                            break;
            //                        case PropertyType.uchar:
            //                        case PropertyType.uint8:
            //                            ebr.ReadByte();
            //                            break;
            //                        case PropertyType.@short:
            //                        case PropertyType.int16:
            //                            ebr.ReadInt16();
            //                            break;
            //                        case PropertyType.@ushort:
            //                        case PropertyType.uint16:
            //                            ebr.ReadUInt16();
            //                            break;
            //                        case PropertyType.@int:
            //                        case PropertyType.int32:
            //                            ebr.ReadInt32();
            //                            break;
            //                        case PropertyType.@uint:
            //                        case PropertyType.uint32:
            //                            ebr.ReadUInt32();
            //                            break;
            //                        case PropertyType.@float:
            //                        case PropertyType.float32:
            //                            mesh.Vertices[e].Position.X = ebr.ReadSingle();
            //                            mesh.Vertices[e].Position.Y = ebr.ReadSingle();
            //                            mesh.Vertices[e].Position.Z = ebr.ReadSingle();
            //                            p += 2;
            //                            //Adjusting BoundBox...
            //                            mesh.BoundBox.Include(mesh.Vertices[e].Position);
            //                            //Reporting progress
            //                            int percent = (int)(((float)e / mesh.Vertices.Length) * 100.0f);
            //                            if ((percent % 20) == 0)
            //                            {
            //                                this.OnElementLoaded(percent, ElementMesh.Vertex);
            //                            }
            //                            break;
            //                        case PropertyType.@double:
            //                        case PropertyType.float64:
            //                            ebr.ReadDouble();
            //                            break;
            //                        default:
            //                            break;
            //                    }
            //                }
            //            }
            //        }
            //    }
            //}
            //GC.Collect();
            //ForceGenerateNormals(mesh);
            //return mesh;
            return(null);
        }
Example #28
0
        private void ParserASCII(PlyObjectHeader header, Stream sr, ref MeshModel mesh)
        {
            MeshVertex[]     vertices = new MeshVertex[header.Elements["vertex"].Count];
            int[]            indices  = new int[header.Elements["face"].Count * 3];
            NumberFormatInfo nfi      = new NumberFormatInfo();

            nfi.NumberDecimalSeparator = ".";
            nfi.NumberGroupSeparator   = ",";
            //Initialize bound box calculation
            String[] str;
            //for number of vertices readed in header do...
            BoundBox boundBox = new BoundBox();

            for (int i = 0; i < vertices.Length; i++)
            {
                str = sr.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);


                vertices[i].Position = new Point3D(float.Parse(str[0], nfi), float.Parse(str[1], nfi),
                                                   float.Parse(str[2], nfi));
                //Adjusting BoundBox...
                boundBox.Include(vertices[i].Position);
                //Reporting progress
                int percent = (int)(((float)i / vertices.Length) * 100.0f);
                if ((percent % 20) == 0)
                {
                    this.OnElementLoaded(percent, ElementMesh.Vertex);
                }
            }

            //MeshModel mesh = new MeshModel(header.Elements["face"].Count);
            mesh.Triangles = new MeshTriangle[header.Elements["face"].Count];
            mesh.BoundBox  = boundBox;

            for (int i = 0, ptr = 0; i < mesh.Triangles.Length; i++)
            {
                str = sr.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                indices[ptr++]            = Int32.Parse(str[1], nfi);
                mesh.Triangles[i].Vertex1 = vertices[indices[ptr - 1]];
                indices[ptr++]            = Int32.Parse(str[2], nfi);
                mesh.Triangles[i].Vertex2 = vertices[indices[ptr - 1]];
                indices[ptr++]            = Int32.Parse(str[3], nfi);
                mesh.Triangles[i].Vertex3 = vertices[indices[ptr - 1]];

                int percent = (int)(((float)i / indices.Length) * 100.0f);
                if ((percent % 20) == 0)
                {
                    this.OnElementLoaded(percent, ElementMesh.VextexIndice);
                }
            }
            int verticesCount = vertices.Length;

            vertices = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
            ProcessNormalsPerVertex(indices, ref mesh, verticesCount);
            indices = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Example #29
0
 public MeshModel AddMesh(MeshModel model)
 {
     _meshes.Add(model);
     return(model);
 }
Example #30
0
    private void AddMqo(MeshModel mqo)
    {
        this.models.Add(mqo);

        //追加したMQOを削除するためのメニューを作成・追加する。
        ToolStripMenuItem menu = new ToolStripMenuItem();
        menu.Text = mqo.Name;
        menu.Tag = mqo;

        //メニューがクリックされると、
        //MQOとこのメニュー自身が削除されるように仕込んでおく。
        menu.Click += delegate(object sender, EventArgs e)
        {
            ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
            MeshModel m = (MeshModel)menuItem.Tag;

            this.models.Remove(m);
            m.Dispose();

            //this.menuRemove.DropDownItems.Remove(menu);
            menu.Dispose();

            if (this.pickedModel == m)
                this.pickedModel = null;
        };

        //this.menuRemove.DropDownItems.Add(menu);
    }
Example #31
0
    void OpenMqoFile(object sender, EventArgs e)
    {
        OpenFileDialog dialog = new OpenFileDialog();
        dialog.Title = "Open MQO File";
        dialog.Filter = "MQO (*.mqo)|*.mqo";

        if (dialog.ShowDialog() == DialogResult.OK)
        {
            try
            {
                MeshModel mqo = new MeshModel(dialog.FileName, System.IO.Path.GetFileNameWithoutExtension(dialog.FileName),
                                               1f, true, new MeshModel.MQOLoadingParams());

                this.AddMqo(mqo);

                this.RenderingControl.Invalidate();
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += Environment.NewLine + ex.InnerException.Message;
                }

                MessageBox.Show(errMessage);
            }
        }
    }
 public abstract void Import(ref MeshModel mesh);