コード例 #1
0
ファイル: GearWorx.cs プロジェクト: benlewis/unhinged_vr
	void OnGUI () {
		bool Error = false;
		//int OrigToothCount = QtyTeeth;
		//float ScaleFact = 1.0f;
		//float ToothHeight = 0.0f;
		
		GUILayout.Label ("Create Gear (Gears By BrainTwinkie)", EditorStyles.boldLabel);            
	
		QtyTeeth = EditorGUILayout.IntSlider("Qty Teeth", QtyTeeth, 1, 1000,GUILayout.ExpandWidth(true) );               
		//LockRatio = EditorGUILayout.Toggle("Lock Tooth/Radius Ratio", LockRatio); 
		/*
		if(LockRatio){
			ScaleFact = (float)QtyTeeth / (float) OrigToothCount;
			ToothHeight = OutsideToothRadius - InnerToothRadius;
			
			
			InnerToothRadius *= ScaleFact;
			OutsideToothRadius = InnerToothRadius + ToothHeight;
			//InnerToothRadius *= ScaleFact;
		}
		*/
		OutsideToothRadius = EditorGUILayout.FloatField("Outside Tooth Radius", OutsideToothRadius);                
		
		InnerToothRadius = EditorGUILayout.FloatField("Base Tooth Radius", InnerToothRadius);               
		
		RingRadius = EditorGUILayout.FloatField("Ring Radius", RingRadius); 
		
		Height = EditorGUILayout.FloatField("Height", Height);
		
		if(InnerToothRadius != 0){
			SpokeType = (GearSupport.SpokeTypes) EditorGUILayout.EnumPopup("Spoke Type", SpokeType,GUILayout.ExpandWidth(true) );               
			
			if(SpokeType != GearSupport.SpokeTypes.None && SpokeType != GearSupport.SpokeTypes.Solid){
				SpokeCount = EditorGUILayout.IntSlider("Spoke Count", SpokeCount, 1, 10,GUILayout.ExpandWidth(true) );               
			}
			
			if(SpokeType != GearSupport.SpokeTypes.None){
				SpokeIndent = EditorGUILayout.FloatField("Spoke Indent", SpokeIndent);               
	
			}
			
			if(SpokeType == GearSupport.SpokeTypes.Straight){
				hubHeight = EditorGUILayout.FloatField("Hub Height", hubHeight);  
				HubRadius = EditorGUILayout.FloatField("Hub Radius", HubRadius);    
				HubSides = EditorGUILayout.IntSlider("Hub Sides", HubSides, 1, 100, GUILayout.ExpandWidth(true));    
				SpokeWidthInner = EditorGUILayout.FloatField("Spoke Width (Inner)", SpokeWidthInner);
				SpokeWidthOuter = EditorGUILayout.FloatField("Spoke Width (Outer)", SpokeWidthOuter);
				
				if(hubHeight >= Height){
					EditorGUILayout.LabelField("Warning! Hub Height should be less than Gear Height.", GUILayout.ExpandWidth(true));	
				}
				
			}
			
			
			EditorGUILayout.LabelField("", GUILayout.ExpandWidth(true));	
		}
		
		TopScalePct = EditorGUILayout.FloatField("Top Scale %", TopScalePct);  
		
		TopRotation = EditorGUILayout.FloatField("Top Rotation (Deg)", TopRotation);      
		
		ToothRotation = EditorGUILayout.FloatField("Tooth Rotation (Deg)", ToothRotation);               
		
		ToothWidthPct = EditorGUILayout.FloatField("Outside Tooth Width %", ToothWidthPct);  
			
		GearMaterial = (Material)EditorGUILayout.ObjectField("Gear Material",(Material)GearMaterial, typeof(Material), false, GUILayout.Height(16));
		//DebugTextMaterial = (Material)EditorGUILayout.ObjectField("DebugText Material",(Material)DebugTextMaterial, typeof(Material), false, GUILayout.Height(16));
		//DebugTextFont = (Font)EditorGUILayout.ObjectField("DebugText Font",(Font)DebugTextFont, typeof(Font), false, GUILayout.Height(16));
		//DebugTextMaterial = DebugTextFont.material;
		
		
		EditorGUILayout.LabelField("", GUILayout.ExpandWidth(true));	
		
		if(RingRadius > InnerToothRadius){
			EditorGUILayout.LabelField("ERROR! Ring Radius larger than the Inner tooth radius.", GUILayout.ExpandWidth(true));	
			Error = true;
		}
		
		if(RingRadius < 0){
			EditorGUILayout.LabelField("ERROR! Ring Radius must be greater than or 0.", GUILayout.ExpandWidth(true));	
			Error = true;
		}
		
		if(ToothWidthPct < 0){
			EditorGUILayout.LabelField("ERROR! Tooth Width % must be greater than or 0.", GUILayout.ExpandWidth(true));	
			Error = true;
		}
		
		if(OutsideToothRadius < InnerToothRadius){
			EditorGUILayout.LabelField("ERROR! Outside Tooth Radius must be greater than the Inner Tooth Radius.", GUILayout.ExpandWidth(true));	
			Error = true;
		}
		
		if(Height <=0){
			EditorGUILayout.LabelField("ERROR! Height must be greater than 0.", GUILayout.ExpandWidth(true));	
			Error = true;
		}
		
		if(SpokeType == GearSupport.SpokeTypes.Straight){
			float inctheta;
			float spokeadj;
			inctheta = 2.0f * (Mathf.PI / QtyTeeth);
			spokeadj = 2.0f * Mathf.Asin(SpokeWidthInner / (8.0f * HubRadius)); //Calc'd using cord of circ.
			
			if(inctheta - spokeadj <= spokeadj){
				EditorGUILayout.LabelField("Warning! Spoke width and hub radius may create overlapping verts.", GUILayout.ExpandWidth(true));	
				//Error = true;
			}
		}
		
		if(GearMaterial == null){
			EditorGUILayout.LabelField("Warning! Material Not Assigned.", GUILayout.ExpandWidth(true));	
		}
		
		EditorGUILayout.LabelField("", GUILayout.ExpandWidth(true));	
		if(!Error){
			if(GUILayout.Button ("Create")){
				CreateGear();
			}
		}else{
			EditorGUILayout.LabelField("Clear errors to create gears.", GUILayout.ExpandWidth(true));	
		}
		
	}
