Skip to content

Commit

Permalink
fix: add hidings to skin category (adr-60) and ignore tokenId on wear…
Browse files Browse the repository at this point in the history
…able urns (#179)
  • Loading branch information
leanmendoza authored Jan 24, 2024
1 parent 296edfc commit 6181223
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 30 deletions.
40 changes: 20 additions & 20 deletions godot/src/decentraland_components/avatar.gd
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func async_load_wearables():
return

wearables_by_category = curated_wearables[0]
# var hidden_categories = curated_wearables[1]
var hiding_list: PackedStringArray = curated_wearables[1]

var body_shape = wearables_by_category.get(Wearables.Categories.BODY_SHAPE)
if body_shape == null:
Expand All @@ -312,11 +312,11 @@ func async_load_wearables():
try_to_set_body_shape(Wearables.get_wearable_main_file_hash(body_shape, current_body_shape))
wearables_by_category.erase(Wearables.Categories.BODY_SHAPE)

var has_skin = false
var hide_upper_body = false
var hide_lower_body = false
var hide_feet = false
var hide_head = false
var has_own_skin = false
var has_own_upper_body = false
var has_own_lower_body = false
var has_own_feet = false
var has_own_head = false

for category in wearables_by_category:
var wearable = wearables_by_category[category]
Expand All @@ -330,30 +330,30 @@ func async_load_wearables():
var wearable_skeleton: Skeleton3D = obj.find_child("Skeleton3D")
for child in wearable_skeleton.get_children():
var new_wearable = child.duplicate()
new_wearable.name = new_wearable.name.to_lower()
new_wearable.name = new_wearable.name.to_lower() + "_" + category
body_shape_skeleton_3d.add_child(new_wearable)

match category:
Wearables.Categories.UPPER_BODY:
hide_upper_body = true
has_own_upper_body = true
Wearables.Categories.LOWER_BODY:
hide_lower_body = true
has_own_lower_body = true
Wearables.Categories.FEET:
hide_feet = true
has_own_feet = true
Wearables.Categories.HEAD:
hide_head = true
has_own_head = true
Wearables.Categories.SKIN:
has_skin = true
has_own_skin = true

var hidings = {
"ubody_basemesh": has_skin or hide_upper_body,
"lbody_basemesh": has_skin or hide_lower_body,
"feet_basemesh": has_skin or hide_feet,
"head": has_skin or hide_head,
"head_basemesh": has_skin or hide_head,
"mask_eyes": has_skin or hide_head,
"mask_eyebrows": has_skin or hide_head,
"mask_mouth": has_skin or hide_head,
"ubody_basemesh": has_own_skin or has_own_upper_body,
"lbody_basemesh": has_own_skin or has_own_lower_body,
"feet_basemesh": has_own_skin or has_own_feet,
"head": has_own_skin or has_own_head,
"head_basemesh": has_own_skin or has_own_head,
"mask_eyes": has_own_skin or has_own_head,
"mask_eyebrows": has_own_skin or has_own_head,
"mask_mouth": has_own_skin or has_own_head,
}

for child in body_shape_skeleton_3d.get_children():
Expand Down
29 changes: 23 additions & 6 deletions godot/src/decentraland_components/wearables/wearables.gd
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,9 @@ static func get_replaces_list(wearable: Dictionary, body_shape_id: String) -> Pa
return representation.get("overrideHides", [])


static func get_hides_list(wearable: Dictionary, body_shape_id: String) -> PackedStringArray:
var result: PackedStringArray = []
static func get_hides_list(
wearable: Dictionary, wearable_category: String, body_shape_id: String
) -> PackedStringArray:
var representation = get_representation(wearable, body_shape_id)

var hides: PackedStringArray = []
Expand All @@ -453,12 +454,27 @@ static func get_hides_list(wearable: Dictionary, body_shape_id: String) -> Packe

hides.append_array(get_replaces_list(wearable, body_shape_id))

if wearable_category == Categories.SKIN:
hides.append_array(
[
"head",
"hair",
"facial_hair",
"mouth",
"eyebrows",
"eyes",
"upper_body",
"lower_body",
"feet"
]
)

# Safeguard the wearable can not hide itself
var index := hides.find(wearable.get("category", ""))
var index := hides.find(wearable_category)
if index != -1:
hides.remove_at(index)

return result
return hides


# @returns Empty if there is no representation
Expand Down Expand Up @@ -497,7 +513,7 @@ static func compose_hidden_categories(
if wearable == null:
continue

var current_hides_list = get_hides_list(wearable, body_shape_id)
var current_hides_list = get_hides_list(wearable, priority_category, body_shape_id)
if current_hides_list.is_empty():
continue

Expand All @@ -511,7 +527,8 @@ static func compose_hidden_categories(
if force_render.has(category_to_hide):
continue

result.push_back(category_to_hide)
if not result.has(category_to_hide):
result.push_back(category_to_hide)

return result

Expand Down
74 changes: 74 additions & 0 deletions godot/src/tool/avatar_renderer/test-input.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,80 @@
}
}
}
},
{
"entity": "mati_avatar_test",
"destPath": "output/mati_avatar_test.png",
"width": 256,
"height": 512,
"faceDestPath": "output/mati_avatar_test_face.png",
"faceWidth": 256,
"faceHeight": 256,
"avatar": {
"bodyShape": "urn:decentraland:off-chain:base-avatars:BaseMale",
"wearables": [
"urn:decentraland:off-chain:base-avatars:eyebrows_00",
"urn:decentraland:off-chain:base-avatars:eyes_06",
"urn:decentraland:off-chain:base-avatars:mouth_03",
"urn:decentraland:off-chain:base-avatars:beard",
"urn:decentraland:off-chain:base-avatars:short_hair",
"urn:decentraland:matic:collections-v2:0xf1483f042614105cb943d3dd67157256cd003028:6:631873750011343120187508166102022593913370572403294667525865865225",
"urn:decentraland:matic:collections-v2:0xd50191baed16bc532feb9d499fdaa805fe01d3ff:8:842498333348457493583344221469363458551160763204392890034487820292",
"urn:decentraland:matic:collections-v2:0xf1483f042614105cb943d3dd67157256cd003028:16:1684996666696914987166688442938726917102321526408785780068975640582",
"urn:decentraland:matic:collections-v2:0xd05723401566e9d9b7a728bd4dbe07584cf8ac76:5:526561458342785933489590138418352161594475477002745556271554887855"
],
"forceRender": [],
"emotes": [
{
"slot": 0,
"urn": "handsair"
},
{
"slot": 6,
"urn": "money"
},
{
"slot": 7,
"urn": "kiss"
},
{
"slot": 8,
"urn": "tik"
},
{
"slot": 9,
"urn": "shrug"
}
],
"snapshots": {
"body": "https://peer-ec1.decentraland.org/content/contents/bafkreidhmzu5wwcssv3f65wfs7swnncalwarfqavsfifxvclgv32ku3zdu",
"face256": "https://peer-ec1.decentraland.org/content/contents/bafkreigea3qbj56h6erxvt524hah2mlxnvqkpazjelcotktxldecvraohq"
},
"eyes": {
"color": {
"r": 0.22265625,
"g": 0.484375,
"b": 0.69140625,
"a": 1
}
},
"hair": {
"color": {
"r": 0.98046875,
"g": 0.82421875,
"b": 0.5078125,
"a": 1
}
},
"skin": {
"color": {
"r": 0.94921875,
"g": 0.76171875,
"b": 0.6484375,
"a": 1
}
}
}
}
]
}
16 changes: 12 additions & 4 deletions rust/decentraland-godot-lib/src/content/content_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use godot::{
use tokio::sync::Semaphore;

use crate::{
content::content_mapping::DclContentMappingAndUrl, godot_classes::promise::Promise,
http_request::http_queue_requester::HttpQueueRequester,
content::content_mapping::DclContentMappingAndUrl, dcl::common::string::FindNthChar,
godot_classes::promise::Promise, http_request::http_queue_requester::HttpQueueRequester,
scene_runner::tokio_runtime::TokioRuntime,
};

Expand Down Expand Up @@ -358,7 +358,12 @@ impl ContentProvider {
let mut wearable_to_fetch = HashSet::new();

for wearable in wearables.iter_shared() {
let wearable_id = wearable.to_string().to_lowercase();
let wearable_id = wearable.to_string();
let token_id_pos = wearable_id
.find_nth_char(6, ':')
.unwrap_or(wearable_id.len());
let wearable_id = wearable_id[0..token_id_pos].to_lowercase();

if let Some(entry) = self.cached.get(&wearable_id) {
promise_ids.insert(entry.promise.instance_id());
} else {
Expand Down Expand Up @@ -412,7 +417,10 @@ impl ContentProvider {

#[func]
pub fn get_wearable(&mut self, id: GString) -> Variant {
let id = id.to_string().to_lowercase();
let id = id.to_string();
let token_id_pos = id.find_nth_char(6, ':').unwrap_or(id.len());
let id = id[0..token_id_pos].to_lowercase();

if let Some(entry) = self.cached.get(&id) {
if let Ok(results) = entry.promise.bind().get_data().try_to::<Dictionary>() {
if let Some(wearable) = results.get(id) {
Expand Down
2 changes: 2 additions & 0 deletions rust/decentraland-godot-lib/src/dcl/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use serde::{Deserialize, Serialize};

use crate::godot_classes::JsonGodotClass;

pub mod string;

pub struct SceneJsFileContent(pub String);
pub struct SceneMainCrdtFileContent(pub Vec<u8>);

Expand Down
24 changes: 24 additions & 0 deletions rust/decentraland-godot-lib/src/dcl/common/string.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
pub trait FindNthChar {
fn find_nth_char(&self, n: i32, character: char) -> Option<usize>;
}

impl FindNthChar for &str {
fn find_nth_char(&self, mut n: i32, character: char) -> Option<usize> {
for (i, c) in self.char_indices() {
if c == character {
n -= 1;
}
if n == 0 {
return Some(i);
}
}

None
}
}

impl FindNthChar for String {
fn find_nth_char(&self, n: i32, character: char) -> Option<usize> {
self.as_str().find_nth_char(n, character)
}
}

0 comments on commit 6181223

Please sign in to comment.