private void OnSceneGUI() { if (myCreator.previewGeneratedMesh && Event.current.type == EventType.Repaint) { myCreator.UpdateMesh(); } }
void Update() { // Make the vertices wobble for (int i = 0; i < meshCreator.MeshVerticesCount; i++) { MeshVertex meshVertex = meshCreator.MeshVertices[i]; float scale = Mathf.Lerp(2f, 4f, Mathf.Abs(Mathf.Cos(Time.time + i / 4f))); meshVertex.Position = meshVertex.Position.normalized * scale; } // Update the mesh meshCreator.UpdateMesh(meshFilter.sharedMesh); }
void LateUpdate() { if (UpdateChunks) { UpdateChunks = false; foreach (Chunk c in ToUpdate) { if (c != null) { MeshCreator.UpdateMesh(c, c.Blocks); } } ToUpdate.Clear(); } }
public override bool OnPlace(int x, int y, int z, int rot) { Block b = Block.Transparent.Instance(); b.AddComponent <MultiblockPartComponent>(x, y, z, parentBlock); bool canPlaceThis; Chunk chunk = null; foreach (Vector3Int pos in Locations) { if (pos.x + x < 0 || pos.x + x > World.sizeX * Chunk.maxX - 1 || pos.z + z < 0 || pos.z + z > World.sizeZ * Chunk.maxZ - 1 || World.GetBlock(x + pos.x, y + pos.y, z + pos.z) != null) { return(false); } canPlaceThis = false; chunk = World.GetChunkByBlock(x + pos.x, z + pos.z); foreach (Chunk c in World.builder.building.Chunks) { if (c == chunk) { canPlaceThis = true; break; } } if (!canPlaceThis) { return(false); } } foreach (Vector3Int pos in Locations) { World.SetBlock(x + pos.x, y + pos.y, z + pos.z, b); } MeshCreator.UpdateMesh(chunk, chunk.Blocks); return(true); }
/*** * OnInspectorGUI * this does the main display of information in the inspector. ***/ public override void OnInspectorGUI() { // TODO: inspector layout should be redesigned so that it's easier to // see the texture and material information if (mcd != null) { // determine if we're looking at a scene object or a prefab object bool isPrefab = PrefabUtility.GetPrefabType(mcd.gameObject) == PrefabType.Prefab; // below is GUI code for normal scene view if (!isPrefab) { EditorGUILayout.LabelField("UCLA Game Lab Mesh Creator"); EditorGUILayout.Space(); EditorGUILayout.LabelField("Mesh Creation Outline", ""); mcd.outlineTexture = EditorGUILayout.ObjectField("Mesh Outline Texture", mcd.outlineTexture, typeof(Texture2D), true) as Texture2D; mcd.pixelTransparencyThreshold = EditorGUILayout.Slider(" Pixel Threshold", mcd.pixelTransparencyThreshold, 1.0f, 255.0f); EditorGUILayout.Space(); // what type of object being created, 2d or 3d? if (mcd.uvWrapMesh == true) { meshType = ObjectMeshType.Full3D; } else { meshType = ObjectMeshType.Flat2D; } meshType = (ObjectMeshType)EditorGUILayout.EnumPopup("Mesh Type", meshType); if (meshType == ObjectMeshType.Full3D) { mcd.uvWrapMesh = true; } else { mcd.uvWrapMesh = false; } //with colliders? if (mcd.generateCollider == false) { colliderType = ObjectColliderType.None; } else if (mcd.usePrimitiveCollider == false && mcd.useAABBCollider == false) { colliderType = ObjectColliderType.Mesh; } else if (mcd.usePrimitiveCollider == false && mcd.useAABBCollider == true) { colliderType = ObjectColliderType.BoundingBox; } else { colliderType = ObjectColliderType.Boxes; } colliderType = (ObjectColliderType)EditorGUILayout.EnumPopup("Collider Type", colliderType); if (colliderType == ObjectColliderType.None) { mcd.generateCollider = false; } else if (colliderType == ObjectColliderType.Mesh) { mcd.generateCollider = true; mcd.usePrimitiveCollider = false; mcd.useAABBCollider = false; } else if (colliderType == ObjectColliderType.BoundingBox) { mcd.generateCollider = true; mcd.usePrimitiveCollider = false; mcd.useAABBCollider = true; } else // ObjectColliderType.Boxes { mcd.generateCollider = true; mcd.usePrimitiveCollider = true; mcd.useAABBCollider = false; } EditorGUILayout.Space(); if (mcd.uvWrapMesh) { EditorGUILayout.TextArea("A 3d mesh will be created."); } else { if (mcd.createEdges && mcd.createBacksidePlane) { EditorGUILayout.TextArea("Flat front and back planes will be created, with a mesh side edge."); } else if (mcd.createEdges) { EditorGUILayout.TextArea("A flat front plane will be created, with a mesh side edge."); } else if (mcd.createBacksidePlane) { EditorGUILayout.TextArea("Flat front and back planes will be created."); } else { EditorGUILayout.TextArea("A flat front plane will be created."); } } EditorGUILayout.Space(); showMeshInfo = EditorGUILayout.Foldout(showMeshInfo, "Mesh Creation"); if (showMeshInfo) { EditorGUILayout.LabelField(" Mesh id number", mcd.idNumber); if (!mcd.uvWrapMesh) { mcd.createEdges = EditorGUILayout.Toggle(" Create full mesh for edge?", mcd.createEdges); mcd.createBacksidePlane = EditorGUILayout.Toggle(" Create backside plane?", mcd.createBacksidePlane); } } EditorGUILayout.Space(); showMaterialInfo = EditorGUILayout.Foldout(showMaterialInfo, "Mesh Materials"); if (showMaterialInfo) { mcd.useAutoGeneratedMaterial = EditorGUILayout.Toggle(" Auto Generate Material?", mcd.useAutoGeneratedMaterial); if (!mcd.useAutoGeneratedMaterial) { mcd.frontMaterial = EditorGUILayout.ObjectField(" Use Other Material", mcd.frontMaterial, typeof(Material), true) as Material; } } EditorGUILayout.Space(); showColliderInfo = EditorGUILayout.Foldout(showColliderInfo, "Collider Creation"); if (showColliderInfo) { if (mcd.generateCollider && mcd.usePrimitiveCollider) { mcd.maxNumberBoxes = EditorGUILayout.IntField(" Max Number Boxes", mcd.maxNumberBoxes); } if (mcd.generateCollider) { mcd.usePhysicMaterial = EditorGUILayout.Toggle(" Use Physics Material?", mcd.usePhysicMaterial); if (mcd.usePhysicMaterial) { mcd.physicMaterial = EditorGUILayout.ObjectField(" Physical Material", mcd.physicMaterial, typeof(PhysicMaterial), true) as PhysicMaterial; } mcd.setTriggers = EditorGUILayout.Toggle(" Set Collider Triggers?", mcd.setTriggers); } } EditorGUILayout.Space(); showExperimentalInfo = EditorGUILayout.Foldout(showExperimentalInfo, "Advanced"); if (showExperimentalInfo) { EditorGUILayout.LabelField(" Mesh Scale", ""); mcd.meshWidth = EditorGUILayout.FloatField(" Width", mcd.meshWidth); mcd.meshHeight = EditorGUILayout.FloatField(" Height", mcd.meshHeight); mcd.meshDepth = EditorGUILayout.FloatField(" Depth", mcd.meshDepth); EditorGUILayout.Space(); EditorGUILayout.LabelField(" Edge Smoothing", ""); mcd.mergeClosePoints = EditorGUILayout.Toggle(" Merge Close Vertices", mcd.mergeClosePoints); //mcd.mergePercent = EditorGUILayout.FloatField( "Merge Percent Points", mcd.mergePercent); if (mcd.mergeClosePoints) { mcd.mergeDistance = EditorGUILayout.FloatField(" Merge Distance (px)", mcd.mergeDistance); } EditorGUILayout.Space(); EditorGUILayout.LabelField(" Pivot Position", ""); mcd.pivotHeightOffset = EditorGUILayout.FloatField(" Pivot Height Offset", mcd.pivotHeightOffset); mcd.pivotWidthOffset = EditorGUILayout.FloatField(" Pivot Width Offset", mcd.pivotWidthOffset); mcd.pivotDepthOffset = EditorGUILayout.FloatField(" Pivot Depth Offset", mcd.pivotDepthOffset); } EditorGUILayout.Space(); if (GUILayout.Button("Update Mesh", GUILayout.MaxWidth(100))) { // do some simple parameter checking here so we don't get into trouble if (mcd.maxNumberBoxes < 1) { Debug.LogWarning("Mesh Creator: minimum number of boxes should be one or more. Setting to 1 and continuing."); } else { MeshCreator.UpdateMesh(mcd.gameObject); } } showToolInfo = EditorGUILayout.Foldout(showToolInfo, "Mesh Creator Info"); if (showToolInfo) { EditorGUILayout.LabelField(" Mesh Creator Data", "version " + MeshCreatorData.versionNumber.ToString()); EditorGUILayout.LabelField(" Mesh Creator Editor", "version " + versionNumber.ToString()); EditorGUILayout.LabelField(" Mesh Creator", "version " + MeshCreator.versionNumber.ToString()); } } // end normal scene GUI code else // begin prefab inspector GUI code { EditorGUILayout.LabelField("UCLA Game Lab Mesh Creator"); EditorGUILayout.Space(); EditorGUILayout.LabelField("Mesh Creator must be used in a scene."); EditorGUILayout.LabelField("To manipulate Mesh Creator Data and update this prefab,"); EditorGUILayout.LabelField("pull it into a scene, update Mesh Creator, and apply your"); EditorGUILayout.LabelField("changes to the prefab."); EditorGUILayout.Space(); EditorGUILayout.LabelField("Mesh Creation Outline", ""); EditorGUILayout.ObjectField("Mesh Outline Texture", mcd.outlineTexture, typeof(Texture2D), true); EditorGUILayout.LabelField(" Pixel Threshold", mcd.pixelTransparencyThreshold.ToString()); EditorGUILayout.Space(); // what type of object being created, 2d or 3d? if (mcd.uvWrapMesh == true) { meshType = ObjectMeshType.Full3D; } else { meshType = ObjectMeshType.Flat2D; } EditorGUILayout.LabelField("Mesh Type", meshType.ToString()); //with colliders? if (mcd.generateCollider == false) { colliderType = ObjectColliderType.None; } else if (mcd.usePrimitiveCollider == false && mcd.useAABBCollider == false) { colliderType = ObjectColliderType.Mesh; } else if (mcd.usePrimitiveCollider == false && mcd.useAABBCollider == true) { colliderType = ObjectColliderType.BoundingBox; } else { colliderType = ObjectColliderType.Boxes; } EditorGUILayout.LabelField("Collider Type", colliderType.ToString()); EditorGUILayout.Space(); if (mcd.uvWrapMesh) { EditorGUILayout.TextArea("A 3d mesh will be created."); } else { if (mcd.createEdges && mcd.createBacksidePlane) { EditorGUILayout.TextArea("Flat front and back planes will be created, with a mesh side edge."); } else if (mcd.createEdges) { EditorGUILayout.TextArea("A flat front plane will be created, with a mesh side edge."); } else if (mcd.createBacksidePlane) { EditorGUILayout.TextArea("Flat front and back planes will be created."); } else { EditorGUILayout.TextArea("A flat front plane will be created."); } } EditorGUILayout.Space(); showMeshInfo = EditorGUILayout.Foldout(showMeshInfo, "Mesh Creation"); if (showMeshInfo) { EditorGUILayout.LabelField(" Mesh id number", mcd.idNumber); if (!mcd.uvWrapMesh) { EditorGUILayout.Toggle(" Create full mesh for edge?", mcd.createEdges); EditorGUILayout.Toggle(" Create backside plane?", mcd.createBacksidePlane); } } EditorGUILayout.Space(); showMaterialInfo = EditorGUILayout.Foldout(showMaterialInfo, "Mesh Materials"); if (showMaterialInfo) { EditorGUILayout.Toggle(" Auto Generate Material?", mcd.useAutoGeneratedMaterial); if (!mcd.useAutoGeneratedMaterial) { EditorGUILayout.ObjectField(" Use Other Material", mcd.frontMaterial, typeof(Material), true); } } EditorGUILayout.Space(); showColliderInfo = EditorGUILayout.Foldout(showColliderInfo, "Collider Creation"); if (showColliderInfo) { if (mcd.generateCollider && mcd.usePrimitiveCollider) { EditorGUILayout.LabelField(" Max Number Boxes", mcd.maxNumberBoxes.ToString()); } if (mcd.generateCollider) { EditorGUILayout.Toggle(" Use Physics Material?", mcd.usePhysicMaterial); if (mcd.usePhysicMaterial) { EditorGUILayout.ObjectField(" Physical Material", mcd.physicMaterial, typeof(PhysicMaterial), true); } EditorGUILayout.Toggle(" Set Collider Triggers?", mcd.setTriggers); } } EditorGUILayout.Space(); showExperimentalInfo = EditorGUILayout.Foldout(showExperimentalInfo, "Advanced"); if (showExperimentalInfo) { EditorGUILayout.LabelField(" Mesh Scale", ""); EditorGUILayout.LabelField(" Width", mcd.meshWidth.ToString()); EditorGUILayout.LabelField(" Height", mcd.meshHeight.ToString()); EditorGUILayout.LabelField(" Depth", mcd.meshDepth.ToString()); EditorGUILayout.Space(); EditorGUILayout.LabelField(" Edge Smoothing", ""); EditorGUILayout.Toggle(" Merge Close Vertices", mcd.mergeClosePoints); if (mcd.mergeClosePoints) { EditorGUILayout.LabelField(" Merge Distance (px)", mcd.mergeDistance.ToString()); } EditorGUILayout.Space(); EditorGUILayout.LabelField(" Pivot Position", ""); EditorGUILayout.LabelField(" Pivot Height Offset", mcd.pivotHeightOffset.ToString()); EditorGUILayout.LabelField(" Pivot Width Offset", mcd.pivotWidthOffset.ToString()); EditorGUILayout.LabelField(" Pivot Depth Offset", mcd.pivotDepthOffset.ToString()); } showToolInfo = EditorGUILayout.Foldout(showToolInfo, "Mesh Creator Info"); if (showToolInfo) { EditorGUILayout.LabelField(" Mesh Creator Data", "version " + MeshCreatorData.versionNumber.ToString()); EditorGUILayout.LabelField(" Mesh Creator Editor", "version " + versionNumber.ToString()); EditorGUILayout.LabelField(" Mesh Creator", "version " + MeshCreator.versionNumber.ToString()); } } // end prefab inspector GUI code } else { Debug.LogError("MeshCreatorInspector::OnInspectorGUI(): couldn't find a MeshCreatorData component. Something has gone horribly wrong, try reloading your scene."); } }
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(); }
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(); }