// For when you want a spatial material that represents a color. public static Material GetColorSpatialMaterial(Vector3 color) { SpatialMaterial ret = new SpatialMaterial(); ret.AlbedoColor = Color(color); return(ret); }
private MeshInstance generate_joint_mesh() { MeshInstance j_mesh = new MeshInstance(); // Create sphere SphereMesh m_mesh = new SphereMesh(); m_mesh.Radius = 0.05F; m_mesh.Height = 0.1F; m_mesh.RadialSegments = 5; m_mesh.Rings = 5; // Create material SpatialMaterial m_mat = new SpatialMaterial(); m_mat.AlbedoColor = new Color(0.26F, 0.32F, 0.92F); m_mat.EmissionEnabled = true; m_mat.Emission = new Color(0.4F, 0.3F, 1.0F); m_mat.EmissionEnergy = 3.0F; j_mesh.Mesh = m_mesh; j_mesh.MaterialOverride = m_mat; return(j_mesh); }
public static void UpdateDrawLine3D() { if (Line3D.Count > 0) { if (!Node.IsInstanceValid(instance)) { Scene.Current.AddChild(instance = new DrawDebugLine3D()); instance.Owner = Scene.Current; var mat = new SpatialMaterial(); instance.MaterialOverride = mat; mat.VertexColorUseAsAlbedo = true; mat.FlagsUnshaded = true; mat.FlagsDoNotReceiveShadows = true; } instance.Clear(); instance.Begin(Mesh.PrimitiveType.Lines); foreach (var line in Line3D) { instance.SetColor(line.color); instance.AddVertex(line.origin); instance.AddVertex(line.end); } instance.End(); Line3D.Clear(); } else if (Node.IsInstanceValid(instance)) { instance.QueueFree(); } }
private List <Spatial> create_links(int N) { List <Spatial> links = new List <Spatial>(); PhysicsMaterial link_phys_mat = new PhysicsMaterial(); SpatialMaterial link_mesh_mat = new SpatialMaterial(); link_mesh_mat.AlbedoColor = new Color(0.5F, 0.5F, 0.5F, 1F); for (int i = 0; i <= N; i++) { RigidBody link = new RigidBody(); link.Name = String.Format("l{0}", i); link.CanSleep = false; link.ContinuousCd = true; Vector3 link_dimensions = new Vector3(0.2F, 0.8F, 0.1F); MeshInstance link_mesh = create_link_mesh( String.Format("{0}_mesh", link.Name), link_dimensions, link_mesh_mat); CollisionShape link_col = create_link_collision( String.Format("{0}_col", link.Name), link_dimensions); link.AddChild(link_mesh); link.AddChild(link_col); links.Add(link); } return(links); }
// Called when the node enters the scene tree for the first time. public override void _Ready() { if (bulletStartPos == null) { bulletStartPos = new Vector3(); } if (bulletEndPos == null) { bulletEndPos = bulletStartPos; } bulletPos = bulletStartPos; stepPoints = new Dictionary(); collisionList = new Array <PhysicsBody>(); decal = ResourceLoader.Load <PackedScene>("res://Scenes/Decals/BulletHole.tscn"); debugDrawNode = Main.instance.GetNode("DebugDraw") as ImmediateGeometry; material = new SpatialMaterial(); material.FlagsUnshaded = true; material.FlagsUsePointSize = true; material.FlagsNoDepthTest = true; debugDrawNode.MaterialOverride = material; debugDrawNode2 = Main.instance.GetNode("DebugDrawPen") as ImmediateGeometry; material2 = new SpatialMaterial(); material2.FlagsUnshaded = true; material2.FlagsUsePointSize = true; material2.FlagsNoDepthTest = true; material2.AlbedoColor = Colors.Red; debugDrawNode2.MaterialOverride = material2; }
void PopulateTrees(Node parent) { PackedScene scene = ResourceLoader.Load <PackedScene>("res://src/env/Tree.tscn"); SpatialMaterial[] trees = new SpatialMaterial[8] { ResourceLoader.Load <SpatialMaterial>("res://assets/env/tree_0.tres"), ResourceLoader.Load <SpatialMaterial>("res://assets/env/tree_1.tres"), ResourceLoader.Load <SpatialMaterial>("res://assets/env/tree_2.tres"), ResourceLoader.Load <SpatialMaterial>("res://assets/env/tree_3.tres"), ResourceLoader.Load <SpatialMaterial>("res://assets/env/tree_dead_0.tres"), ResourceLoader.Load <SpatialMaterial>("res://assets/env/tree_dead_1.tres"), ResourceLoader.Load <SpatialMaterial>("res://assets/env/tree_dead_2.tres"), ResourceLoader.Load <SpatialMaterial>("res://assets/env/tree_dead_3.tres") }; for (int i = 0; i < 2500; i++) { StaticBody tree = (StaticBody)scene.Instance(); tree.Translation = new Vector3((float)RandRange(-50f, 50f), 0f, (float)RandRange(-50f, 50f)); bool tiny = Randf() <= 0.015f; tree.Scale = Vector3.One * (float)RandRange(1f, 1.5f) * (tiny ? 0.5f : 1f); MeshInstance mesh = tree.GetNode <MeshInstance>("MeshInstance"); bool dead = Randf() <= 0.15f; mesh.MaterialOverride = trees[Randi() % 4 + (dead ? 4 : 0)]; AddChildBelowNode(parent, tree); } }
public override void _Process(float Delta) { Camera Cam = GetViewport().GetCamera(); if (Cam != null) { Translation = Cam.GlobalTransform.origin; } SpatialMaterial Mat = ((SpatialMaterial)SingleStar.GetSurfaceMaterial(0)); Color Old = Mat.AlbedoColor; if (World.TimeOfDay > 0 && World.TimeOfDay < 30f * World.DayNightMinutes) //Daytime { Mat.AlbedoColor = new Color(Old.r, Old.g, Old.b, 0); } else { float Power = 0; if (World.TimeOfDay < 45f * World.DayNightMinutes) { //After sunset Power = (World.TimeOfDay - (30f * World.DayNightMinutes)) / (18f * World.DayNightMinutes); Power = Clamp(Power, 0, 1); } else { //Before sunrise Power = Abs(World.TimeOfDay - (60f * World.DayNightMinutes)) / (18f * World.DayNightMinutes); Power = Clamp(Power, 0, 1); } Mat.AlbedoColor = new Color(Old.r, Old.g, Old.b, Clamp(Power, 0, 1)); } }
// TODO /// <summary> /// <para>CreateVisualGeometry</para> /// Parses a ROS link and creates a MeshInstance for the visual /// geometry specified in that link. /// </summary> /// <param name="visuals">List of visuals stored in the Urdf link.</param> /// <returns> /// <para> /// A mesh containing the accurate visual geometry of the link if no error. /// <para> /// <para> /// Null if there was an error. /// </para></returns> public Godot.Mesh CreateVisualGeometry(List <Link.Visual> visuals) { // The union of the geometries defined in the list define // the end visual of the link, but for now we will just use // the first one if (visuals.Count < 1) { return(null); } Link.Visual workingVis = visuals[0]; // Create the material if it exists SpatialMaterial linkMat = CreateMaterial(workingVis.material); // Create the meshs if (workingVis.geometry.box != null) { return(CreateBox(workingVis.geometry.box, linkMat)); } if (workingVis.geometry.cylinder != null) { return(CreateCylinder(workingVis.geometry.cylinder, linkMat)); } if (workingVis.geometry.sphere != null) { return(CreateSphere(workingVis.geometry.sphere, linkMat)); } if (workingVis.geometry.mesh != null) { return(CreateMesh(workingVis.geometry.mesh).Mesh); } return(null); }
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; }
// Called when the node enters the scene tree for the first time. public override void _Ready() { DensityField = new float[ChunkWidth + 1, ChunkHeight + 1, ChunkWidth + 1]; if (ChunkWidth == 0) { ChunkWidth = 20; } if (ChunkHeight == 0) { ChunkHeight = 20; } Clear(); Begin(Mesh.PrimitiveType.Triangles); SpatialMaterial sp = new SpatialMaterial(); sp.ParamsCullMode = SpatialMaterial.CullMode.Disabled; sp.AlbedoColor = new Color(250, 0, 0, 1); this.MaterialOverride = sp; DensityCompute(); Marcher(); Visible = true; End(); GD.Print(Vertices.Count); }
public override void _Ready() { currentVelocity = initialVelocity; Universe.spaceBodies.Add(this); float r = radius / Universe.scaleFactor; MeshInstance meshInstance = new MeshInstance(); meshInstance.Mesh = new SphereMesh(); //just once! meshInstance.Scale = new Vector3(r, r, r); SpatialMaterial mat = new SpatialMaterial(); mat.AlbedoColor = color; meshInstance.Mesh.SurfaceSetMaterial(0, mat); AddChild(meshInstance); var area = new Area(); var colissionShape = new CollisionShape(); var SphereShape = new SphereShape(); SphereShape.Radius = r; colissionShape.Shape = SphereShape; area.AddChild(colissionShape); AddChild(area); area.Connect("input_event", this, nameof(_OnSelect)); }
public static Material GetSprite(int idx) { Material ret = _vswapSprite.ContainsKey(idx) ? _vswapSprite[idx] : null; if (ret == null) { byte[] data = new byte[VSWAP.SpriteSize.Width * VSWAP.SpriteSize.Height * 4]; SpatialMaterial mat = new SpatialMaterial(); ImageTexture tex = new ImageTexture(); Image img = new Image(); System.Drawing.Bitmap bmp = VSWAP.GetSpriteBitmap(Palette, (uint)idx); int stride = VSWAP.SpriteSize.Width * 4; for (int y = 0; y < VSWAP.SpriteSize.Height; y++) { for (int x = 0; x < VSWAP.SpriteSize.Width; x++) { System.Drawing.Color pixel = bmp.GetPixel(x, y); data[(stride * y) + (x * 4) + 0] = pixel.R; data[(stride * y) + (x * 4) + 1] = pixel.G; data[(stride * y) + (x * 4) + 2] = pixel.B; if (pixel.R == Transparent.r8 && pixel.G == Transparent.g8 && pixel.B == Transparent.b8) { data[(stride * y) + (x * 4) + 3] = 0; } else { data[(stride * y) + (x * 4) + 3] = 255; } } } img.CreateFromData( VSWAP.SpriteSize.Width, VSWAP.SpriteSize.Height, false, Image.Format.Rgba8, data); tex.CreateFromImage(img, (uint)0); mat.AlbedoTexture = tex; mat.ParamsCullMode = SpatialMaterial.CullMode.Disabled; mat.ParamsBillboardMode = SpatialMaterial.BillboardMode.FixedY; ret = mat; _vswapSprite.Add(idx, ret); } return(ret); }
public static void uniqueMaterialWithClickableEmission(MeshInstance mesh, out SpatialMaterial material) { // copy the material to be able to set different seedssss material = (SpatialMaterial)mesh.GetSurfaceMaterial(0).Duplicate(true); MaterialUtils.setClickableEmission(material); mesh.SetSurfaceMaterial(0, material); }
public override void _Ready() { VisualServer.SetDebugGenerateWireframes(true); MaterialOverride = new SpatialMaterial { AlbedoTexture = TextureAtlas.instance.atlas, ParamsCullMode = SpatialMaterial.CullMode.Back }; UseInBakedLight = true; }
public override void _Ready() { bookAnim = GetChild <AnimationPlayer>(0); rightPageMat = GetNode <MeshInstance>(rightPage).GetSurfaceMaterial(0) as SpatialMaterial; leftPageMat = GetNode <MeshInstance>(leftPage).GetSurfaceMaterial(0) as SpatialMaterial; CallDeferred(nameof(DeferredReady)); instance = this; }
public static SpatialMaterial setClickableEmission(SpatialMaterial material) { material.Emission = Color.Color8(255, 255, 255); material.EmissionEnergy = 0.05F; material.EmissionOperator = 0; material.EmissionOnUv2 = false; return(material); }
public static void Paint(Spatial obj, Color color) { SpatialMaterial material = new SpatialMaterial(); material.AlbedoColor = color; material.FlagsTransparent = true; ((MeshInstance)obj).MaterialOverride = material; }
//public void Update(float timeLeft, float totalTime) //{ //text.Text = // //} private void _on_Timer_timeout() { var img = GetNode <Viewport>("Viewport").GetTexture(); var mat = new SpatialMaterial(); mat.FlagsTransparent = true; mat.AlbedoTexture = img; SetSurfaceMaterial(0, mat); }
private void setTankColor(Color c) { foreach (MeshInstance mesh in new MeshInstance[] { trackleft, trackright, body, (MeshInstance)GetNode("Turret/TurretMesh"), gun }) { // need to use Duplicate() or we change the color of both tanks, they share the SpatialMaterial reference SpatialMaterial mat = (SpatialMaterial)mesh.GetSurfaceMaterial(0).Duplicate(true); mat.AlbedoColor = c; mesh.SetSurfaceMaterial(0, mat); } }
public void InitCard(Texture Texture) { if (cardPicture.GetSurfaceMaterial(0) is SpatialMaterial) { var uniqueMaterial = (SpatialMaterial)cardPicture.GetSurfaceMaterial(0).Duplicate(); SpatialMaterial cardPictureMaterial = uniqueMaterial; uniqueMaterial.AlbedoTexture = pictureTexture; cardPicture.SetSurfaceMaterial(0, uniqueMaterial); } }
private void uniqueMaterial() { var mesh = (MeshInstance)GetNode("DepotMesh"); // copy the material to be able to set different seeds material = (SpatialMaterial)mesh.GetSurfaceMaterial(0).Duplicate(true); MaterialUtils.setClickableEmission(material); mesh.SetSurfaceMaterial(0, material); }
private void GenerateMesh() { ArrayMesh mesh = MeshGenerator.GenerateMesh(noiseMap, MeshHeightMultiplier, MeshHeightCurve, LevelOfDetail); MeshInstance meshInstance = GetNode<MeshInstance>("MeshInstance"); meshInstance.Mesh = mesh; meshInstance.CreateTrimeshCollision(); SpatialMaterial material = new SpatialMaterial(); material.AlbedoTexture = TextureGenerator.GenerateColorTexture(noiseMap, RegionThresholds, RegionColors); mesh.SurfaceSetMaterial(0, material); }
public Chunk(Vector3 position, SpatialMaterial m) { chunk = new Spatial { Name = Mundo.MontaNomeDoChunk(position) }; Name = chunk.Name; chunk.Translation = position; material = m; BuildChunk(); }
// // Called every frame. 'delta' is the elapsed time since the previous frame. // public override void _Process(float delta) // { // // } // Cube contructor public Cube(PlanetChunk owner, int currentX, int currentY, int currentZ, Vector3 cubePosition, SpatialMaterial cubeMaterial) { this.owner = owner; cubeLocation = cubePosition; this.cubeMaterial = cubeMaterial; cube = new CSGCombiner(); // TODO: keep as CSGCombiner or change to Spatial? this.currentX = currentX; this.currentY = currentY; this.currentZ = currentZ; }
public override void _Ready() { Mesh = GetNode <MeshInstance>("cube/Icosphere001"); Material = (SpatialMaterial)Mesh.Mesh.SurfaceGetMaterial(0); Tween = GetNode <Tween>("Tween"); Connect("area_entered", this, nameof(OnAreaEntered)); initialMeshTransform = Transform; Tween.InterpolateProperty(Material, "albedo_color", Colors.White, Colors.Red, 1, Tween.TransitionType.Sine, Tween.EaseType.InOut); Tween.Start(); }
public override void _Ready() { Translate(new Vector3((float)GD.RandRange(5, 10), 0, (float)GD.RandRange(0, 10))); var bub = GetNode <MeshInstance>("BubblePhysics/BubbleCollision/Bubble"); var mat = new SpatialMaterial(); mat.AlbedoColor = Color.FromHsv(GD.Randf(), 1, 1); mat.EmissionEnabled = true; mat.Emission = Color.FromHsv(GD.Randf(), 1, 1); mat.EmissionEnergy = 1; bub.MaterialOverride = mat; }
public override void _Ready() { head = GetNode <Area>("Head"); healthBar = GetNode <ProgressBar>("Control/Health"); progressBar = GetNode <ProgressBar>("Control/Progress"); material = GD.Load <SpatialMaterial>("res://Materials/1.tres"); obstacleScene = GD.Load <PackedScene>("res://Scenes/ObstacleBody.tscn"); timer = GetNode <Timer>("Spawner"); cursor = GetNode <Sprite>("Control/Cursor"); Input.SetMouseMode(Input.MouseMode.Visible); }
public override void _Ready() { //base._Ready(); if (_surfaceMaterial == null) { _surfaceMaterial = new SpatialMaterial(); _surfaceMaterial.FlagsUnshaded = true; _surfaceMaterial.FlagsVertexLighting = true; _surfaceMaterial.VertexColorUseAsAlbedo = true; } LoadWAD(WADPath, levelName); }
public void ChangeTexture(Spatial mesh, string name, string newTextureName, Color newColor) { var mi = mesh.FindNode(name); MeshInstance m = (MeshInstance)mi; SpatialMaterial mat = new SpatialMaterial(); var texture = (Texture)GD.Load(newTextureName); mat.AlbedoTexture = texture; mat.AlbedoColor = newColor; m.MaterialOverride = mat; }
public override void _Ready() { GetNode <RigidBody>("DotPhysics").GravityScale = 0; dotMesh = GetNode <MeshInstance>("DotPhysics/DotCollision/Dot"); var mat = new SpatialMaterial(); mat.AlbedoColor = Color.FromHsv(1, 1, 1, 0); mat.EmissionEnabled = true; mat.Emission = Color.FromHsv(GD.Randf(), 1, 1); mat.EmissionEnergy = 1; dotMesh.MaterialOverride = mat; }