Add a first-view controller and a bunch of things
1. Replace 4k models with low-poly once 2. Use bare mixamo for testing 3. Add a basic menu 4. Add a map with collisions and spawn areas
This commit is contained in:
21
addons/Mirror/LICENSE.md
Normal file
21
addons/Mirror/LICENSE.md
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 Norodix
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
103
addons/Mirror/Mirror/Mirror.gd
Normal file
103
addons/Mirror/Mirror/Mirror.gd
Normal file
@ -0,0 +1,103 @@
|
||||
@tool
|
||||
extends Node3D
|
||||
|
||||
const whitegreen : Color = Color(0.9, 0.97, 0.94)
|
||||
|
||||
## Size of the mirror in world units
|
||||
@export var size : Vector2 = Vector2(2, 2)
|
||||
|
||||
## Resolution of the rendered viewport is Size*ResolutionPerUnit
|
||||
@export var ResolutionPerUnit = 100
|
||||
|
||||
## The NodePath to the main camera
|
||||
@export var MainCamPath: NodePath = ""
|
||||
|
||||
## The cull mask array contains the visual layers which are NOT rendered. The render layers numbering is different from their indexing. To avoid rendering layer 1 add a 0 element to the list. To avoid rendering layer 2 add a 1 element to the list and so on.
|
||||
@export var cullMask : Array[int] = []
|
||||
|
||||
## Tint color of the mirror surface
|
||||
@export_color_no_alpha var MirrorColor : Color = whitegreen
|
||||
|
||||
## Distortion multiplier of the mirror
|
||||
@export_range(0, 30, 0.01) var MirrorDistortion = 0
|
||||
|
||||
## The distortion texture of the mirror
|
||||
@export var DistortionTexture: Texture2D
|
||||
|
||||
var MainCam : Camera3D = null
|
||||
var cam : Camera3D
|
||||
var mirror : MeshInstance3D
|
||||
var viewport : SubViewport
|
||||
|
||||
|
||||
func _enter_tree():
|
||||
var node = preload("MirrorContainer.tscn").instantiate()
|
||||
add_child(node)
|
||||
var mesh_instance : MeshInstance3D = node.find_child("MeshInstance3D")
|
||||
mesh_instance.mesh = mesh_instance.mesh.duplicate()
|
||||
|
||||
|
||||
func _ready():
|
||||
MainCam = get_node_or_null(MainCamPath)
|
||||
cam = $MirrorContainer/SubViewport/Camera3D
|
||||
mirror = $MirrorContainer/MeshInstance3D
|
||||
viewport = $MirrorContainer/SubViewport
|
||||
|
||||
|
||||
func _process(delta):
|
||||
_ready() # need to reload for proper operation when used as a toolscript
|
||||
if MainCam == null:
|
||||
# No camera specified for the mirror to operate checked
|
||||
return
|
||||
|
||||
# Cull camera layers
|
||||
cam.cull_mask = 0xFF
|
||||
for i in cullMask:
|
||||
cam.cull_mask &= ~(1<<i)
|
||||
|
||||
# set mirror surface's size
|
||||
mirror.mesh.size = size
|
||||
# set viewport to specified resolution
|
||||
viewport.size = size * ResolutionPerUnit
|
||||
|
||||
# Set tint color
|
||||
mirror.get_active_material(0).set_shader_parameter("tint", MirrorColor)
|
||||
|
||||
# Set distortion texture
|
||||
mirror.get_active_material(0).set_shader_parameter("distort_tex", DistortionTexture)
|
||||
# Set distortion strength
|
||||
mirror.get_active_material(0).set_shader_parameter("distort_strength", MirrorDistortion)
|
||||
|
||||
# Transform3D the mirror camera to the opposite side of the mirror plane
|
||||
var MirrorNormal = mirror.global_transform.basis.z
|
||||
var MirrorTransform = Mirror_transform(MirrorNormal, mirror.global_transform.origin)
|
||||
cam.global_transform = MirrorTransform * MainCam.global_transform
|
||||
|
||||
# Look perpendicular into the mirror plane for frostum camera
|
||||
cam.global_transform = cam.global_transform.looking_at(
|
||||
cam.global_transform.origin/2 + MainCam.global_transform.origin/2, \
|
||||
mirror.global_transform.basis.y
|
||||
)
|
||||
var cam2mirror_offset = mirror.global_transform.origin - cam.global_transform.origin
|
||||
var near = abs((cam2mirror_offset).dot(MirrorNormal)) # near plane distance
|
||||
near += 0.05 # avoid rendering own surface
|
||||
|
||||
# transform offset to camera's local coordinate system (frostum offset uses local space)
|
||||
var cam2mirror_camlocal = cam.global_transform.basis.inverse() * cam2mirror_offset
|
||||
var frostum_offset = Vector2(cam2mirror_camlocal.x, cam2mirror_camlocal.y)
|
||||
cam.set_frustum(mirror.mesh.size.x, frostum_offset, near, 10000)
|
||||
|
||||
|
||||
# n is the normal of the mirror plane
|
||||
# d is the offset from the plane of the mirrored object
|
||||
# Gets the transformation that mirrors through the plane with normal n and offset d
|
||||
func Mirror_transform(n : Vector3, d : Vector3) -> Transform3D:
|
||||
var basisX : Vector3 = Vector3(1.0, 0, 0) - 2 * Vector3(n.x * n.x, n.x * n.y, n.x * n.z)
|
||||
var basisY : Vector3 = Vector3(0, 1.0, 0) - 2 * Vector3(n.y * n.x, n.y * n.y, n.y * n.z)
|
||||
var basisZ : Vector3 = Vector3(0, 0, 1.0) - 2 * Vector3(n.z * n.x, n.z * n.y, n.z * n.z)
|
||||
|
||||
var offset = Vector3.ZERO
|
||||
offset = 2 * n.dot(d)*n
|
||||
|
||||
return Transform3D(Basis(basisX, basisY, basisZ), offset)
|
||||
pass
|
31
addons/Mirror/Mirror/Mirror.gdshader
Normal file
31
addons/Mirror/Mirror/Mirror.gdshader
Normal file
@ -0,0 +1,31 @@
|
||||
shader_type spatial;
|
||||
render_mode cull_disabled, unshaded;
|
||||
|
||||
uniform vec4 tint : source_color = vec4(vec3(0.98),1.0);
|
||||
uniform sampler2D mirror_tex : source_color, repeat_disable;
|
||||
uniform sampler2D distort_tex : source_color;
|
||||
uniform float distort_strength : hint_range(0, 30);
|
||||
|
||||
void vertex() {
|
||||
UV.x = 1.0 - UV.x;
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
vec2 m_UV = UV;
|
||||
|
||||
// Backface texcoord flip correction
|
||||
if (!FRONT_FACING) {
|
||||
m_UV.x = 1.0 - m_UV.x;
|
||||
}
|
||||
|
||||
float distort_ofs = texture(distort_tex, m_UV).r;
|
||||
|
||||
// Map offset to [-1, 1] region
|
||||
distort_ofs = (distort_ofs * 2.0) - 1.0;
|
||||
|
||||
|
||||
vec2 base_uv = m_UV + distort_ofs * distort_strength / VIEWPORT_SIZE;
|
||||
vec4 mirror_sample = texture(mirror_tex,base_uv);
|
||||
|
||||
ALBEDO = tint.rgb * mirror_sample.rgb;
|
||||
}
|
29
addons/Mirror/Mirror/MirrorContainer.tscn
Normal file
29
addons/Mirror/Mirror/MirrorContainer.tscn
Normal file
@ -0,0 +1,29 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://b51uk2h1t8l33"]
|
||||
|
||||
[ext_resource type="Material" uid="uid://cp471l6edt4ab" path="res://addons/Mirror/Mirror/MirrorMaterial.tres" id="1"]
|
||||
|
||||
[sub_resource type="QuadMesh" id="11"]
|
||||
size = Vector2(2, 2)
|
||||
|
||||
[node name="MirrorContainer" type="Node3D"]
|
||||
|
||||
[node name="SubViewport" type="SubViewport" parent="."]
|
||||
size = Vector2i(100, 100)
|
||||
render_target_update_mode = 3
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="SubViewport"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.406672, 1.21628, 8.51171)
|
||||
keep_aspect = 0
|
||||
cull_mask = 1048571
|
||||
projection = 2
|
||||
size = 3.0
|
||||
frustum_offset = Vector2(-0.406672, -1.21628)
|
||||
near = 8.51171
|
||||
far = 10000.0
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 2.38419e-07, 0, 1, 0, -2.38419e-07, 0, 1, 0, 0, 0)
|
||||
layers = 4
|
||||
mesh = SubResource("11")
|
||||
skeleton = NodePath("../..")
|
||||
surface_material_override/0 = ExtResource("1")
|
14
addons/Mirror/Mirror/MirrorMaterial.tres
Normal file
14
addons/Mirror/Mirror/MirrorMaterial.tres
Normal file
@ -0,0 +1,14 @@
|
||||
[gd_resource type="ShaderMaterial" load_steps=3 format=3 uid="uid://cp471l6edt4ab"]
|
||||
|
||||
[ext_resource type="Shader" path="res://addons/Mirror/Mirror/Mirror.gdshader" id="1"]
|
||||
|
||||
[sub_resource type="ViewportTexture" id="12"]
|
||||
viewport_path = NodePath("SubViewport")
|
||||
|
||||
[resource]
|
||||
resource_local_to_scene = true
|
||||
render_priority = 0
|
||||
shader = ExtResource("1")
|
||||
shader_parameter/tint = Color(0.98, 0.98, 0.98, 1)
|
||||
shader_parameter/distort_strength = 0.0
|
||||
shader_parameter/mirror_tex = SubResource("12")
|
24
addons/Mirror/README.md
Normal file
24
addons/Mirror/README.md
Normal file
@ -0,0 +1,24 @@
|
||||
# Godot Mirror
|
||||
|
||||

