Пример #1
0
		///<summary>If using DirectX, the facesDirectX IndexBuffer variable must be instantiated in a subsequent call to PrepareForDirectX().</summary>
		public ToothGroup Copy() {
			ToothGroup tg=new ToothGroup();
			tg.Visible=this.Visible;
			tg.PaintColor=this.PaintColor;
			tg.GroupType=this.GroupType;
			tg.Faces=new List<Face>();
			for(int i=0;i<this.Faces.Count;i++) {
				tg.Faces.Add(this.Faces[i].Copy());
			}
			return tg;
		}
Пример #2
0
        ///<summary>If using DirectX, the facesDirectX IndexBuffer variable must be instantiated in a subsequent call to PrepareForDirectX().</summary>
        public ToothGroup Copy()
        {
            ToothGroup tg = new ToothGroup();

            tg.Visible    = this.Visible;
            tg.PaintColor = this.PaintColor;
            tg.GroupType  = this.GroupType;
            tg.Faces      = new List <Face>();
            for (int i = 0; i < this.Faces.Count; i++)
            {
                tg.Faces.Add(this.Faces[i].Copy());
            }
            return(tg);
        }
Пример #3
0
		///<summary>Should only be run on startup for efficiency.</summary>
		private void ImportObj() {
			byte[] buffer=null;
			if(toothID=="1" || toothID=="16") {
				buffer=Properties.Resources.tooth1;
			}
			else if(toothID=="2" || toothID=="15") {
				buffer=Properties.Resources.tooth2;
			}
			else if(toothID=="3" || toothID=="14") {
				//file+="3.obj";
				buffer=Properties.Resources.tooth3;
			}
			else if(toothID=="4" || toothID=="13") {
				buffer=Properties.Resources.tooth4;
			}
			else if(toothID=="5" || toothID=="12") {
				buffer=Properties.Resources.tooth5;
			}
			else if(toothID=="6" || toothID=="11") {
				buffer=Properties.Resources.tooth6;
			}
			else if(toothID=="7" ||toothID=="10") {
				buffer=Properties.Resources.tooth7;
			}
			else if(toothID=="8" || toothID=="9") {
				buffer=Properties.Resources.tooth8;
			}
			else if(toothID=="17" || toothID=="32") {
				buffer=Properties.Resources.tooth32;
			}
			else if(toothID=="18" || toothID=="31") {
				buffer=Properties.Resources.tooth31;
			}
			else if(toothID=="19" || toothID=="30") {
				buffer=Properties.Resources.tooth30;
			}
			else if(toothID=="20" || toothID=="29") {
				buffer=Properties.Resources.tooth29;
			}
			else if(toothID=="21" || toothID=="28") {
				buffer=Properties.Resources.tooth28;
			}
			else if(toothID=="22" || toothID=="27") {
				buffer=Properties.Resources.tooth27;
			}
			else if(toothID=="23" || toothID=="24" || toothID=="25" ||toothID=="26") {
				buffer=Properties.Resources.tooth25;
			}
			else if(toothID=="A" || toothID=="J") {
				buffer=Properties.Resources.toothA;
			}
			else if(toothID=="B" || toothID=="I") {
				buffer=Properties.Resources.toothB;
			}
			else if(toothID=="C" || toothID=="H") {
				buffer=Properties.Resources.toothC;
			}
			else if(toothID=="D" || toothID=="G") {
				buffer=Properties.Resources.toothD;
			}
			else if(toothID=="E" || toothID=="F") {
				buffer=Properties.Resources.toothE;
			}
			else if(toothID=="P" || toothID=="O" || toothID=="Q" || toothID=="N") {
				buffer=Properties.Resources.toothP;
			}
			else if(toothID=="R" || toothID=="M") {
				buffer=Properties.Resources.toothR;
			}
			else if(toothID=="S" || toothID=="L") {
				buffer=Properties.Resources.toothS;
			}
			else if(toothID=="T" || toothID=="K") {
				buffer=Properties.Resources.toothT;
			}
			else if(toothID=="implant"){
				buffer=Properties.Resources.implant;
			}
			bool flipHorizontally=false;
			if(toothID!="implant" && IdToInt(toothID)>=9 && IdToInt(toothID)<=24) {
				flipHorizontally=true;
			}
			//There will not necessarily be the same number of vertices as normals.
			//But as they get paired up later, we will create a 1:1 relationship.
			List<Vertex3f> verts=new List<Vertex3f>();
			List<Vertex3f> norms=new List<Vertex3f>();
			Groups=new List<ToothGroup>();
			//ArrayList ALf=new ArrayList();//faces always part of a group
			List<Face> faces=new List<Face>();
			MemoryStream stream=new MemoryStream(buffer);
			using(StreamReader sr = new StreamReader(stream)){
				String line;
				Vertex3f vertex;
				string[] items;
				string[] subitems;
				Face face;
				ToothGroup group=null;
				while((line = sr.ReadLine()) != null) {
					if(line.StartsWith("#")//comment
						|| line.StartsWith("mtllib")//material library.  We build our own.
						|| line.StartsWith("usemtl")//use material
						|| line.StartsWith("o")) {//object. There's only one object 
						continue;
					}
					if(line.StartsWith("v ")) {//vertex
						items=line.Split(new char[] { ' ' });
						vertex=new Vertex3f();//float[3];
						if(flipHorizontally) {
							vertex.X=-Convert.ToSingle(items[1],CultureInfo.InvariantCulture);
						}
						else {
							vertex.X=Convert.ToSingle(items[1],CultureInfo.InvariantCulture);
						}
						vertex.Y=Convert.ToSingle(items[2],CultureInfo.InvariantCulture);
						vertex.Z=Convert.ToSingle(items[3],CultureInfo.InvariantCulture);
						verts.Add(vertex);
						continue;
					}
					if(line.StartsWith("vn")) {//vertex normal
						items=line.Split(new char[] { ' ' });
						vertex=new Vertex3f();//new float[3];
						if(flipHorizontally) {
							vertex.X=-Convert.ToSingle(items[1],CultureInfo.InvariantCulture);
						}
						else {
							vertex.X=Convert.ToSingle(items[1],CultureInfo.InvariantCulture);
						}
						vertex.Y=Convert.ToSingle(items[2],CultureInfo.InvariantCulture);
						vertex.Z=Convert.ToSingle(items[3],CultureInfo.InvariantCulture);
						norms.Add(vertex);
						continue;
					}
					if(line.StartsWith("g")) {//group
						if(group != null) {
							//move all faces into the existing group
							group.Faces=new List<Face>(faces);
							//move the existing group into the AL
							Groups.Add(group);
						}
						//start a new group to which all subsequent faces will be attached.
						group=new ToothGroup();
						faces=new List<Face>();
						//group.PaintColor=Color.FromArgb(255,255,253,209);//default to enamel
						switch(line) {
							default:
								group.GroupType=ToothGroupType.None;
								break;
							case "g cube1_Cementum":
								group.GroupType=ToothGroupType.Cementum;
								break;
							case "g cube1_Enamel2":
								group.GroupType=ToothGroupType.Enamel;
								break;
							case "g cube1_M":
								group.GroupType=ToothGroupType.M;
								break;
							case "g cube1_D":
								group.GroupType=ToothGroupType.D;
								break;
							case "g cube1_F":
								group.GroupType=ToothGroupType.F;
								break;
							case "g cube1_I":
								group.GroupType=ToothGroupType.I;
								break;
							case "g cube1_L":
								group.GroupType=ToothGroupType.L;
								break;
							case "g cube1_V":
								group.GroupType=ToothGroupType.V;
								break;
							case "g cube1_B":
								group.GroupType=ToothGroupType.B;
								break;
							case "g cube1_O":
								group.GroupType=ToothGroupType.O;
								break;
							case "g cube1_Canals":
								group.GroupType=ToothGroupType.Canals;
								break;
							case "g cube1_Buildup":
								group.GroupType=ToothGroupType.Buildup;
								break;
							case "g cube1_Implant":
								group.GroupType=ToothGroupType.Implant;
								break;
							case "g cube1_EnamelF":
								group.GroupType=ToothGroupType.EnamelF;
								break;
							case "g cube1_DF":
								group.GroupType=ToothGroupType.DF;
								break;
							case "g cube1_MF":
								group.GroupType=ToothGroupType.MF;
								break;
							case "g cube1_IF":
								group.GroupType=ToothGroupType.IF;
								break;
						}
					}
					if(line.StartsWith("f")) {//face. Usually 4 vertices, but not always.
						items=line.Split(new char[] { ' ' });
						face=new Face();
						VertexNormal vertnorm;
						int vertIdx;
						int normIdx;
						//do we need to load these backwards for flipping, so they'll still be counterclockwise?
						//It seems to work anyway, but it's something to keep in mind for later.
						for(int i=1;i<items.Length;i++){//face.GetLength(0);i++) {
							subitems=items[i].Split(new char[] { '/' });// eg: 9//9  this is an index to a given vertex/normal.
							vertnorm=new VertexNormal();//unlike the old way of just storing idxs, we will actually store vertices.
							vertIdx=Convert.ToInt32(subitems[0])-1;
							normIdx=Convert.ToInt32(subitems[2])-1;
							vertnorm.Vertex=verts[vertIdx];
							vertnorm.Normal=norms[normIdx];
							face.IndexList.Add(GetIndexForVertNorm(vertnorm));
						}
						faces.Add(face);
						continue;
					}
				}//while readline
				//For the very last group, move all faces into the group
				group.Faces=new List<Face>(faces);//new int[ALf.Count][][];
				//move the last group into the AL
				Groups.Add(group);
			}
			//MessageBox.Show(Vertices[2,2].ToString());
		}
