Skip to content

Commit

Permalink
remove more GDscript, rayselector
Browse files Browse the repository at this point in the history
  • Loading branch information
Avnzx committed Jul 21, 2022
1 parent ffdcbf9 commit 8cacc66
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 69 deletions.
Binary file added assets/sky_seamless_texture_5904.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions assets/sky_seamless_texture_5904.jpg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/sky_seamless_texture_5904.jpg-5347084fd9ca296efb07adce2272c008.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://assets/sky_seamless_texture_5904.jpg"
dest_files=[ "res://.import/sky_seamless_texture_5904.jpg-5347084fd9ca296efb07adce2272c008.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
1 change: 1 addition & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ toggle_map={
[layer_names]

3d_physics/layer_2="player"
3d_physics/layer_3="icosphere_faces"

[network]

Expand Down
2 changes: 1 addition & 1 deletion scenes/icosphere/Main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[ext_resource path="res://scripts/icosphere/Camera.gd" type="Script" id=1]
[ext_resource path="res://scripts/icosphere/IcoSphere.cs" type="Script" id=2]
[ext_resource path="res://scripts/icosphere/label.gd" type="Script" id=3]
[ext_resource path="res://scripts/icosphere/RaySelector.cs" type="Script" id=3]
[ext_resource path="res://scripts/util/mouse_speed.gd" type="Script" id=4]
[ext_resource path="res://scenes/icosphere/default_env.tres" type="Environment" id=5]

Expand Down
4 changes: 2 additions & 2 deletions scenes/icosphere/shader.tres
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[gd_resource type="Shader" format=2]

[resource]
code = "shader_type canvas_item;
code = "shader_type spatial;

void fragment(){
void vertex(){
COLOR = vec4(0.4, 0.6, 0.9, 1.0);
}"
28 changes: 21 additions & 7 deletions scenes/menus/MainMenu.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
[gd_scene format=2]
[gd_scene load_steps=3 format=2]

[sub_resource type="SpatialMaterial" id=1]
flags_vertex_lighting = true

[sub_resource type="SpatialMaterial" id=2]
flags_disable_ambient_light = true
albedo_color = Color( 0.686275, 0.654902, 0.717647, 1 )
roughness = 0.62
clearcoat_enabled = true
clearcoat = 0.83
clearcoat_gloss = 0.67

[node name="Spatial" type="Spatial"]

Expand All @@ -7,20 +18,23 @@ transform = Transform( 0.866025, 0, -0.5, 0, 1, 0, 0.5, 0, 0.866025, -2.29011, 0

[node name="CSGBox" type="CSGBox" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
width = 6.0
depth = 6.0
width = 7.454
height = 1.593
depth = 5.858
material = SubResource( 1 )

[node name="CSGBox" type="CSGBox" parent="CSGBox"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0460715, 1.58279, -2.70092 )
width = 6.0
width = 7.454
height = 5.15782
depth = 0.657439
depth = 0.023
material = SubResource( 2 )

[node name="CSGBox" type="CSGBox" parent="CSGBox/CSGBox"]
transform = Transform( 0.0304862, 0, -0.999535, 0, 1, 0, 0.999535, 0, 0.0304862, 2.61414, -0.10704, 2.91418 )
width = 6.0
width = 7.454
height = 4.79101
depth = 0.657439
depth = 0.023

[node name="DirectionalLight" type="DirectionalLight" parent="."]
transform = Transform( 0.5, 0.224144, -0.836516, 0, 0.965926, 0.258819, 0.866025, -0.12941, 0.482963, -1, 4, 6 )
Expand Down
4 changes: 2 additions & 2 deletions scripts/icosphere/Camera.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ func _process(_delta):

func _unhandled_input(event):
# set a variable and change cursor
if (event is InputEventMouseButton and event.button_mask == BUTTON_MASK_LEFT):
if (event is InputEventMouseButton and event.button_mask == BUTTON_MASK_RIGHT):
_drag = true
Input.set_default_cursor_shape(Input.CURSOR_DRAG)
if (event is InputEventMouseButton and event.button_index == BUTTON_LEFT and not event.pressed):
if (event is InputEventMouseButton and event.button_index == BUTTON_RIGHT and not event.pressed):
_drag = false
Input.set_default_cursor_shape(Input.CURSOR_ARROW)

Expand Down
52 changes: 36 additions & 16 deletions scripts/icosphere/IcoSphere.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class IcoSphere : Node {
private ArrayMesh _array_mesh = new ArrayMesh();
private SurfaceTool _surfacetool = new SurfaceTool();
Godot.Collections.Array faces = new Godot.Collections.Array();
private Godot.Collections.Array facecolliders = new Godot.Collections.Array();



public Vector3[] create_face(Vector3 lla0, Vector3 lla1, Vector3 lla2) {
Expand Down Expand Up @@ -143,30 +145,49 @@ public void CreateShape() {
mi.Mesh = _array_mesh;
AddChild(mi);

// TODO: Create proper collision
// creates child StaticBody, parenting a CollisionShape (MeshInstance -> StaticBody -> CollisionShape)
mi.CreateTrimeshCollision();

// go through each face and create a new ConcaveCollision
// Shape for them, allowing the faces to be selected
for (int i = 0; i < _array_mesh.GetSurfaceCount(); i++) {
Vector3[] surface = (Vector3[]) _array_mesh.SurfaceGetArrays(i)[0];

StaticBody surfacebody = new StaticBody();
surfacebody.Name = "facestaticbody";
this.AddChild(surfacebody,true);

facecolliders.Add(surfacebody);

Vector3[] shapepoints = new Vector3[3];
surface.CopyTo(shapepoints,0);

ConcavePolygonShape collidershape = new ConcavePolygonShape();
collidershape.Data = shapepoints;

uint shapeowner = surfacebody.CreateShapeOwner(surfacebody);
surfacebody.ShapeOwnerAddShape(shapeowner, collidershape);

}


var collider = new ConcavePolygonShape();
var staticbody = new StaticBody();
mi.AddChild(staticbody);
// mi.AddChild(staticbody);

VectorVisualise viz = new VectorVisualise(mi);
// VectorVisualise viz = new VectorVisualise(mi);

Vector3[] single_face = (Vector3[]) faces[0];
MeshInstance _meshistc = mi;
// Vector3[] single_face = (Vector3[]) faces[0];
// MeshInstance _meshistc = mi;

for (int i = 0; i < _array_mesh.GetSurfaceCount(); i++) {
SpatialMaterial _materl = (SpatialMaterial) _array_mesh.SurfaceGetMaterial(i);
// for (int i = 0; i < _array_mesh.GetSurfaceCount(); i++) {
// SpatialMaterial _materl = (SpatialMaterial) _array_mesh.SurfaceGetMaterial(i);

viz!.AddVisQueue(_meshistc!,
SphereGeom.calc_surface_normal_newell_method((Vector3[]) faces[i])*-Vector3.One,
_materl.AlbedoColor);
// viz!.AddVisQueue(_meshistc!,
// SphereGeom.calc_surface_normal_newell_method((Vector3[]) faces[i])*-Vector3.One,
// _materl.AlbedoColor);

}
// }

viz!.AddVisQueue(_meshistc!, Vector3.Up);
// viz!.AddVisQueue(_meshistc!, Vector3.Up);
}

public void CreateAdjacencyGraph() {
Expand Down Expand Up @@ -204,8 +225,7 @@ public void CreateAdjacencyGraph() {
}
}






}
45 changes: 45 additions & 0 deletions scripts/icosphere/RaySelector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Godot;
using System;

class RaySelector : Label {

RayCast raycast = new RayCast();
Camera? camera;

// Called when the node enters the scene tree for the first time.
public override void _Ready() {
this.Text = "Placeholder";
AddChild(raycast);

camera = GetCamera();
}

private Camera GetCamera(){
return GetNode<Camera>("../../Gimbal/Camera");
}

public override void _Input(InputEvent @event) {
}

public override void _PhysicsProcess(float delta) {
// this.Text = ("Mouse speed: %s" % MouseSpeed.get_instant_mouse_speed());
camera = GetCamera();

if(raycast.IsColliding())
GD.Print(raycast.GetCollider());

float ray_length = 100f;

var fromPos = camera!.ProjectRayOrigin(GetViewport().GetMousePosition());
var toPos = camera.ProjectRayNormal(GetViewport().GetMousePosition()) * ray_length;
GD.Print(GetViewport().GetMousePosition());

raycast.Translation = fromPos;
GD.Print(fromPos);
raycast.CastTo = toPos;
raycast.Enabled = true;
raycast.DebugShapeThickness = 20;
raycast.CollideWithAreas = true;
}

}
38 changes: 0 additions & 38 deletions scripts/icosphere/label.gd

This file was deleted.

2 changes: 0 additions & 2 deletions scripts/world/room/RoomFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public CustRoom NewRoom() {

float _halfpolygon = CoordHelper.PolygonFlatToFlatDistance(6,15f);

// TODO: add a proper collider

var color = new Color(
(float) GD.RandRange(0.1, 1.0),
(float) GD.RandRange(0.1, 1.0),
Expand Down
4 changes: 3 additions & 1 deletion scripts/world/worldgeom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public void CreateRoomGroup() {

}

if(_gamestate.debugMode)
GD.Print(_gamestate.CurrentPlayerRoom);

// flip next room
_isflipped = !_isflipped;
}
Expand All @@ -76,7 +79,6 @@ public override void _Input(InputEvent @event) {
m_sceneManager!.DeferredGotoScene("res://scenes/icosphere/Main.tscn");
}


}

[Export]
Expand Down

0 comments on commit 8cacc66

Please sign in to comment.