static void Main(string[] args) { try { ConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; ci.Database = "../XXX.FDB"; IDataSource dataSouce = new DataSourceFactory().OpenDataSource(ci); string[] names = (string[])dataSouce.GetFeatureDatasetNames(); IFeatureDataSet fds = dataSouce.OpenFeatureDataset(names[0]); IResourceManager resManager = fds as IResourceManager; //没有锁时这句会报错 IEnumResName myEnumNames = resManager.GetModelNames(); while (myEnumNames.MoveNext()) { string modelName = myEnumNames.Current; IModel myModel = resManager.GetModel(modelName); if (myModel != null) { for (int i = 0; i < myModel.GroupCount; i++) { IDrawGroup myGroup = myModel.GetGroup(i); for (int j = 0; j < myGroup.PrimitiveCount; j++) { IDrawPrimitive myPv = myGroup.GetPrimitive(j); IDrawMaterial myDM = myPv.Material; if (myDM != null) { myDM.EnableLight = false; } myPv.Material = myDM; myGroup.SetPrimitive(j, myPv); } myModel.SetGroup(i, myGroup); } resManager.UpdateModel(modelName, myModel); } } //手动释放COM对象 Marshal.ReleaseComObject(fds); MessageBox.Show("完成!"); } catch { MessageBox.Show("必须插入加密锁!必须安装CityMaker Builder 7.1"); } }
// 新建空模型 public bool NewEmptyModel(int[] index, RenderType renderType, object renderInfo, out IModel model) { model = null; if (index.Length == 0) { return(false); } string[] strArray = null; uint[] numArray = null; if (renderType == RenderType.Texture) { strArray = renderInfo as string[]; if ((strArray == null) || (strArray.Length < index.Length)) { return(false); } } else { numArray = renderInfo as uint[]; if ((numArray == null) || (numArray.Length < index.Length)) { return(false); } } IDrawGroup drawGroup = null; IDrawPrimitive primitive = null; IDrawMaterial material = null; IResourceFactory factory = new ResourceFactoryClass(); model = factory.CreateModel(); model.SwitchSize = SwitchSize; drawGroup = new DrawGroupClass(); for (int i = 0; i < index.Length; i++) { material = new DrawMaterialClass { CullMode = this._cullModel, EnableBlend = false, EnableLight = true, SpecularColor = this._specularColor, WrapModeS = gviTextureWrapMode.gviTextureWrapRepeat, WrapModeT = gviTextureWrapMode.gviTextureWrapRepeat }; primitive = new DrawPrimitiveClass { PrimitiveMode = gviPrimitiveMode.gviPrimitiveModeTriangleList, PrimitiveType = gviPrimitiveType.gviPrimitiveNormal, VertexArray = new FloatArrayClass(), IndexArray = new UInt16ArrayClass(), NormalArray = new FloatArrayClass() }; if (renderType == RenderType.Texture) { material.TextureName = strArray[index[i]]; primitive.TexcoordArray = new FloatArrayClass(); material.DiffuseColor = uint.MaxValue; } else { material.TextureName = ""; primitive.TexcoordArray = null; material.DiffuseColor = numArray[index[i]]; } primitive.Material = material; drawGroup.AddPrimitive(primitive); } model.AddGroup(drawGroup); return(true); }