Пример #4
0
		///<summary>This is used when calling display lists.</summary>
		public int GetIndexForDisplayList(ToothGroup group) {
			int toothInt=Tooth.ToOrdinal(toothID);
			//this can be enhanced later, but it's very simple for now.
			return (toothInt*15)+(int)group.GroupType;
		}
Пример #5
0
		private Material GetGroupMaterial(ToothGraphic toothGraphic,ToothGroup group){
			Material material=new Material();
			Color materialColor;
			if(toothGraphic.ShiftO<-10) {//if unerupted
				materialColor=Color.FromArgb(group.PaintColor.A/2,group.PaintColor.R/2,group.PaintColor.G/2,group.PaintColor.B/2);
			} else {
				materialColor=group.PaintColor;
			}
			material.Ambient=materialColor;
			material.Diffuse=materialColor;
			if(group.GroupType==ToothGroupType.Cementum) {
				material.Specular=specular_color_cementum;
			} else if(group.PaintColor.R>245&&group.PaintColor.G>245&&group.PaintColor.B>235) {
				//because DirectX washes out the specular on the enamel, we have to turn it down only for the enamel color
				//for reference, this is the current enamel color: Color.FromArgb(255,250,250,240)
				float specEnamel=.4f;
				material.Specular=Color.FromArgb(255,(int)(255*specEnamel),(int)(255*specEnamel),(int)(255*specEnamel));
			} else {
				material.Specular=specular_color_normal;
			}
			material.SpecularSharpness=specularSharpness;
			return material;
		}