肖像模組製作

本頁面所適用的版本可能已經過時,最後更新於2.8
(重新導向自DNA



The character screen

肖像是通過疊加基本元素的層來構建的:背景、通用頭部、面部元素(臉頰、頭髮、鼻子等)、衣服、帽子等。

這些基本元素中的每一個都有多個變體或框架。

框架的選擇基於以下幾點:

  • 角色的DNA,
  • 角色的某些Property(也就是triggers)

兒童是一個例外,因為它們是使用單個圖像創建的,因此兒童看起來很相似。

特性

有兩種特徵:DNA和屬性。兩者都是字母串(變數值可能為零)。

他們可以通過控制台命令charinfo來查看。

DNA

DNA是由父母遺傳的11個字母組成的字符串,出生後不會改變。

對於已經成為歷史的角色,他們的DNA被設置在角色歷史:

125501 = {
	name="Temujin" # AKA: Genghis Khan
	dynasty=11100
	dna="bfimkolbecc"
	(...)
}

否則,隨機生成的角色將獲得隨機的DNA字符串,這些字符串將保存在遊戲存檔中。

Index Used for
d0 脖子
d1 下巴
d2 嘴巴
d3 鼻子
d4 臉頰
d5 不使用的變數
d6 眼睛
d7 耳朵
d8 發色
d9 瞳色
d10 不使用的變數

所以成吉思汗角色代碼中的 dna = "bfimkolbecc" 意味着:

  • 脖子使用圖像b (mongol_male_neck_1.dds中的第二個圖標)
  • 下巴使用圖像f(mongol_male_chin_1.dds中的第六個圖標)
  • 嘴巴使用圖像i(mongol_male_mouth_1.dds中的第九個圖標)
  • 鼻子使用圖像m(mongol_male_nose_1.dds中的第13個圖標)
  • 以此類推...

如果dds文件中的圖像塊數量小於字母對應的數字, 它就會循環計數。比如,下巴對應的dds文件只有4個圖標,那麼a和e都代表第一個圖標。

Property

屬性在ck2中由一個14位的字符串組成。如果字符串不夠長,結尾會加上0。

只有頭髮(p1)和鬍子(p4)可以在遊戲裏通過Customization Pack修改。其他的值來自portrait_properties.txt

  • p0: 背景
  • p1: 頭髮
  • p2: 基本的腦袋
  • p3: 衣服
  • p4: 鬍子
  • p5: 頭盔
  • p6: 是否在監獄
  • p7: 傷疤圖層1
  • p8: 紅色的點
  • p9: Boils
  • p10: 是否盲人
  • p11: 是否玩家
  • p12: 面具
  • p13: 眼罩
  • p14: 中式化妝圖層
  • p15: 中式化妝圖層2
  • p16: 中國皇帝的珠寶
  • p17: 永生
  • p18: 特殊王冠-後
  • p19: 特殊王冠
  • p20: 雀斑
  • p21: 體格
  • p22: 蒼白的
  • p23: 黑眼圈
  • p24: 兔唇
  • p25: 傷疤圖層2
  • p26: 傷疤圖層3
  • p27: 濺血
  • p28: 紋身
  • p29: 土著出征前的臉部化妝
  • p30: 惡魔之子
  • p31: 法蘭克文化男性疊加圖層
  • p32: 法蘭克文化女性疊加圖層
  • p33: 法蘭克文化女性疊底圖層和頭髮

可以用下面的方式添加新的Property:

  • 定義一個包含sprite的.gfx文件,以GFX_custom為例。
spriteType = {
	name = "GFX_custom"
	texturefile = "gfx\\characters\\shared\\new_property.dds"
	noOfFrames = 2
	norefcount = yes
	can_be_lowres = yes
}
  • 在portrait_properties.txt配置p18 (property的數量是從這裏動態確定的):
# p18
18 = {
	0 = {
		factor = 50
	}
	1 = {
		factor = 50
	}
}
  • 在portraits.gfx中疊加圖層: "GFX_custom:p18"

渲染

基於玩家的實驗,以下是對遊戲中肖像渲染工作原理的描述。記住,其中一部分的邏輯仍然由Portrait Builder重新實施,這用來作為遊戲外的渲染檢查工具。

孩子

對於孩子的portraits:

  1. 直接在 /interface/portraits/* 查找 PORTRAIT_<culturegfx>_child_<sex>
    • <culturegfx> 是graphical_culture用來定義角色所屬的文化或者文化組。
    • <sex> 決定是男是女。

封建制度政府

遊戲渲染封建封建制度政府中成人肖像如下:

  1. 直接在/interface/portraits/portrait.gfx (或者其他/interface/*下面的portraitType) 尋找PORTRAIT_<culturegfx>_<sex><_period><age>,
    • <culturegfx>graphical_culture 用來定義角色所屬的文化或者文化組。(common/cultures/00_cultures.txt)
    • <sex>決定是男是女。
    • <age>是一個int類型(整數值)r: 0代表年輕(16 <= age < 30), 1代表中年 (30 <= age < 50), 2代表暮年(age >= 50)
    • <_period> 在值為_early時說明早於950年。_late 時說明晚於1250年。其他情況下為空值。(注意:真實的時間放在defines下面的EARLY_PORTRAIT_AND_UNIT_BEFORE_YEAR和LATE_PORTRAIT_AND_UNIT_AFTER_YEAR定義中)
  2. 如果沒有匹配的portraitType,將會嘗試尋找某些默認值:no date, no age,返回值中尋找graphical_cultures列表裏面的種族。尋找來自父母文化組的種族特點(注意不是文化,種族是先天的,文化後天可以改)。萬不得已會將變數的值變為westerngfx。
  3. 如果沒有匹配的portraitType,將會按照順序使用圖層,每個圖層被定義在 GFX_TYPE:[d|p]INDEX:
    1. 在spriteTypes(/interface/portraits/portrait_sprites.gfx或者其他 /interface/*下的spriteType)尋找 GFX_TYPE 然後讀取dds文件的圖標序號N
    2. 解析要使用的dds圖標:
      • 如果字符串的值為d, 在DNA字符串的INDEX位置查找,轉換數字後對N進行取模的運算(運算符mod)。
      • 如果字符串的值為p, 解析值的INDEX屬性。這定義於/interface/portrait_properties.txt。選擇基於加權隨機,但將自動選擇評估結果>=100的第一個結果。
  4. 為種族定義膚色,在common/graphicalculturetypes/graphicalculturetype.txt,因此這也可以"管理"到混血兒。

神權制度政府

該制度政府下的人物肖像渲染類似封建制度政府,但頭飾和服裝層除外。

  1. 尋找角色的宗教定義,然後直接查找dds文件里的圖標目錄。 (portrait_properties.txt不起作用):
    • religious_clothing_head: 用於宗教頭飾圖層的dds圖標文件。
    • religious_clothing_priest: 用於其他宗教下祭祀的dds圖標文件。
  2. GFX_religious_male_clothes下的dds圖標目錄是硬編碼的, 比如GFX_religious_male_headgear。這些文件用來替換掉portrait.gfx中的定義。

共和制政府

該制度政府下的人物肖像渲染類似封建制度政府,但頭飾和服裝層除外。 GFX_merchant_male_clothes下的dds圖標目錄是硬編碼的, 比如GFX_merchant_male_headgear。這些文件用來替換掉portrait.gfx中的定義。


衣物覆蓋

2.7版本添加了一種新機制,可以根據規則覆蓋服裝層。

ck2中唯一的代碼翻譯位於dlc072.zip下的 \interface\portraits\society_clothes.gfx

完整數組代碼的結構如下所示:

portraitType = {
	name = "PORTRAIT_<override_type>_clothing_male"

	weight = {
		additive_modifier = {
			value = 10000
			# Conditions (in portrait scope) for modifier to apply
		}
	}

	layer = { # GFX_empty can be used to disable a layer
		"GFX_xxx_male_clothing_behind:c0"
		"GFX_xxx_male_headgear_behind:c1"
		"GFX_xxx_male_clothing_front:c2"
		"GFX_xxx_male_headgear_mid:c3"
		"GFX_xxx_male_clothing_infront:c4"
		"GFX_xxx_male_headgear_front:c5"
	}

	allow_property_values = {
		<property_index> = {
			<frame_index> = {
				# Conditions (in portrait scope) for frame to be used
			}
		}
	}
}

注意:

  • c0到c7是根據"文化目錄"來渲染衣物的圖層的(通常是由p3和p5定義):
    • c0 =衣物-後
    • c1 =頭飾-後
    • c2 =衣物
    • c3 =頭飾-中
    • c4 =衣物-前
    • c5 =頭飾
    • c6 =頭髮後面的頭飾圖層
    • c7 =頭飾與頭髮圖層

注意:通過模組你不能添加一個動態的額外文化圖標目錄。

  • layerallow_property_values 可以像portrait_properties.txt用類似的方式選擇p3 (衣物) 和p5 (頭飾) 下覆蓋衣物對應dds文件下的圖標。

Portrait scope

A new scope is used, which is a sort of limited version of a character scope, with conditions prefixed with portrait_.

變數名 變數類型 ck2是否可用 變數說明 代碼示例
portrait_age child/oldage 角色的年齡在portrait threshold閾值判斷下來說是孩子,年輕,中年還是一個老年人。由於閾值是可配置的,因此這裏沒有直接硬編碼數值。 portrait_age > child

portrait_age < oldage

portrait_is_female bool 角色是否為女性 portrait_is_female = yes
portrait_has_trait trait 該外貌變數下角色是否有特性 portrait_has_trait = vaishnavist_hindu
portrait_religion religion X [Seen in the .exe - to be tested]
portrait_culture culture 角色的文化 portrait_culture = greek
portrait_culture_group culture_group 字面意思:文化組 portrait_culture_group = latin
portrait_gfx_culture ? X [Seen in the .exe - to be tested]
portrait_government government X Whether character has the specified government. Seems to only work on landed characters.
portrait_tier tier portrait_tier = king
portrait_title_tier ? X [Seen in the .exe - to be tested]
portrait_society society portrait_society = monastic_order_benedictine
portrait_society_rank int Character rank if member of a society portrait_society_rank = 1
portrait_clothing bool 警告: portrait_clothing = no 似乎不起作用. portrait_clothing = yes
portrait_offmap offmap_power 該角色是否為中國皇帝 portrait_offmap = offmap_china
portrait_is_patrician bool X 角色是否在一個商人共和國,他們的僱主是貴族,還是有共和國政府的形式。 portrait_is_patrician = yes
portrait_in_command bool X 該角色是否帶領軍隊 portrait_in_command = yes

自定義種族

通過在肖像類型層中創建新資產和/或混合現有的ck2或DLC資產,可以創建新的種族。

例如,一個customgfx種族和norsegfx的臉和byzantinegfx的衣服。

新的資產

主條目:Graphics modding

如果你從頭創建一個圖像sprite,你需要

  • 在文件夾gfx/characters/中創造兩個文件夾(gothic_male和gothic_female) 來存放sprite (例如:有12個圖標的gothic_male_clothes.dds)
  • 在文件夾interface/創造一個portraits_gothic_spritetypes.gfx文件,文件下要有每個圖像sprite都有一個條目:
spriteTypes = {
  spriteType = {
    name = "GFX_gothic_male_clothes"
    texturefile = "gfx\\characters\\gothic_male\\gothic_male_clothes.dds"
    noOfFrames = 12
    norefcount = yes
    can_be_lowres = yes
  }
  ...
}

DLC資產

重複使用DLC資產比創建新資產更容易,但因為DLC資產本身不能捆綁到模組中。[2] 沒有DLC的用戶將不會擁有這些資產(例如the Norse Portraits DLC) ,沒有DLC的用戶會見到沒有渲染腦袋但是渲染衣服的gothicgfx。

如果定義了哥德式風格的一些portraitTypes,遊戲就會渲染它們。即使這些層涉及未知資產,也不能正確顯示。 將會在一旦對應的portraitType沒有創立,其他種族的graphical_cultures列表的返回值(或者默認渲染的westerngfx)將會進行渲染。

這種問題包含以下幾種狀況:

  1. 將portraitTypes的定義捆綁在主mod之外的子mod中。這樣的話玩家就會:
    • 如果沒有所需DLC,只能讓子mod工作。
    • 如果沒有所需DLC,會看到候選返回值下種族外貌。
  2. 為了不使用DLC資產的種族提供後備的portraitTypes。玩家需要下載額外返回值下的portraitTypes然後再沒有所需DLC情況下使用。

新的種族

如果要定義一個新的gothicgfx種族,請按照以下步驟

  • 在主要mod文件夾common/graphicalculturetypes/ 下建立一個新的txt文件並加入以下代碼:
gothicgfx = {
  skin_tone = 0
}
  • 在主要mod文件夾common/cultures/00_cultures.txt 的文件中,修改或者添加一種新的哥特文化組的culture然後添加以下代碼:
graphical_cultures = { gothicgfx occitangfx }

注意:如果開了子mod,那麼重要的是,列表中的最後一個culturefx是ck2的類型之一(occitangfx、muslimgfx、byzantinegfx、westerngfx)。如果它是westerngfx,則可以省略它,因為它是默認值,或者用作3層種族。如果要候選返回值的portraitTypes,則不需要這樣做。

  • 在子modI(或者主要mod,根據情況選擇)文件夾下 interface/添加一個新的portraits_gothic.gfx文件,並且使用以下的數組結構。 (代碼從ck2的另一個文件下portraits.gfx複製過來):
spriteTypes = {
  spriteType = {
    name = "PORTRAIT_gothicgfx_child_male"
  }
  spriteType = {
    name = "PORTRAIT_gothicgfx_child_female"
  }
  portraitType = {
    name = "PORTRAIT_gothicgfx_male"
  }
  portraitType = {
    name = "PORTRAIT_gothicgfx_male1"
  }
  portraitType = {
    name = "PORTRAIT_gothicgfx_male2"
  }
  portraitType = {
    name = "PORTRAIT_gothicgfx_female"
  }
  portraitType = {
    name = "PORTRAIT_gothicgfx_female1"
  }
  portraitType = {
    name = "PORTRAIT_gothicgfx_female2"
  }
}
  • 對於每個portraitType,給每個圖層(自定義的、ck2本體的或者DLC的spriteType)匹配正確的sprite
portraitType = {
  name = "PORTRAIT_gothicgfx_female"
  effectFile = "gfx/FX/portrait.lua"
  layer = { # GFX_TYPE:[d|p]INDEX:COLOR_LINK:DONT_REFRESH_IF_VALID:CULTURE_INDEX
    "GFX_character_background:p0"
    "GFX_byzantine_female_clothes_behind:p3:c0"
    "GFX_byzantine_female_headgear_behind:p5:c1"
    "GFX_norse_female_hair_behind:p1:h:y"
    "GFX_norse_female_base:p2"
    "GFX_norse_female_neck:d0"
    "GFX_norse_female_mouth:d2"
    "GFX_norse_female_nose:d3"
    "GFX_norse_female_chin:d1"
    "GFX_norse_female_cheeks:d4"
    "GFX_norse_female_eyes:d6"
    "GFX_norse_female_eyes2:d6:e"
    "GFX_character_scars:p7:y"
    "GFX_character_reddots:p8"
    "GFX_character_boils:p9"
    "GFX_character_blinded_eyes:p10"
    "GFX_norse_female_ear:d7"			
    "GFX_byzantine_female_clothes:p3:c2"
    "GFX_empty:p5:c3"
    "GFX_norse_female_hair:p1:h:y"
    "GFX_empty:p3:c4"
    "GFX_byzantine_female_headgear:p5:c5"
    "GFX_character_imprisoned:p6"
    "GFX_player_overlay:p11"
}

靜態的portraits

要顯示靜態預渲染肖像,有幾種技術:

雜項層

使用雜項層(例如blinded_eyes),添加一個預先渲染的portrait圖標[3]

  • 把這個圖層放到portraits.gfx列表的最後面
  • 在portrait_sprites.gfx里添加新的圖標 (ex: GFX_character_blinded_eyes)
  • 編輯sprite(比如blinded_eyes.dds)然後添加額外圖標
  • 在portrait_properties.txt中為每個圖層對應屬性的dds圖標添加一個條目(比如: p10盲人), 基於獨特特徵或角色flag的觸發器
# p10 blinded
10 = {
	0 = {
		factor = 100
		modifier = {
			factor = 0
			trait = blinded
		}
		modifier = {
			factor = 0
			#Either a character flag or a unique trait.
		}
	}
	
	1 =  {
		factor = 100
		modifier = {
			factor = 0
			NOT = {
				trait = blinded
			}
		}
		modifier = {
			factor = 0
			#Either a character flag or a unique trait.
		}

	}
	2 =  {
		factor = 100
		modifier = {
			factor = 0
			NOT = {
				#Either a character flag or a unique trait.
			}
		}
	}
}

遮擋flag

在角色歷史中使用occluded = yes。可用於默罕默德(先知). 最大的限制是,每個occluded = yes的角色會擁有相同的portrait。這使用單個的圖標材質,而且在Muhammad.tga中硬編碼

spriteType = {
  name = "GFX_Muhammad"
  texturefile = "gfx\\characters\\Muhammad.tga"
  noOfFrames = 1
  norefcount = yes
}

自定義種族

使用自定義種族,然後將之設定在角色歷史中。或者通過 set_graphical_culture 事件命令 因為命令需要文化作為參數,所以還必須定義自定義文化。 此外,種族在出生時從父母中的一方隨機繼承。 所以需要一些on_action事件來控制。

步驟如下:

  • common/cultures/ 創建一個自定義文化
special = {
  graphical_cultures = { specialgfx }
  ...
}
  • interface/ 為自定義種族定義一個portrait, 然後需要一個基於p2 property的圖標
spriteType = {
  name = "GFX_special"
  texturefile = "gfx\\characters\\special.tga"
  noOfFrames = 1
  norefcount = yes
}

portraitType = {
  name = "PORTRAIT_specialgfx_male"
  effectFile = "gfx/FX/portrait.lua"
  layer = { # GFX_TYPE:[d|p]INDEX:COLOR_LINK:DONT_REFRESH_IF_VALID:CULTURE_INDEX
    "GFX_character_background:p0"
    "GFX_special:p2"
    "GFX_character_imprisoned:p6"
  }
  hair_color = { { 10 10 10 } { 50 50 50 } { 255 255 255 } } #Must be included.
  eye_color = {	{ 255 255 255} } # Leaving these out will crash the game.
}

portraitType = {
  name = "PORTRAIT_specialgfx_female"
  ... #The rest is same as above. Both *_male and *_female portraitType are required, even for static portraits.
}
  • 使用 set_graphical_culture = special 命令和 graphical_culture = specialgfx 在事件中進行控制

External links

See also

References