Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.0 Add MDL, VTF, VMT native support #34

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
root = true

[*]
charset = utf-8
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ test.tscn
godotvmf_mod

addons/godotvmf/texture_checksums.json
tools
285 changes: 0 additions & 285 deletions addons/godotvmf/3rdparty/objParse.gd

This file was deleted.

51 changes: 51 additions & 0 deletions addons/godotvmf/entities/prop_static.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@tool
extends ValveIONode

static var cached_models = {};
static var last_cache_changed = 0;

func _apply_entity(e):
super._apply_entity(e);
cached_models = cached_models if cached_models else {};

if last_cache_changed == null:
last_cache_changed = 0;

assert("models" in VMFConfig.config, "Missing 'models' in VMFConfig.config");

var cache_key = e.get('model');
var model_path = (VMFConfig.config.models.targetFolder + "/" + e.get('model')).replace("\\", "/").replace("//", "/").replace("res:/", "res://");

if Time.get_ticks_msec() - last_cache_changed > 10000:
cached_models = {};

if cache_key not in cached_models:
if not ResourceLoader.exists(model_path):
push_warning("[prop_static]: Model not found: {0}".format([model_path]));
queue_free();
return

cached_models[cache_key] = ResourceLoader.load(model_path);
last_cache_changed = Time.get_ticks_msec();

var model: MeshInstance3D = cached_models[cache_key].instantiate();

add_child(model);
model.set_owner(get_owner());
model.scale *= e.get('modelscale', 1.0);
model.reparent(get_vmfnode().geometry);
model.name = e.get('model', 'prop_static').get_file().get_basename() + str(model.get_instance_id());

var fade_min = entity.get('fademindist', 0.0) * VMFConfig.config.import.scale;
var fade_max = entity.get('fademaxdist', 0.0) * VMFConfig.config.import.scale;
var fade_margin = fade_max - fade_min;

model.visibility_range_end = max(0.0, fade_max);
model.visibility_range_fade_mode = GeometryInstance3D.VISIBILITY_RANGE_FADE_SELF \
if e.get('screenspacefade', 0) == 1 \
else GeometryInstance3D.VISIBILITY_RANGE_FADE_DISABLED;

if model.visibility_range_fade_mode != GeometryInstance3D.VISIBILITY_RANGE_FADE_DISABLED:
model.visibility_range_end_margin = fade_margin;

queue_free();
6 changes: 6 additions & 0 deletions addons/godotvmf/entities/prop_static.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://cb0240swycsj5"]

[ext_resource type="Script" path="res://addons/godotvmf/entities/prop_static.gd" id="1_xdb2b"]

[node name="PropStatic" type="Node3D"]
script = ExtResource("1_xdb2b")
Loading