public CmdResult Execute(ExtendCmdData cmdData, ref string message) { var mainForm = cmdData.MainForm as Form; var viewForm = cmdData.ViewForm as IViewForm; if (viewForm == null) { return(CmdResult.Cancel); } var osgView = viewForm.View as ZfOsgViewCtrl; var osgObj = osgView.OsgObj; // 读取模型 string osgFileName; if (!DialogUtil.OpenOSG(out osgFileName)) { return(CmdResult.Cancel); } var node = OsgDB._.readNodeFile(osgFileName); var sequence = new Sequence(); for (int i = 0; i < 24 * 2; i++) { var matrixd = Matrixf.rotate((float)(Math.PI / 12 * 2) * i, new Vec3d(0, 0, 1)); var matrixTransform = new MatrixTransform(matrixd); matrixTransform.addChild(node); sequence.addChild(matrixTransform, i); } //设置帧动画持续的时间 sequence.setInterval(Sequence.LoopMode.LOOP, 0, -1); //设置播放的速度及重复的次数 sequence.setDuration(1.0f / 24, 10); sequence.setLoopMode(Sequence.LoopMode.LOOP); sequence.setMode(Sequence.SequenceMode.START); sequence.Name = "sequence"; osgObj.AddOrReplaceModel("Models", sequence); return(CmdResult.Succeed); }
/// <summary> /// Executes the specified command data. /// </summary> /// <param name="cmdData">The command data.</param> /// <param name="message">The message.</param> /// <returns>CmdResult.</returns> public CmdResult Execute(ExtendCmdData cmdData, ref string message) { var mainForm = cmdData.MainForm as Form; var viewForm = cmdData.ViewForm as IViewForm; if (viewForm == null) { return(CmdResult.Cancel); } var osgView = viewForm.View as ZfOsgViewCtrl; var osgObj = osgView.OsgObj; string[] osgFileNames; if (!DialogUtil.OpenOSG(out osgFileNames)) { return(CmdResult.Cancel); } foreach (var osgFileName in osgFileNames) { var node = OsgDB._.readNodeFile(osgFileName); // 读取模型 if (node.IsValid()) { // 使用[分组]-[模型],的方式组织模型树,模型Name为Key,即如果添加相同名称的模型,原来的模型会删除 node.Name = Path.GetFileNameWithoutExtension(osgFileName); osgObj.AddOrReplaceModel("Models", node); osgObj.SetView(ViewMode.ShowAll);//显示全图 } else { ZfMessageUtil.ShowError(string.Format("打开文件\"{0}\"失败!", osgFileName)); } } return(CmdResult.Succeed); }