|
||||
|
||||
A plugin created for godot to instance mirrors in a 3D scene. The mirrors use additional cameras to render the scene from a mirrored perspective.
|
||||
|
||||
Mirror properties that can be adjusted:
|
||||
- Tint
|
||||
- Size
|
||||
- Visible visual layers
|
||||
- Player camera
|
||||
|
||||
## Usage
|
||||
|
||||
After the addon is enabled a custom node is added to godot under the spatial node.
|
||||
|
||||
The main camera that renders the scene needs to be selected in the variables of the node. Only one camera is supported at a time. The plugin adds a secondary camera to the opposite side of the mirror relative to this camera and renders the image to the mirror surface.
|
||||
|
||||
The cull mask array contains the visual layers which are NOT rendered. The render layers numbering is different from their indexing. To avoid rendering layer 1 add a 0 element to the list.
|
||||
To avoid rendering layer 2 add a 1 element to the list and so on.
|
||||
|
||||
## Installation
|
||||
|
||||
Copy the addons/Mirror folder into your godot root directory, same as the asset library installs addons. Enable the plugin in Project settings/Plugins.
|
78
addons/Mirror/icon.svg
Normal file
78
addons/Mirror/icon.svg
Normal file
@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 4.2333332 4.2333332"
|
||||
version="1.1"
|
||||
id="svg8"
|
||||
inkscape:version="1.0.2 (e86c870879, 2021-01-15)"
|
||||
sodipodi:docname="icon.svg">
|
||||
<defs
|
||||
id="defs2" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="22.627417"
|
||||
inkscape:cx="8.6940988"
|
||||
inkscape:cy="12.428262"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:current-layer="layer1"
|
||||
inkscape:document-rotation="0"
|
||||
showgrid="false"
|
||||
units="px"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1016"
|
||||
inkscape:window-x="1920"
|
||||
inkscape:window-y="27"
|
||||
inkscape:window-maximized="1" />
|
||||
<metadata
|
||||
id="metadata5">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<g
|
||||
id="g872"
|
||||
transform="translate(0.02117361,-0.01175623)"
|
||||
style="fill:none;stroke-width:0.34395833;stroke-miterlimit:4;stroke-dasharray:none;stroke:#e58f91;stroke-opacity:1">
|
||||
<path
|
||||
id="rect842"
|
||||
style="fill:none;stroke:#e58f91;stroke-width:0.34395833;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stop-color:#000000;stroke-opacity:1"
|
||||
d="M 0.3745072,0.3633829 2.2572793,0.71289572 V 3.5439501 L 0.3745072,3.8934629 Z"
|
||||
sodipodi:nodetypes="ccccc" />
|
||||
<circle
|
||||
style="fill:none;stroke:#e58f91;stroke-width:0.34395833;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stop-color:#000000;stroke-opacity:1"
|
||||
id="path847"
|
||||
cx="3.3799474"
|
||||
cy="2.1284225"
|
||||
r="0.43653148" />
|
||||
<circle
|
||||
style="fill:none;stroke:#e58f91;stroke-width:0.34395833;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stop-color:#000000;stroke-opacity:1"
|
||||
id="circle849"
|
||||
cx="1.3158932"
|
||||
cy="2.1284225"
|
||||
r="0.43653148" />
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.6 KiB |
37
addons/Mirror/icon.svg.import
Normal file
37
addons/Mirror/icon.svg.import
Normal file
@ -0,0 +1,37 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://dxj8owcka0ldn"
|
||||
path="res://.godot/imported/icon.svg-d5bf744255b68932164587d8eb3dc79a.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/Mirror/icon.svg"
|
||||
dest_files=["res://.godot/imported/icon.svg-d5bf744255b68932164587d8eb3dc79a.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
svg/scale=1.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/convert_colors_with_editor_theme=false
|
7
addons/Mirror/plugin.cfg
Normal file
7
addons/Mirror/plugin.cfg
Normal file
@ -0,0 +1,7 @@
|
||||
[plugin]
|
||||
|
||||
name="Mirror"
|
||||
description="Adds custom mirror node to the editor"
|
||||
author="Norodix"
|
||||
version="0.2"
|
||||
script="plugin.gd"
|
12
addons/Mirror/plugin.gd
Normal file
12
addons/Mirror/plugin.gd
Normal file
@ -0,0 +1,12 @@
|
||||
@tool
|
||||
extends EditorPlugin
|
||||
|
||||
|
||||
func _enter_tree():
|
||||
add_custom_type("Mirror", "Node3D", preload("Mirror/Mirror.gd"), preload("icon.svg"))
|
||||
pass
|
||||
|
||||
|
||||
func _exit_tree():
|
||||
remove_custom_type("Mirror")
|
||||
pass
|
Reference in New Issue
Block a user