public override void _Ready() { // ---- // GD.Print(heightTerrain.Name); // <--- ERROR HERE, PRODUCES A CRASH RUNNING IN EDITOR // ---- for (int i = 0; i < this.GetChildCount(); i++) { Node child = this.GetChild(i); this.RemoveChild(child); } float [,] noiseMap = Noise.GenerateNoiseMap(noise, chunkSize, noiseScale); MeshInstance world = new MeshInstance(); world.Name = "World"; PlaneMesh plane = MapGenerator.GeneratePlaneMesh(chunkSize); SpatialMaterial mat = new SpatialMaterial(); mat.AlbedoTexture = MapDisplay.DrawNoiseMapToTexture(noiseMap); mat.AlbedoTexture.Flags = 1; plane.Material = mat; ArrayMesh mesh = MapGenerator.AddNoiseToMesh(plane, noiseMap, chunkSize, heightMultiplier, heightCurve); world.Mesh = mesh; AddChild(world); world.Owner = this; }
public void AddBrowserPlane(int pxWidth, int pxHeight, string defaultURL, WallSide sideToAdd) { if (pxWidth <= 0 || pxHeight <= 0) { return; } PlaneMesh newPlane = PlaneMeshFactory.GetPlane(pxWidth, pxHeight, "PlaneMesh", true, defaultURL); if (browserPlanes.Count == 0) { newPlane.go.transform.position = Vector3.zero; browserPlanes.AddFirst(newPlane); middleBrowserPlane = browserPlanes.First; return; } if (sideToAdd == WallSide.LEFT) { newPlane.go.transform.position = GetSidePos(WallSide.LEFT); browserPlanes.AddFirst(newPlane); } else // (sideToAdd == WallSide.RIGHT) { newPlane.go.transform.position = GetSidePos(WallSide.RIGHT); browserPlanes.AddLast(newPlane); } }
private void OnEnable() { PlaneMesh = (PlaneMesh)target; if (PlaneMeshBanner == null) { PlaneMeshBanner = new GUIContent((Texture2D)EditorGUIUtility.Load("Assets/ElseForty/Media/PlaneMeshBanner.png")); } if (PlaneMesh.gameObject.GetComponent <MeshRenderer>() == null) { PlaneMesh.gameObject.AddComponent <MeshRenderer>(); } PlaneMesh.MeshRenderer = PlaneMesh.gameObject.GetComponent <MeshRenderer>(); if (PlaneMesh.gameObject.GetComponent <MeshFilter>() == null) { PlaneMesh.gameObject.AddComponent <MeshFilter>(); } PlaneMesh.Mesh = PlaneMesh.gameObject.GetComponent <MeshFilter>(); if (PlaneMesh.Material == null) { PlaneMesh.Material = (Material)EditorGUIUtility.Load("Assets/ElseForty/Assets/Materials/Base.mat"); } if (PlaneMesh.SplinePlus == null) { PlaneMesh.SplinePlus = PlaneMesh.gameObject.GetComponent <SplinePlus>(); } PlaneMesh.SplinePlus.SPData.ObjectType = SPType.PlaneMesh; PlaneMesh.DrawMeshOnEachBranch(); }
public static ArrayMesh AddNoiseToMesh(PlaneMesh plane, float[,] noiseMap, int chunkSize, int heightMultiplier, Curve heightCurve) { SurfaceTool st = new SurfaceTool(); st.CreateFrom(plane, 0); ArrayMesh mesh = new ArrayMesh(); MeshDataTool dt = new MeshDataTool(); mesh = st.Commit(); dt.CreateFromSurface(mesh, 0); for (int y = 0; y < chunkSize; y++) { for (int x = 0; x < chunkSize; x++) { int z = y; int vertexIndex = z * chunkSize + x; Vector3 vertex = dt.GetVertex(vertexIndex); vertex.y = heightCurve.Interpolate(noiseMap[chunkSize - x - 1, chunkSize - z - 1]) * heightMultiplier; dt.SetVertex(vertexIndex, vertex); } } for (int surface = 0; surface < mesh.GetSurfaceCount(); surface++) { mesh.SurfaceRemove(surface); } dt.CommitToSurface(mesh); st.Begin(Mesh.PrimitiveType.Triangles); st.CreateFrom(mesh, 0); st.Index(); st.GenerateNormals(); return(st.Commit()); }
public override void _Ready() { if (Terrain == null || Terrain.GetWidth() != TileSize || Terrain.GetHeight() != TileSize) { Terrain = new ImageTexture(); Terrain.Create(TileSize, TileSize, Image.Format.Rgbaf); terrainImg = new Image(); terrainImg.Create(TileSize, TileSize, false, Image.Format.Rgbaf); } if (Mesh == null) { var mesh = new PlaneMesh(); mesh.Size = new Vector2(TileSize, TileSize); mesh.SubdivideWidth = TileSize; mesh.SubdivideDepth = TileSize; Mesh = mesh; var mat = new ShaderMaterial(); mat.SetShader(TerrainShader); SetSurfaceMaterial(0, mat); } if (WorldPos != Vector3.Zero) { _LoadTerrainData(); } hydraulics = new HydraulicSimulation(Terrain); terrainImg = Terrain.GetData(); }
private void OnEnable() { PlaneMesh = (PlaneMesh)target; PlaneMesh.SPData = PlaneMesh.gameObject.transform.GetComponent <SplinePlus>().sPData; if (PlaneMesh.MeshHolder == null) { var meshHolder = SplinePlusAPI.AddMeshHolder(PlaneMesh.SPData, "PlaneMesh"); PlaneMesh.MeshHolder = meshHolder; PlaneMesh.MeshRenderer = meshHolder.GetComponent <MeshRenderer>(); PlaneMesh.Mesh = meshHolder.GetComponent <MeshFilter>(); } if (Delete == null) { Delete = new GUIContent((Texture2D)EditorGUIUtility.Load(SplinePlusEditor.FindAssetPath("Delete.png"))); } if (PlaneMesh.Material == null) { PlaneMesh.Material = (Material)EditorGUIUtility.Load(SplinePlusEditor.FindAssetPath("Base.mat")); if (PlaneMesh.Material == null) { Debug.Log("mat null"); } } PlaneMesh.SPData.MeshModifier = PlaneMesh; PlaneMesh.DrawMesh(); SplineCreationClass.Update_Spline += Update_Spline; }
private void Initialize() { _meshInstance = GetNode <MeshInstance>("Mesh"); PlaneMesh initialMesh = (PlaneMesh)_meshInstance.Mesh; _resX = initialMesh.SubdivideWidth + 1; _resZ = initialMesh.SubdivideDepth + 1; _noise = new OpenSimplexNoise(); UpdateNoiseSettings(); _surfaceTool = new SurfaceTool(); _meshDataTool = new MeshDataTool(); Control HUD = GetNode <Control>("../HUD"); HUD.Connect("UpdateSeed", this, nameof(_On_Seed_Updated)); HUD.Connect("UpdateOctaves", this, nameof(_On_Octaves_Updated)); HUD.Connect("UpdateAmplitude", this, nameof(_On_Amplitude_Updated)); HUD.Connect("UpdatePeriod", this, nameof(_On_Period_Updated)); HUD.Connect("UpdateLacunarity", this, nameof(_On_Lacunarity_Updated)); HUD.Connect("UpdatePersistence", this, nameof(_On_Persistence_Updated)); _initialized = true; }
// Called when the node enters the scene tree for the first time. public override void _Ready() { global = GetNode <Global>("/root/Global"); OnStartTimerTimeout(); CharacterContainer = GetNode <Spatial>("/root/Spatial/CharacterContainer"); SurfaceTool surfaceTool = new SurfaceTool(); planeMesh = new PlaneMesh(); planeMesh.Material = (Material)ResourceLoader.Load("mesh_material.tres"); planeMesh.SubdivideWidth = width - 2; //Subtract two bc there's already two vertices before we start subdividing planeMesh.SubdivideDepth = height - 2; planeMesh.Size = new Vector2(42.4f, 24f); //42.47f (42.4f, 24f) surfaceTool.CreateFrom(planeMesh, 0); arrayPlane = surfaceTool.Commit(); meshInstance = new MeshInstance(); meshInstance.Mesh = arrayPlane; NewDetectedBody(); AddChild(meshInstance); AddChild(detectBody); UpdateShapes(); }
public PlaneMeshModifierNode(PlaneMesh planeMesh, Axis modifierAxis, float scale, bool flipY) { this.planeMesh = planeMesh; this.modifierAxis = modifierAxis; this.scale = scale; this.flipY = flipY; }
private void Awake() { paths = new List <GameObject>(); buildings = new List <GameObject>(); planeMesh = GetComponent <PlaneMesh>(); }
public override void OnValidate() { base.OnValidate(); var mb = PlaneMesh.Create(gridSize, Foreach.Cell(gridSize, cellSize).Select(c => c.o)); meshFilter.sharedMesh = mb.ToMesh(); meshFilter.sharedMesh.RecalculateNormals(); }
public static PlaneMesh GeneratePlaneMesh(int chunkSize) { PlaneMesh plane = new PlaneMesh(); plane.Size = new Vector2(chunkSize, chunkSize); plane.SubdivideDepth = chunkSize - 2; plane.SubdivideWidth = chunkSize - 2; return(plane); }
public void Generate() { planeMesh = new PlaneMesh(); planeMesh.Size = new Vector2(chunkSize, chunkSize); planeMesh.SubdivideDepth = Mathf.RoundToInt(chunkSize * 0.5f); planeMesh.SubdivideWidth = Mathf.RoundToInt(chunkSize * 0.5f); surfaceTool = new SurfaceTool(); meshDataTool = new MeshDataTool(); surfaceTool.CreateFrom(planeMesh, 0); arrayPlane = surfaceTool.Commit(); meshDataTool.CreateFromSurface(arrayPlane, 0); for (int i = 0; i < meshDataTool.GetVertexCount(); i++) { Vector3 vertex = meshDataTool.GetVertex(i); vertex.y = noise.GetNoise3d( vertex.x + position.x, vertex.y, vertex.z + position.z) * References.steepness; meshDataTool.SetVertex(i, vertex); avgHeight += vertex.y; } avgHeight /= meshDataTool.GetVertexCount(); for (int i = 0; i < arrayPlane.GetSurfaceCount(); i++) { arrayPlane.SurfaceRemove(i); } for (int i = 0; i < meshDataTool.GetFaceCount(); i++) { Vector3 A = meshDataTool.GetVertex(meshDataTool.GetFaceVertex(i, 0)); Vector3 B = meshDataTool.GetVertex(meshDataTool.GetFaceVertex(i, 1)); Vector3 C = meshDataTool.GetVertex(meshDataTool.GetFaceVertex(i, 2)); Vector3 face = (A + B + C) / 3 + position; Vector3 normal = meshDataTool.GetFaceNormal(i); slope += Maths.Angle(Vector3.Up, normal); } slope /= meshDataTool.GetFaceCount(); meshDataTool.CommitToSurface(arrayPlane); surfaceTool.Begin(Mesh.PrimitiveType.Triangles); surfaceTool.CreateFrom(arrayPlane, 0); surfaceTool.GenerateNormals(); meshInstance = new MeshInstance(); meshInstance.Mesh = surfaceTool.Commit(); meshInstance.SetSurfaceMaterial(0, (Material)ResourceLoader.Load("res://Assets/Shader/Terrain.material")); meshInstance.CreateTrimeshCollision(); meshInstance.CastShadow = GeometryInstance.ShadowCastingSetting.On; AddChild(meshInstance); }
// Initialization code. Must be called directly, sets up the component public void Generate(int width, int height) { plane = gameObject.GetComponent<PlaneMesh>(); plane.Generate(width, height); Width = plane.Width; Height = plane.Height; Grid = new float[Width, Height]; SwapGrid = new float[Width, Height]; }
public override void OnValidate() { base.OnValidate(); var mb = IsSimple ? PlaneMesh.Create() : PlaneMesh.Create(); for (int i = 0; i < Subdivisions; i++) { mb.Subdivide(Steps); } meshFilter.sharedMesh = mb.ToMesh(); meshFilter.sharedMesh.RecalculateNormals(); }
// Initializes the terrain generator public void Generate(int width, int height) { plane = gameObject.GetComponent<PlaneMesh>(); plane.Generate(width, height); Width = plane.Width; Height = plane.Height; HeightMap = new float[Width, Height]; GenerateHeightMap(); // Alter the heightmap to reflect the terrain plane.UpdateHeights(HeightMap); plane.mesh.Optimize(); // Add the newly generated mesh to the mesh collider // (for some reason it can't find it otherwise?) gameObject.GetComponent<MeshCollider>().sharedMesh = plane.mesh; }
public static PlaneMesh GetPlane(int pxWidth, int pxHeight, string planeGOName = "PlaneMesh", bool addBrowser = false, string initialURL = "") { float worldWidth = metersPerPixel * pxWidth; float worldHeight = metersPerPixel * pxHeight; GameObject planeMeshGO = CreatePlane(worldWidth, worldHeight, planeGOName); PlaneMesh newPlane = new PlaneMesh(planeMeshGO, worldWidth, worldHeight); if (planeMeshGO == null) { Debug.LogError("Public Browser failed to instantiate"); } if (addBrowser) { CollabBrowserTexture bTex = planeMeshGO.AddComponent <CollabBrowserTexture>(); bTex.Width = pxWidth; bTex.Height = pxHeight; bTex.InitialURL = initialURL; } return(newPlane); }
public virtual void Initialize() { MeshFilter mf = GetComponent <MeshFilter>(); if (mf != null) { MeshCollider mc = GetComponent <MeshCollider>(); if (mc == null) { mc = gameObject.AddComponent <MeshCollider>(); mc.sharedMesh = mf.mesh; } if (useScaleForPixelDimensions) { pixelHeight = PanelHelpers.GetPxHeightFromTransform(this.transform, pixelWidth); } bTex = gameObject.AddComponent <CollabBrowserTexture>(); bTex.Width = pixelWidth; bTex.Height = pixelHeight; bTex.id = bssId; bTex.InitialURL = url; bTex.KeyInputEnabled = false; bTex.blacklistRequestURLFragments.AddRange(blacklistRequestURLFragments); bTex.requestReplacements = requestReplacements; bTex.LoadingTexture = refreshTex; bTex.FocusChange += OnFocusChange; } else { PlaneMesh bPlane = PlaneMeshFactory.GetPlane(pixelWidth, pixelHeight, gameObject.name + "-bplane", true, url); bTex = bPlane.go.GetComponent <CollabBrowserTexture>(); } bTex.AllowURLChanges = false; bTex.AddLoadCompleteEventListener(OnLoadCompleted); // web panel for focus control WebPanel webPanel = gameObject.AddComponent <WebPanel>(); webPanel.focusCameraOnInputFieldClick = false; // not currently needed for bizsim panels }
public override void _Ready() { mesh = new PlaneMesh(); float sizeX = mesh.Size.x; float sizeY = mesh.Size.y; grass = new SpatialMaterial(); grass.AlbedoColor = Color.Color8(100, 200, 25); water = new SpatialMaterial(); water.AlbedoColor = Color.Color8(0, 130, 200); for (uint i = 0; i < tilemap.GetLength(0); i++) { for (uint j = 0; j < tilemap.GetLength(1); j++) { MeshInstance tile = new MeshInstance(); tile.Mesh = mesh; tile.Translate(new Vector3(j * sizeX, 0, i * sizeY)); if (tilemap[i, j] == 0) { tile.MaterialOverride = grass; tile.SetMeta("type", "grass"); } else if (tilemap[i, j] == 1) { tile.MaterialOverride = water; tile.SetMeta("type", "water"); } AddChild(tile); } } }
public override void _Ready() { var env = GetNode <WorldEnvironment>("sky").Environment; env.BackgroundMode = Godot.Environment.BGMode.Sky; env.BackgroundSky = new PanoramaSky() { Panorama = ((Texture)GD.Load("res://assets/park.hdr")) }; env.BackgroundSkyRotationDegrees = new Vector3(0, 140, 0); GD.Load <AudioStream>("res://assets/field.ogg").Play(Audio); var sun1 = new DirectionalLight() { LightEnergy = 0.4f }; var sun2 = new DirectionalLight() { LightEnergy = 0.4f, LightIndirectEnergy = 0 }; sun2.RotationDegrees = new Vector3(-62, -145, 0); AddChild(sun1); AddChild(sun2); InitSound(); AddChild(Audio); var gMat = new ShaderMaterial() { Shader = new Shader() { Code = @" shader_type spatial; render_mode blend_mix,depth_draw_opaque,cull_disabled,diffuse_burley,specular_schlick_ggx; uniform vec4 albedo : hint_color; uniform sampler2D texture_albedo : hint_albedo; uniform float freq = 2f; uniform float range = 2f; uniform float pow = 0.1; void vertex() { if (VERTEX.y > 0.0) { vec3 vertPos = (vec4(VERTEX, 1.0) * WORLD_MATRIX).xyz; float disp = sin(vertPos.x * range + TIME * freq) * pow; VERTEX.x += disp; VERTEX.z += disp; } } void fragment() { vec2 base_uv = UV; vec4 albedo_tex = texture(texture_albedo,base_uv); ALBEDO = albedo.rgb * albedo_tex.rgb; METALLIC = 0f; SPECULAR = 0.5; ROUGHNESS = 1f; ALPHA = albedo.a * albedo_tex.a; ALPHA_SCISSOR=0.6; }" } }; gMat.SetShaderParam("albedo", new Color("ff999900")); gMat.SetShaderParam("texture_albedo", GD.Load <Texture>("res://assets/grass5.png")); var bMat = new ShaderMaterial() { Shader = new Shader() { Code = @" shader_type spatial; render_mode blend_mix,depth_draw_opaque,cull_disabled,diffuse_burley,specular_schlick_ggx; uniform vec4 albedo : hint_color; uniform sampler2D texture_albedo : hint_albedo; uniform float freq = 16f; uniform float range = 0.7f; void vertex() { VERTEX.y += sin(TIME * freq) * (1.0 - sin(3.14 * UV.x)) * range; } void fragment() { vec2 base_uv = UV; vec4 albedo_tex = texture(texture_albedo,base_uv); ALBEDO = albedo.rgb * albedo_tex.rgb; METALLIC = 0f; SPECULAR = 0.5; ROUGHNESS = 1f; ALPHA = albedo.a * albedo_tex.a; ALPHA_SCISSOR=0.6; }" } }; bMat.SetShaderParam("albedo", new Color("ffffffff")); bMat.SetShaderParam("texture_albedo", GD.Load <Texture>("res://assets/butterfly.png")); float height = 0; for (int i = -3; i < 30; i++) { for (int j = -3; j < 3; j++) { var gInt = (Spatial)GD.Load <PackedScene>("res://scenes/Grass.tscn").Instance(); var gmesh = gInt.GetNode <MeshInstance>("Grass"); gmesh.MaterialOverride = gMat; var tempScale = gInt.Scale; tempScale.y *= 0.8f; tempScale *= (float)GD.RandRange(0.3f, 0.7f); gInt.Scale = tempScale; gInt.RotateY(Mathf.Deg2Rad((float)GD.RandRange(-180, 180))); if ((i % 2) == 0) { gInt.Translation = new Vector3(i, height -= 0.04f, j); } else { gInt.Translation = new Vector3(i, height, j + 0.5f); } void AddAdditionalGrass(Vector3 pos) { var additionalGrass2 = (Spatial)gInt.Duplicate(); var gmat2 = (ShaderMaterial)gMat.Duplicate(); gmat2.SetShaderParam("albedo", new Color("ff999900")); additionalGrass2.GetNode <MeshInstance>("Grass").MaterialOverride = gmat2; additionalGrass2.Translate(pos); AddChild(additionalGrass2); } if (i < 5) { AddAdditionalGrass(new Vector3(1.5f, 0, 0)); AddAdditionalGrass(new Vector3(-1.5f, 0, 0)); } if (i > 10) { AddAdditionalGrass(new Vector3(0, 0, 11f)); AddAdditionalGrass(new Vector3(0, 0, -11f)); } AddChild(gInt); } } var bMesh = new PlaneMesh() { Size = new Vector2(1, 1), SubdivideDepth = 1, SubdivideWidth = 1, Material = bMat }; var bPartR = new CPUParticles() { Mesh = bMesh, Scale = Scale * 0.3f, Gravity = new Vector3(0, 0, 0), Direction = new Vector3(0, 0, -1), InitialVelocity = 30, Amount = 30, Spread = 30, Lifetime = 20, InitialVelocityRandom = 0.80f, EmissionShape = CPUParticles.EmissionShapeEnum.Sphere, EmissionSphereRadius = 1, }; AddChild(bPartR); var bPartL = (CPUParticles)bPartR.Duplicate(); AddChild(bPartL); bPartR.Translate(new Vector3(15, 5, 25)); bPartL.RotationDegrees = new Vector3(0, 180, 0); bPartL.Translate(new Vector3(-15, 5, 25)); }
protected override bool OnAttached() { var attached = base.OnAttached(); if (attached) { this.transform.ScaleChanged += this.Transform_ScaleChanged; // Add components to owner entity this.materialComponent = new MaterialComponent(); this.meshRenderer = new MeshRenderer(); this.planeMesh = new PlaneMesh(); this.noesisFramebufferPanel = new NoesisFramebufferPanel() { BackgroundColor = WaveEngine.Common.Graphics.Color.Transparent, PPAAEnabled = true, EnableKeyboard = false, EnableMouse = false, EnableTouch = false, }; // Set property values this.planeMesh.Width = 1f; this.planeMesh.Height = 1f; this.noesisFramebufferPanel.TessellationQuality = this.Quality; // Build FrameworkElement this.textBlock = this.BuildTextBlock(); this.textBlock.Text = this.Text; this.textBlock.FontSize = this.FontSize; this.frameworkElement = this.BuildFrameworkElement(); this.noesisFramebufferPanel.FrameworkElement = this.frameworkElement; // Noesis framebuffer configuration if (this.noesisFramebufferPanel.FrameBuffer == null) { this.noesisFramebuffer = this.graphicsContext.Factory.CreateFrameBuffer(this.noesisFramebufferPanel.Width, this.noesisFramebufferPanel.Height); this.noesisFramebufferPanel.FrameBuffer = this.noesisFramebuffer; } // Material initialization if (this.materialComponent.Material == null) { var effect = this.assetsService.Load <Effect>(DefaultResourcesIDs.StandardEffectID); this.standardMaterial = new StandardMaterial(effect) { Id = this.Id, LightingEnabled = false, IBLEnabled = false, LayerDescription = this.assetsService.Load <RenderLayerDescription>(DefaultResourcesIDs.AlphaRenderLayerID) }; this.materialComponent.Material = this.standardMaterial.Material; } else { this.standardMaterial = new StandardMaterial(this.materialComponent.Material); } this.standardMaterial.Alpha = this.Alpha; // Update Noesis panel framebuffer this.UpdateNoesisPanelFramebuffer(); // Add container entity and components (bug workaround) var containerEntity = new Entity("components") { Flags = HideFlags.DontSave, } .AddComponent(new Transform3D()) .AddComponent(this.materialComponent) .AddComponent(this.meshRenderer) .AddComponent(this.planeMesh) .AddComponent(this.noesisFramebufferPanel) ; this.Owner.AddChild(containerEntity); } return(attached); }
public void TestPlaneMesh() { XNAGame game = new XNAGame(); List <PlaneMesh> meshes = new List <PlaneMesh>(); bool wireframe = false; game.InitializeEvent += delegate { PlaneMesh mesh; mesh = new PlaneMesh(10, 10, Color.White); mesh.Initialize(game); meshes.Add(mesh); mesh = new PlaneMesh(100, 100, Color.White); mesh.WorldMatrix = Matrix.CreateTranslation(150, 0, 150); mesh.Initialize(game); meshes.Add(mesh); }; game.UpdateEvent += delegate { if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.W)) { wireframe = !wireframe; } }; game.DrawEvent += delegate { game.LineManager3D.AddAABB(meshes[1].BoundingBox, Matrix.Identity, Color.Red); int i; if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.R)) { for (i = 0; i < meshes.Count; i++) { meshes[i].ReloadShader(game); } } game.GraphicsDevice.RenderState.FillMode = FillMode.Solid; game.GraphicsDevice.RenderState.CullMode = CullMode.None; if (!wireframe) { for (i = 1; i < meshes.Count; i++) { meshes[i].Render(game); } } i = 0; meshes[i].Color = Color.LightGreen; meshes[i].Render(game); game.GraphicsDevice.RenderState.CullMode = CullMode.CullClockwiseFace; meshes[i].Color = Color.Red; meshes[i].Render(game); game.GraphicsDevice.RenderState.FillMode = FillMode.WireFrame; game.GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace; meshes[i].Color = Color.Black; meshes[i].Render(game); if (wireframe) { for (i = 1; i < meshes.Count; i++) { meshes[i].Render(game); } } }; game.Run(); }
// Use this for initialization void Start() { _planeMesh = GetComponent<PlaneMesh>(); }
// Start is called before the first frame update //find the scripts and then generate the inital terrain using default values void Start() { planeMesh = FindObjectOfType <PlaneMesh>(); inputHandler = FindObjectOfType <InputHandler>(); EditTerrain(); }
private void UpdateSelectionHighlight() { if (selection.Is3D()) { GD.Print("3D Selections are not implemented!"); GetNode <MeshInstance>("2DSelectionHighlight").Hide(); return; } var(start, end, normal) = selection.GetSelectionTuple(); if (normal == Vector3.Zero) { GetNode <MeshInstance>("2DSelectionHighlight").Hide(); return; } MeshInstance selectionHighlight2d = GetNode <MeshInstance>("2DSelectionHighlight"); PlaneMesh planeMesh = (PlaneMesh)selectionHighlight2d.Mesh; selectionHighlight2d.Translation = Vector3.Zero; if (normal == Vector3.Up) { planeMesh.Size = new Vector2(Math.Abs(start.x - end.x) + 1.0f, Math.Abs(start.z - end.z) + 1.0f); selectionHighlight2d.Rotation = Vector3.Zero; selectionHighlight2d.Translation = new Vector3((end.x - start.x) / 2.0f + start.x + 0.5f, start.y + 1.01f, (end.z - start.z) / 2.0f + start.z + 0.5f); } else if (normal == Vector3.Down) { planeMesh.Size = new Vector2(Math.Abs(start.x - end.x) + 1.0f, Math.Abs(start.z - end.z) + 1.0f); selectionHighlight2d.Rotation = new Vector3(Mathf.Pi, 0, 0); selectionHighlight2d.Translation = new Vector3((end.x - start.x) / 2.0f + start.x + 0.5f, start.y - 0.01f, (end.z - start.z) / 2.0f + start.z + 0.5f); } else if (normal == Vector3.Left) { planeMesh.Size = new Vector2(Math.Abs(start.y - end.y) + 1.0f, Math.Abs(start.z - end.z) + 1.0f); selectionHighlight2d.Rotation = new Vector3(0, 0, Mathf.Pi / 2); selectionHighlight2d.Translation = new Vector3(start.x - 0.01f, (end.y - start.y) / 2.0f + start.y + 0.5f, (end.z - start.z) / 2.0f + start.z + 0.5f); } else if (normal == Vector3.Right) { planeMesh.Size = new Vector2(Math.Abs(start.y - end.y) + 1.0f, Math.Abs(start.z - end.z) + 1.0f); selectionHighlight2d.Rotation = new Vector3(0, 0, -Mathf.Pi / 2); selectionHighlight2d.Translation = new Vector3(start.x + 1.01f, (end.y - start.y) / 2.0f + start.y + 0.5f, (end.z - start.z) / 2.0f + start.z + 0.5f); } else if (normal == Vector3.Forward) { planeMesh.Size = new Vector2(Math.Abs(start.x - end.x) + 1.0f, Math.Abs(start.y - end.y) + 1.0f); selectionHighlight2d.Rotation = new Vector3(-Mathf.Pi / 2, 0, 0); selectionHighlight2d.Translation = new Vector3((end.x - start.x) / 2.0f + start.x + 0.5f, (end.y - start.y) / 2.0f + start.y + 0.5f, start.z - 0.01f); } else if (normal == Vector3.Back) { planeMesh.Size = new Vector2(Math.Abs(start.x - end.x) + 1.0f, Math.Abs(start.y - end.y) + 1.0f); selectionHighlight2d.Rotation = new Vector3(Mathf.Pi / 2, 0, 0); selectionHighlight2d.Translation = new Vector3((end.x - start.x) / 2.0f + start.x + 0.5f, (end.y - start.y) / 2.0f + start.y + 0.5f, start.z + 1.01f); } selectionHighlight2d.Show(); }
// Use this for initialization void Start() { _planeMesh = GetComponent <PlaneMesh>(); }
// returns the distance that will fill the screen with the plane widthwise static public float GetCameraDistFromPlane(PlaneMesh plane, Camera cam) { return(GetCameraDistFromPlaneHeight(plane.worldHeight, cam.fieldOfView)); }
public override void _Ready() { var mesh = new PlaneMesh(); mesh.Size = new Vector2(size, size); mesh.SubdivideDepth = 3; mesh.SubdivideWidth = (int)position.x == 0 ? (int)size : 3; var surface_tool = new SurfaceTool(); surface_tool.CreateFrom(mesh, 0); var mesh_tool = new MeshDataTool(); mesh_tool.CreateFromSurface(surface_tool.Commit(), 0); var biome = GetBiome(/*hydro_noise.GetNoise2dv(position / size), */ heat_noise.GetNoise2d(position.x / size / 10.0f, position.y)); for (int i = 0; i < mesh_tool.GetVertexCount(); ++i) { var vertex = mesh_tool.GetVertex(i); var vertex_global_pos = position + new Vector2(vertex.x, vertex.z); var height_noise_val = height_noise.GetNoise2dv(vertex_global_pos); vertex.y = height_noise_val * 20; var color_factor = (height_noise_val + 1) / 2.0f; var hydro_val = (int)Math.Round(hydro_noise.GetNoise2dv(vertex_global_pos)); if ((int)vertex.x == 0 && (int)position.x == 0) { mesh_tool.SetVertexColor(i, new Color(color_factor, color_factor / 2, 0.0f)); } else if (hydro_val == -1) { mesh_tool.SetVertexColor(i, biome.dry_color * color_factor); } else if (hydro_val == 1) { mesh_tool.SetVertexColor(i, biome.humid_color * color_factor); } else { mesh_tool.SetVertexColor(i, biome.ground_color * color_factor); } mesh_tool.SetVertex(i, vertex); } /*if (base_tree_mesh == null && ResourceLoader.Exists("res://assets/tree.obj")) * { * base_tree_mesh = ResourceLoader.Load<Mesh>("res://assets/tree.obj"); * } * if (base_tree_material == null && ResourceLoader.Exists("res://assets/tree.tres")) * { * Console.WriteLine("OK"); * base_tree_material = ResourceLoader.Load<SpatialMaterial>("res://assets/tree.tres"); * } * * MultiMesh trees = new MultiMesh(); * trees.Mesh = base_tree_mesh; * trees.TransformFormat = MultiMesh.TransformFormatEnum.Transform3d; * * if ((int)position.x == 0) * { * var points1 = Utility.UniformPoissonDiskSampler.SampleRectangle(-new Vector2(size, size) / 2, new Vector2(-5, size / 2.0f), biome.tree_spacing); * var points2 = Utility.UniformPoissonDiskSampler.SampleRectangle(new Vector2(5, 0), new Vector2(size, size) / 2, biome.tree_spacing); * trees.InstanceCount = points1.Count + points2.Count; * * int i = 0; * foreach (var p in points1) * { * trees.SetInstanceTransform(i, Transform.Identity.Scaled(new Vector3(1, biome.tree_size, 1)).Translated(new Vector3(p.x, height_noise.GetNoise2dv(position + p) * 20, p.y))); ++i; * } * * foreach (var p in points2) * { * trees.SetInstanceTransform(i, Transform.Identity.Scaled(new Vector3(1, biome.tree_size, 1)).Translated(new Vector3(p.x, height_noise.GetNoise2dv(position + p) * 20, p.y))); ++i; * } * } * else * { * var points = Utility.UniformPoissonDiskSampler.SampleRectangle(-new Vector2(size, size) / 2, new Vector2(size, size) / 2, biome.tree_spacing); * trees.InstanceCount = points.Count; * int i = 0; * foreach (var p in points) * { * trees.SetInstanceTransform(i, Transform.Identity.Scaled(new Vector3(1, biome.tree_size, 1)).Translated(new Vector3(p.x, height_noise.GetNoise2dv(position + p) * 20, p.y))); ++i; * } * } * * MultiMeshInstance child = new MultiMeshInstance(); * child.Multimesh = trees; * child.MaterialOverride = base_tree_material; * AddChild(child);*/ var array = new ArrayMesh(); mesh_tool.CommitToSurface(array); Mesh = array; if (base_shader == null && ResourceLoader.Exists("res://assets/chunk_shader.tres")) { base_shader = ResourceLoader.Load <ShaderMaterial>("res://assets/chunk_shader.tres"); } var shader = base_shader; MaterialOverride = shader; }