void Awake() { Instance = this; string[] dirs = Directory.GetDirectories(Application.dataPath + '/' + Paths.AssetResArtworksNoPrefix); names = Array.ConvertAll(dirs, v => Path.GetFileName(v)); // labelStyle = new GUIStyle(EditorStyles.boldLabel); }
/// <summary> /// /// </summary> public void Dispose() { if (mesh != null) { if (Application.isPlaying) { Mesh.Destroy(mesh); } else { Mesh.DestroyImmediate(mesh); } mesh = null; } if (_manager != null) { _manager.Release(); _manager = null; } _material = null; meshRenderer = null; meshFilter = null; _stencilEraser = null; meshModifier = null; }
void OnSceneGUI() { var script = ((MeshPicker)target); if (null != Camera.current) { var current = Event.current; if (current.type == EventType.MouseDown || current.type == EventType.MouseMove) { script.SetHoveringRegion(null); var pos = current.mousePosition; var ray = HandleUtility.GUIPointToWorldRay(pos); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { if (hit.transform.parent == script.transform) { if (current.type == EventType.MouseDown && current.button == 1) { script.Toggle(hit.transform.GetComponent <MeshRenderer>()); MeshModifier.DoRepaint(); current.Use(); } script.SetHoveringRegion(hit.transform.name); } } } MeshModifier.ShortcutCheck(true); } }
public CaveGenerator() { meshGenerator = new MeshModifier(); caveGenerator = new CaveDataGenerator(); borderDensity = 0; prefabName = string.Empty; }
/// <summary> /// Remove mesh modifier from the modifiers list /// </summary> /// <param name="modifier">Mesh modifier to be removed from style</param> public virtual void RemoveMeshModifier(MeshModifier modifier) { if (_subLayerProperties.MeshModifiers != null) { _subLayerProperties.MeshModifiers.Remove(modifier); _subLayerProperties.HasChanged = true; } }
void OnTriggerEnter(Collider col) { modifier = col.GetComponent <MeshModifier>(); if (modifier != null) { modifier.meshCenter.AddMesh(this.GetComponent <MeshFilter>()); } }
void Start() { m_Mesh = GetComponent <MeshFilter>().mesh; m_RoomVertices = m_Mesh.vertices; m_SharedTriangles = MeshModifier.GetSharedTriangles(m_Mesh); m_RoomAnalyzer = new SurfaceAnalyzer(m_Mesh); m_RoomEdges = m_RoomAnalyzer.Analyze(m_RoomVertices, m_SharedTriangles, null); m_Material = GetComponent <MeshRenderer>().sharedMaterial; }
/// <summary> /// Add mesh modifier to the modifiers list. /// </summary> /// <param name="modifier">Mesh modifier to add to style</param> public virtual void AddMeshModifier(MeshModifier modifier) { if (_subLayerProperties.MeshModifiers == null) { _subLayerProperties.MeshModifiers = new List <MeshModifier>(); } _subLayerProperties.MeshModifiers.Add(modifier); _subLayerProperties.HasChanged = true; }
void OnDestroy() { ClearCurrent(); Instance = null; if (scene.IsValid()) { EditorSceneManager.OpenScene("Assets/Scenes/Start.unity", OpenSceneMode.Single); EditorSceneManager.CloseScene(scene, true); } }
public CaveGenerator(string seed, int width, int height, int wallDensityPercentaje, int algorithmIterations, int borderDensity, int wallRegionMinDensity, int roomRegionMinDensity, int passagesDensity, float scale, float wallsAltitude, string name) { prefabName = name; this.borderDensity = borderDensity; meshGenerator = new MeshModifier(scale, wallsAltitude); int numericSeed = GetNumericSeed(seed); caveGenerator = new CaveDataGenerator(numericSeed, width, height, wallDensityPercentaje, algorithmIterations, borderDensity, wallRegionMinDensity, roomRegionMinDensity, passagesDensity); }
public T AddOrCreateMeshModifier <T>() where T : MeshModifier { MeshModifier mod = _defaultStack.MeshModifiers.FirstOrDefault(x => x.GetType() == typeof(T)); if (mod == null) { mod = (MeshModifier)CreateInstance(typeof(T)); _defaultStack.MeshModifiers.Add(mod); } return((T)mod); }
//TODO: Determine Unity Pro / Free version and use Transparent/Cutout/Diffuse if pro otherwise //use Diffuse in material GameObject CreateRoom(Mesh mesh, Vector3 position, int roomidx, Material material, FloorAttribute floor_attribute) { MeshModifier.CullAlphaFace(ref mesh, m_LevelTextureTile); GameObject go = new GameObject("room" + roomidx); Renderer renderer = go.AddComponent <MeshRenderer>(); MeshFilter mf = go.AddComponent <MeshFilter>(); mf.mesh = mesh; go.transform.position = position; go.transform.rotation = Quaternion.identity; renderer.sharedMaterial = material; //renderer.material.mainTexture = m_LevelTextureTile; //renderer.material.color = new Color(1f, 1f, 1f, 1.0f); renderer.castShadows = !Settings.EnableIndoorShadow; //renderer.material.SetTexture("_BumpMap", Bumptex);*/ if (floor_attribute != FloorAttribute.Water) { //check for inertia tensor calculation! if (mesh.bounds.extents.y == 0 || mesh.bounds.extents.x == 0 || mesh.bounds.extents.z == 0) { BoxCollider cldr = go.AddComponent <BoxCollider>(); cldr.isTrigger = true; } else { #if (UNITY_5_3_OR_NEWER || UNITY_5_3) MeshCollider cldr = go.AddComponent <MeshCollider>(); //room mesh tends to be concave, MeshCollider can not be used as trigger for this kind of mesh in unity 5.3 or higher cldr.isTrigger = false; #else MeshCollider cldr = go.AddComponent <MeshCollider>(); cldr.isTrigger = true; #endif } } else { //go.AddComponent<WaterEffect>(); //no need to WaterEffect.cs for each water surface. use a global Water Effect Controller instead } /*Rigidbody rb = go.AddComponent<Rigidbody>(); * rb.isKinematic = true; * rb.useGravity = false;*/ //go.AddComponent<RoomCollision>(); return(go); }
private void OnTriggerEnter(Collider other) { //Debug.Log("Potion collided with: " + other.transform.name); if (other.tag.Equals("Player")) { //Debug.Log("metallizing"); metalSound.Play(); if (mm = other.gameObject.GetComponent <MeshModifier>()) { mm.Metalize(duration); StartCoroutine(respawnPotion()); } } }
void UpdateMeshObjectWithSpline2(TrailMeshObject tmo, MeshModifier meshModifier, NF.Collections.Generic.LinkedList <LineInfo> records, SplineMeshInfo meshInfo, TrailRecordConfig config) { int desireRecordFrameCount = Math.Min(records.Count, config.MaxPlayingRecordLength); if (desireRecordFrameCount < 2) { return; } var line = mSpliner.Refresh(records, desireRecordFrameCount); meshModifier.FillSplineVUC2(mSpliner, config.ColorStart, config.ColorEnd, ref meshInfo.mMeshInfo); tmo.UpdateMesh(line, 2, ref meshInfo.mMeshInfo); }
private void Start() { // ball.RaiseCollisionEvent += OnBallCollision; mesh = GetComponent <HexMesh>(); mesh.Initialize(); radius = mesh.Size / 2f; modPoints = new MeshModPoint[] { new MeshModPoint(mesh.Size), new MeshModPoint(mesh.Size) }; modifier = new MeshModifier(mesh, modPoints); }
public SplineMeshInfo(TrailRecordConfig config, MeshModifier meshModifier) { var linePerVertexCount = (int)config.ELinePerVertexCount; int line = config.MaxPlayingRecordLength * config.SplineDetail; var totalVertexCount = line * linePerVertexCount; mMeshInfo.Vertices = new NativeArray <Vector3>(new Vector3[totalVertexCount], Allocator.Persistent); mMeshInfo.UVs = new NativeArray <Vector2>(new Vector2[totalVertexCount], Allocator.Persistent); mMeshInfo.Colors = new NativeArray <Color>(new Color[totalVertexCount], Allocator.Persistent); mMeshInfo.Indices = new NativeArray <int>(new int[(line - 1) * linePerVertexCount * (linePerVertexCount + 1)], Allocator.Persistent); if (config.ColorStart == config.ColorEnd) { switch (config.ELinePerVertexCount) { case TrailRecordConfig.E_LinePerVertexCount.TWO: meshModifier.FillSplineCI2(config.ColorStart, ref mMeshInfo); break; case TrailRecordConfig.E_LinePerVertexCount.THREE: meshModifier.FillSplineCI3(config.ColorStart, ref mMeshInfo); break; } } else { switch (config.ELinePerVertexCount) { case TrailRecordConfig.E_LinePerVertexCount.TWO: meshModifier.FillSplineI2(ref mMeshInfo); break; case TrailRecordConfig.E_LinePerVertexCount.THREE: meshModifier.FillSplineI3(ref mMeshInfo); break; } } }
void DoUpdate() { MeshModifier meshModifier = displacementSettings.GetMeshModifier(); meshModifier.ModifyMaterial(material); Context.Constants constants = new Context.Constants { desiredScreenSpaceLength = desiredScreenSpaceLength, gameObject = gameObject, material = material, maxDepth = maxDepth, resolution = resolution * 2 - 1, // We can only use odd resolutions., meshModifier = meshModifier }; Context.Branch[] branches = Context.Branch.GetFromConstants(constants); Context.Depth[] depths = Context.Depth.GetFromConstants(constants); Context.Triangles[] triangles = Context.Triangles.GetFromConstants(constants); Node[] roots = new Node[6]; for (int i = 0; i < 6; i++) { roots[i] = Node.CreateRoot(constants, depths[0], branches[i]); } context = new Context { constants = constants, branches = branches, depths = depths, triangles = triangles, roots = roots }; Reconciler.Initialize(context); lastReconciliationTime = Time.time; }
public static Mesh CreateObjectMesh(Parser.Tr2Mesh tr2mesh, Parser.Tr2Level leveldata) { Vector3[] sharedVertices = null; if (tr2mesh.NumVertices > 0) { sharedVertices = new Vector3[tr2mesh.NumVertices]; for (int vertAttribCount = 0; vertAttribCount < tr2mesh.NumVertices; vertAttribCount++) { float x = tr2mesh.Vertices[vertAttribCount].x; float y = tr2mesh.Vertices[vertAttribCount].y; float z = tr2mesh.Vertices[vertAttribCount].z; ////print("chk vtx x y z:" +x+ " " +y + " " +z); sharedVertices[vertAttribCount].x = x; sharedVertices[vertAttribCount].y = -y; sharedVertices[vertAttribCount].z = z; } //uv = new Vector2[leveldata.Rooms[chkRoom].RoomData.NumVertices]; } //warning: a variable lengh array in a structure can cause access violence //selected_texObjectIdx = leveldata.Rooms[chkRoom].RoomData.Rectangles[0].Texture; //selected_texObj = leveldata.ObjectTextures[selected_texObjectIdx]; //selected_texTileIdx = selected_texObj.Tile; int NumTexturedTriangles = tr2mesh.NumTexturedTriangles; int NumTexturedRectangles = tr2mesh.NumTexturedRectangles; int numNonsharedVertices = (NumTexturedRectangles * 4) + (NumTexturedTriangles * 3); int numNonsharedTris = (NumTexturedRectangles * 3 * 2) + (NumTexturedTriangles * 3); Vector3[] nonSharedVertices = new Vector3[numNonsharedVertices]; Vector2[] nonSharedUVs = new Vector2[numNonsharedVertices]; int[] nonSharedTris = new int[numNonsharedTris]; //triangles = new int[leveldata.Rooms[chkRoom].RoomData.NumRectangles * 3 * 2]; Parser.Tr2Face4[] TexturedRectangles = tr2mesh.TexturedRectangles; for (int rectCount = 0; rectCount < NumTexturedRectangles; rectCount++) { int Idx0 = TexturedRectangles[rectCount].Vertices0; int Idx1 = TexturedRectangles[rectCount].Vertices1; int Idx2 = TexturedRectangles[rectCount].Vertices2; int Idx3 = TexturedRectangles[rectCount].Vertices3; int vertOrUVIdx0 = rectCount * 4 + 0; int vertOrUVIdx1 = rectCount * 4 + 1; int vertOrUVIdx2 = rectCount * 4 + 2; int vertOrUVIdx3 = rectCount * 4 + 3; nonSharedVertices[vertOrUVIdx0] = sharedVertices[Idx0]; nonSharedVertices[vertOrUVIdx1] = sharedVertices[Idx1]; nonSharedVertices[vertOrUVIdx2] = sharedVertices[Idx2]; nonSharedVertices[vertOrUVIdx3] = sharedVertices[Idx3]; ushort texObjectIdx = TexturedRectangles[rectCount].Texture; if (texObjectIdx >= leveldata.ObjectTextures.Length) { continue; //fixed: outof bound exception for Parser.Tr2Level.ObjectTextures } Parser.Tr2ObjectTexture texObj = leveldata.ObjectTextures[texObjectIdx]; ushort texTileIdx = texObj.Tile; //bind this textile in material? //if(texTileIdx != prevTexture) //{ //newMatCount +=1; //prevTexture = texTileIdx; ////print("newMatCount:"+ newMatCount); //} SetFaceUVs(nonSharedUVs, vertOrUVIdx0, vertOrUVIdx1, vertOrUVIdx2, vertOrUVIdx3, texObj); ////print("uv[Idx0]"+ uv[Idx0].x + " " + uv[Idx0].y); ////print("uv[Idx1]"+ uv[Idx1].x + " " + uv[Idx1].y); //ushort opacity = texObj.TransparencyFlags; //isItOpacq nonSharedTris[rectCount * 6 + 0] = vertOrUVIdx0; nonSharedTris[rectCount * 6 + 1] = vertOrUVIdx1; nonSharedTris[rectCount * 6 + 2] = vertOrUVIdx2; nonSharedTris[rectCount * 6 + 3] = vertOrUVIdx2; nonSharedTris[rectCount * 6 + 4] = vertOrUVIdx3; nonSharedTris[rectCount * 6 + 5] = vertOrUVIdx0; } Parser.Tr2Face3[] TexturedTriangles = tr2mesh.TexturedTriangles; for (int triCount = 0; triCount < NumTexturedTriangles; triCount++) { int Idx0 = TexturedTriangles[triCount].Vertices0; int Idx1 = TexturedTriangles[triCount].Vertices1; int Idx2 = TexturedTriangles[triCount].Vertices2; int vertOrUVIdx0 = triCount * 3 + 0; int vertOrUVIdx1 = triCount * 3 + 1; int vertOrUVIdx2 = triCount * 3 + 2; int strideVertIdx = (NumTexturedRectangles * 4); int strideTriIdx = (NumTexturedRectangles * 3 * 2); nonSharedVertices[strideVertIdx + vertOrUVIdx0] = sharedVertices[Idx0]; nonSharedVertices[strideVertIdx + vertOrUVIdx1] = sharedVertices[Idx1]; nonSharedVertices[strideVertIdx + vertOrUVIdx2] = sharedVertices[Idx2]; ushort texObjectIdx = tr2mesh.TexturedTriangles[triCount].Texture; if (texObjectIdx >= leveldata.ObjectTextures.Length) { continue; //fixed: outof bound exception for Parser.Tr2Level.ObjectTextures } Parser.Tr2ObjectTexture texObj = leveldata.ObjectTextures[texObjectIdx]; //if(texTileIdx != prevTexture) //{ //newMatCount +=1; //prevTexture = texTileIdx; ////print("newMatCount:"+ newMatCount); //} SetFaceUVs(nonSharedUVs, strideVertIdx + vertOrUVIdx0, strideVertIdx + vertOrUVIdx1, strideVertIdx + vertOrUVIdx2, texObj); ////print("uv[Idx0]"+ uv[Idx0].x + " " + uv[Idx0].y); ////print("uv[Idx1]"+ uv[Idx1].x + " " + uv[Idx1].y); //ushort opacity = texObj.TransparencyFlags; //isItOpacq nonSharedTris[strideTriIdx + vertOrUVIdx0] = strideVertIdx + vertOrUVIdx0; nonSharedTris[strideTriIdx + vertOrUVIdx1] = strideVertIdx + vertOrUVIdx1; nonSharedTris[strideTriIdx + vertOrUVIdx2] = strideVertIdx + vertOrUVIdx2; } for (int i = 0; i < nonSharedVertices.Length; i++) { nonSharedVertices[i] = nonSharedVertices[i] * Settings.SceneScaling; } Mesh mesh = new Mesh(); mesh.Clear(); mesh.vertices = nonSharedVertices; mesh.uv = nonSharedUVs; mesh.triangles = nonSharedTris; MeshModifier.VertexWeild(mesh); #if UNITY_EDITOR Vector4[] tangents = new Vector4[mesh.vertices.Length]; computeTangentsAndBinormals(mesh.vertices, mesh.normals, mesh.uv, mesh.triangles, tangents); mesh.tangents = tangents; tangents = null; #endif //free some memory nonSharedVertices = null; nonSharedUVs = null; nonSharedTris = null; return(mesh); }
/// <summary> /// Add mesh modifier to the modifiers list. /// </summary> /// <param name="modifier">Mesh modifier to add to style</param> public virtual void AddMeshModifier(MeshModifier modifier) { _subLayerProperties.MeshModifiers.Add(modifier); _subLayerProperties.HasChanged = true; }
public T FindMeshModifier <T>() where T : MeshModifier { MeshModifier mod = _defaultStack.MeshModifiers.FirstOrDefault(x => x.GetType() == typeof(T)); return((T)mod); }
/// <summary> /// /// </summary> public void Dispose() { if (mesh != null) { if (Application.isPlaying) Mesh.Destroy(mesh); else Mesh.DestroyImmediate(mesh); mesh = null; } if (_manager != null) { _manager.Release(); _manager = null; } if (_customMatarial && _material != null) { if (Application.isPlaying) Material.Destroy(_material); else Material.DestroyImmediate(_material); } _material = null; meshRenderer = null; meshFilter = null; _stencilEraser = null; meshModifier = null; }