/*** * OnEnable * set the MeshCreator when component is added to the object ***/ private void OnEnable() { mcd = target as MeshCreatorData; if (mcd == null) { Debug.LogError("MeshCreatorInspector::OnEnable(): couldn't find a MeshCreatorData.cs component. Is the file in your project?"); } }
void OnGUI() { EditorGUIUtility.AddCursorRect(new Rect(10, 10, 400, 150), MouseCursor.Link); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); // display game lab logo & link if (GUILayout.Button(gameLabLogo)) { Application.OpenURL("http://games.ucla.edu/"); } GUILayout.FlexibleSpace(); //basic instructions GUILayout.Label("Choose a texture with alpha channel to create a mesh from\nSquare images are recommended.\n\nThen select whether to create depth on the mesh and whether you\nwant colliders for your new mesh.\n\nEnter a game object name and you are good to go.\n\nAdvanced control is available once you create the object.", GUILayout.Width(400)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); EditorGUILayout.Space(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.BeginVertical(); //source texture EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Texture to Create Mesh From", GUILayout.Width(175)); GUILayoutOption[] textureDisplaySize = { GUILayout.Width(150), GUILayout.Height(150) }; if (textureToCreateMeshFrom != null) { if (textureToCreateMeshFrom.height != textureToCreateMeshFrom.width) { if (textureToCreateMeshFrom.width > textureToCreateMeshFrom.height) { textureDisplaySize[0] = GUILayout.Width(150); textureDisplaySize[1] = GUILayout.Height(150 * textureToCreateMeshFrom.height / textureToCreateMeshFrom.width); } else { textureDisplaySize[0] = GUILayout.Width(150 * textureToCreateMeshFrom.width / textureToCreateMeshFrom.height); textureDisplaySize[1] = GUILayout.Height(150); } } } textureToCreateMeshFrom = (Texture2D)EditorGUILayout.ObjectField(textureToCreateMeshFrom, typeof(Texture2D), false, textureDisplaySize); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); // what type of object being created, 2d or 3d? GUILayout.BeginHorizontal(); meshType = (ObjectMeshType)EditorGUILayout.EnumPopup("Mesh Type", meshType, GUILayout.Width(330)); GUILayout.EndHorizontal(); //with colliders? GUILayout.BeginHorizontal(); colliderType = (ObjectColliderType)EditorGUILayout.EnumPopup("Collider Type", colliderType, GUILayout.Width(330)); GUILayout.EndHorizontal(); //object name GUILayout.BeginHorizontal(); GUILayout.Label("Game Object Name", GUILayout.Width(175)); gameObjectName = GUILayout.TextField(gameObjectName, 50, GUILayout.Width(175)); GUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.Space(); //submit button GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Create Mesh", GUILayout.Width(100)) && textureToCreateMeshFrom != null) { // register the Undo Undo.RegisterSceneUndo("Create New Mesh Object"); // create the new object and set the proper variables GameObject newObject = new GameObject(gameObjectName); MeshCreatorData mcd = newObject.AddComponent("MeshCreatorData") as MeshCreatorData; // set up mesh creator data mcd.outlineTexture = textureToCreateMeshFrom; mcd.useAutoGeneratedMaterial = true; // for height and width, maintain the image's aspect ratio if (textureToCreateMeshFrom.height != textureToCreateMeshFrom.width) { float height = textureToCreateMeshFrom.height; float width = textureToCreateMeshFrom.width; Debug.LogWarning("MeshCreatorWizard:: image " + textureToCreateMeshFrom.name + " has non-square size " + width + "x" + height + ", adjusting scale to match."); if (height > width) { mcd.meshHeight = 1.0f; mcd.meshWidth = width / height; } else { mcd.meshHeight = height / width; mcd.meshWidth = 1.0f; } } else { mcd.meshHeight = 1.0f; mcd.meshWidth = 1.0f; } mcd.meshDepth = 1.0f; // set up the depth options if (meshType == ObjectMeshType.Full3D) { mcd.uvWrapMesh = true; mcd.createEdges = false; mcd.createBacksidePlane = false; } else { mcd.uvWrapMesh = false; mcd.createEdges = false; mcd.createBacksidePlane = false; } // set up the collider options if (colliderType == ObjectColliderType.Boxes) { mcd.generateCollider = true; mcd.usePrimitiveCollider = true; mcd.useAABBCollider = false; mcd.maxNumberBoxes = 20; mcd.usePhysicMaterial = false; //mcd.addRigidBody = false; } else if (colliderType == ObjectColliderType.Mesh) { mcd.generateCollider = true; mcd.usePrimitiveCollider = false; mcd.useAABBCollider = false; mcd.maxNumberBoxes = 20; mcd.usePhysicMaterial = false; //mcd.addRigidBody = false; } else if (colliderType == ObjectColliderType.BoundingBox) { mcd.generateCollider = true; mcd.usePrimitiveCollider = false; mcd.useAABBCollider = true; mcd.maxNumberBoxes = 20; mcd.usePhysicMaterial = false; //mcd.addRigidBody = false; } else // default to none { mcd.generateCollider = false; mcd.usePrimitiveCollider = false; mcd.maxNumberBoxes = 20; mcd.usePhysicMaterial = false; //mcd.addRigidBody = false; } // update the mesh MeshCreator.UpdateMesh(newObject); Close(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); }
/*** * OnEnable * set the MeshCreator when component is added to the object ***/ private void OnEnable() { mcd = target as MeshCreatorData; if (mcd == null) { Debug.LogError("MeshCreatorInspector::OnEnable(): couldn't find a MeshCreatorData.cs component. Is the file in your project?"); } mcud = new MeshCreatorUndoManager(mcd, "Mesh Creator"); }
public void doTheCube() { // create the new object and set the proper variables gameObjectName += cpt; cpt++; GameObject newObject = new GameObject(gameObjectName); newObject.transform.position = posIni; //le place comme fils newObject.transform.SetParent(transform, false); //Utilisation de la texture de test //textureToCreateMeshFrom = (Texture2D) Resources.LoadAssetAtPath(testTexture, typeof(Texture2D)); //Utilisation de la texture rendue par le DrawAFigure var bytes = drawing.getTex().EncodeToPNG(); //File.WriteAllBytes ("Assets/textures/" + gameObjectName+".png", bytes); //textureToCreateMeshFrom.LoadImage (bytes); File.WriteAllBytes("Assets/textures/textureExtruded.png", bytes); textureToCreateMeshFrom = (Texture2D)Resources.LoadAssetAtPath("Assets/textures/textureExtruded.png", typeof(Texture2D)); MeshCreatorData mcd = newObject.AddComponent("MeshCreatorData") as MeshCreatorData; // set up mesh creator data mcd.outlineTexture = textureToCreateMeshFrom; mcd.useAutoGeneratedMaterial = true; // for height and width, maintain the image's aspect ratio if (textureToCreateMeshFrom.height != textureToCreateMeshFrom.width) { float height = textureToCreateMeshFrom.height; float width = textureToCreateMeshFrom.width; Debug.LogWarning("MeshCreatorWizard:: image " + textureToCreateMeshFrom.name + " has non-square size " + width + "x" + height + ", adjusting scale to match."); if (height > width) { mcd.meshHeight = 1.0f; mcd.meshWidth = width / height; } else { mcd.meshHeight = height / width; mcd.meshWidth = 1.0f; } } else { mcd.meshHeight = 1.0f; mcd.meshWidth = 1.0f; } mcd.meshDepth = size * 0.25f; // set up the depth options if (meshType == ObjectMeshType.Full3D) { mcd.uvWrapMesh = true; mcd.createEdges = false; mcd.createBacksidePlane = false; } else { mcd.uvWrapMesh = false; mcd.createEdges = false; mcd.createBacksidePlane = false; } // update the mesh MeshCreator.UpdateMesh(newObject); Debug.Log("Objet créé"); //met un shader transparant newObject.renderer.material.mainTexture = (Texture)Texture.Instantiate(textureToCreateMeshFrom); newObject.renderer.material.shader = Shader.Find("Transparent/Diffuse"); //Initialise le placement de l'objet placement.SetActive(true); followObject.front(); followObject.setName(gameObjectName); followObject.makeTran(); gameObjectName = "Mesh Creator Object"; //TODO Detruire la texture créée //File.Delete("Assets/textures/textureExtruded" + gameObjectName + ".png"); //Close(); }
public static bool IdExistsInScene(MeshCreatorData mcd) { // check all objects in this scene for a matching unique number object[] objs = GameObject.FindSceneObjectsOfType( typeof(GameObject)); foreach (GameObject go in objs) { MeshCreatorData meshcd = go.GetComponent(typeof(MeshCreatorData)) as MeshCreatorData; if (meshcd && go != mcd.gameObject) { if (meshcd.idNumber == mcd.idNumber) return true; } } return false; }
/*** * OnEnable * set the MeshCreator when component is added to the object ***/ private void OnEnable() { mcd = target as MeshCreatorData; if (mcd == null) { Debug.LogError("MeshCreatorInspector::OnEnable(): couldn't find a MeshCreatorData component"); } }