コード例 #2
0
    void OnGUI()
    {
        bool Error = false;

        //int OrigToothCount = QtyTeeth;
        //float ScaleFact = 1.0f;
        //float ToothHeight = 0.0f;

        GUILayout.Label("Create Gear (Gears By BrainTwinkie)", EditorStyles.boldLabel);

        QtyTeeth = EditorGUILayout.IntSlider("Qty Teeth", QtyTeeth, 1, 1000, GUILayout.ExpandWidth(true));
        //LockRatio = EditorGUILayout.Toggle("Lock Tooth/Radius Ratio", LockRatio);

        /*
         * if(LockRatio){
         *      ScaleFact = (float)QtyTeeth / (float) OrigToothCount;
         *      ToothHeight = OutsideToothRadius - InnerToothRadius;
         *
         *
         *      InnerToothRadius *= ScaleFact;
         *      OutsideToothRadius = InnerToothRadius + ToothHeight;
         *      //InnerToothRadius *= ScaleFact;
         * }
         */
        OutsideToothRadius = EditorGUILayout.FloatField("Outside Tooth Radius", OutsideToothRadius);

        InnerToothRadius = EditorGUILayout.FloatField("Base Tooth Radius", InnerToothRadius);

        RingRadius = EditorGUILayout.FloatField("Ring Radius", RingRadius);

        Height = EditorGUILayout.FloatField("Height", Height);

        if (InnerToothRadius != 0)
        {
            SpokeType = (GearSupport.SpokeTypes)EditorGUILayout.EnumPopup("Spoke Type", SpokeType, GUILayout.ExpandWidth(true));

            if (SpokeType != GearSupport.SpokeTypes.None && SpokeType != GearSupport.SpokeTypes.Solid)
            {
                SpokeCount = EditorGUILayout.IntSlider("Spoke Count", SpokeCount, 1, 10, GUILayout.ExpandWidth(true));
            }

            if (SpokeType != GearSupport.SpokeTypes.None)
            {
                SpokeIndent = EditorGUILayout.FloatField("Spoke Indent", SpokeIndent);
            }

            if (SpokeType == GearSupport.SpokeTypes.Straight)
            {
                hubHeight       = EditorGUILayout.FloatField("Hub Height", hubHeight);
                HubRadius       = EditorGUILayout.FloatField("Hub Radius", HubRadius);
                HubSides        = EditorGUILayout.IntSlider("Hub Sides", HubSides, 1, 100, GUILayout.ExpandWidth(true));
                SpokeWidthInner = EditorGUILayout.FloatField("Spoke Width (Inner)", SpokeWidthInner);
                SpokeWidthOuter = EditorGUILayout.FloatField("Spoke Width (Outer)", SpokeWidthOuter);

                if (hubHeight >= Height)
                {
                    EditorGUILayout.LabelField("Warning! Hub Height should be less than Gear Height.", GUILayout.ExpandWidth(true));
                }
            }


            EditorGUILayout.LabelField("", GUILayout.ExpandWidth(true));
        }

        TopScalePct = EditorGUILayout.FloatField("Top Scale %", TopScalePct);

        TopRotation = EditorGUILayout.FloatField("Top Rotation (Deg)", TopRotation);

        ToothRotation = EditorGUILayout.FloatField("Tooth Rotation (Deg)", ToothRotation);

        ToothWidthPct = EditorGUILayout.FloatField("Outside Tooth Width %", ToothWidthPct);

        GearMaterial = (Material)EditorGUILayout.ObjectField("Gear Material", (Material)GearMaterial, typeof(Material), false, GUILayout.Height(16));
        //DebugTextMaterial = (Material)EditorGUILayout.ObjectField("DebugText Material",(Material)DebugTextMaterial, typeof(Material), false, GUILayout.Height(16));
        //DebugTextFont = (Font)EditorGUILayout.ObjectField("DebugText Font",(Font)DebugTextFont, typeof(Font), false, GUILayout.Height(16));
        //DebugTextMaterial = DebugTextFont.material;


        EditorGUILayout.LabelField("", GUILayout.ExpandWidth(true));

        if (RingRadius > InnerToothRadius)
        {
            EditorGUILayout.LabelField("ERROR! Ring Radius larger than the Inner tooth radius.", GUILayout.ExpandWidth(true));
            Error = true;
        }

        if (RingRadius < 0)
        {
            EditorGUILayout.LabelField("ERROR! Ring Radius must be greater than or 0.", GUILayout.ExpandWidth(true));
            Error = true;
        }

        if (ToothWidthPct < 0)
        {
            EditorGUILayout.LabelField("ERROR! Tooth Width % must be greater than or 0.", GUILayout.ExpandWidth(true));
            Error = true;
        }

        if (OutsideToothRadius < InnerToothRadius)
        {
            EditorGUILayout.LabelField("ERROR! Outside Tooth Radius must be greater than the Inner Tooth Radius.", GUILayout.ExpandWidth(true));
            Error = true;
        }

        if (Height <= 0)
        {
            EditorGUILayout.LabelField("ERROR! Height must be greater than 0.", GUILayout.ExpandWidth(true));
            Error = true;
        }

        if (SpokeType == GearSupport.SpokeTypes.Straight)
        {
            float inctheta;
            float spokeadj;
            inctheta = 2.0f * (Mathf.PI / QtyTeeth);
            spokeadj = 2.0f * Mathf.Asin(SpokeWidthInner / (8.0f * HubRadius));             //Calc'd using cord of circ.

            if (inctheta - spokeadj <= spokeadj)
            {
                EditorGUILayout.LabelField("Warning! Spoke width and hub radius may create overlapping verts.", GUILayout.ExpandWidth(true));
                //Error = true;
            }
        }

        if (GearMaterial == null)
        {
            EditorGUILayout.LabelField("Warning! Material Not Assigned.", GUILayout.ExpandWidth(true));
        }

        EditorGUILayout.LabelField("", GUILayout.ExpandWidth(true));
        if (!Error)
        {
            if (GUILayout.Button("Create"))
            {
                CreateGear();
            }
        }
        else
        {
            EditorGUILayout.LabelField("Clear errors to create gears.", GUILayout.ExpandWidth(true));
        }
    }