HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: facegen and body  (Read 2032 times)

Thazager

  • General Accounts
  • *
  • Posts: 1155
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
facegen and body
« on: Feb 18, 13, 09:21:56 PM »

Moderate level scripting

This tutorial lets the user change face and body values using sliders. There are 9 different parts of the face and 3 sliders per part. There is also a toggle button to lock the character direction, so that you can swing the camera round the character.

__________________________________________________________________
From the basic window tutorial
Make basic window here. This is a base window and will be used in many of my Tutorials. It uses the GUI pics from textures that all engines have. This can be skipped if you have the basic window already from another tutorial.

Make basic button here. This will also be used in many of my tutorials.

_________________________________________________________________________
In the DOM, create a new (client side) class
name = TMP_Facegen
archtype = guicontrol
add a parent to the class, TMP_Window

click open script

In new (client side) script TMP_ Facegen

Code: [Select]
// create facegen window
shared function Start()
  var win = getFacegenClass()
  if win <> None
    DestroyNode( win )
  .
  win = CreateNodeFromPrototype("TMP_Facegen")
  win.build = true
  MiscUtils:centerWindow(win)
.

//=============================================================================
// a few more commands for character heading (or other Behave) can be found
// in script E_ACCControllerClassMethods in method _onBehave()
//=============================================================================

// freeze camera for facegen
// with heading set to face, you can swing camera around character
function setCameraFacegen(button as NodeRef of Class _GUIButton)
  lbl as NodeRef of Class GUILabel = FindGUIControlByName(button, "text")
  lbl.text = "Locked"

  meNode as NodeRef = GetPlayerCharacterNode()
  meNode["Behave"] = "input IdleType Muted"
  meNode["Behave"] = "heading face 0.0"
.

// release camera for facegen
function removeCameraFacegen(button as NodeRef of Class _GUIButton)
  lbl as NodeRef of Class GUILabel = FindGUIControlByName(button, "text")
  lbl.text = "Free"

  meNode as NodeRef = GetPlayerCharacterNode()
  meNode["Behave"] = "clear"
  meNode["Behave"] = "movetype normal"
  meNode["Behave"] = "heading camera"
.

// buttons used in Create Character section
method _OnButtonMouseClick(button as NodeRef of Class _GUIButton, args references Class GUIMouseEvent)
  when button.name
    is "faceON"
      removeCameraFacegen(button)
      button.name = "faceOFF"
    .
    is "faceOFF"
      setCameraFacegen(button)
      button.name = "faceON"
    .
  .
.

// get user input
method _onSliderValueChange(args references Class GUIValueChangeEvent)
  slide as NodeRef of Class GUISlider = args.source
  Val as Float = (stof(args.value) + 10) / 20     // calc 0.0 - 1.0 values
  var pc = GetPlayerCharacterNode()

  when slide.parent.name
    is "weightSlider"
      SetBodyRaceBlend(pc, "largehuman", Val)
    .
    is "heightSlider"
      nVal as Float = Val + 0.5
      SetNodeScale(pc, (nVal,nVal,nVal))
    .
  .

  // brow cheek chin eyes face forehead jaw mouth nose
  faceData as List of String
  data as String = "5/6/29/8/10/12/16/18/19/21/22/23/26/27/28/29/30/31/33/34/35/37/38/40/47/51/57"
  SplitBy(data,"/",faceData)              // make it an array

  name as String = subString(slide.parent.parent.name, 1, 5)          // pull name from slider
  num as Integer = replaceString(slide.parent.parent.name, name, "")  // get number for data offset
  // (num - 1)    is base offset
  // * 3          is for groups of 3
  // + 1 at end   is for arrays start with 1

  when name
    is "panel"
      when slide.parent.name
        is "slider1"
          SetFaceShapeControlValue(pc, stoi( faceData[(num-1) *3 +1] ), args.value)
        .
        is "slider2"
          SetFaceShapeControlValue(pc, stoi( faceData[(num-1) *3 +2] ), args.value)
        .
        is "slider3"
          SetFaceShapeControlValue(pc, stoi( faceData[(num-1) *3 +3] ), args.value)
        .
      .
    .
  .
.

//=================================================================================================
// get main class
public function getFacegenClass() as NodeRef of Class TMP_Facegen
  return FindGUIControlByName(None, "game.TMP_Facegen")
.

__________________________________________________________
In new (XML) script TMP_ facePanel

Code: [Select]
<createControlType inheritFrom='_panel' type='TMP_facePanel' description='' treePath='CleanEngine' name="TMP_facePanel">
  <size x="270" y="20"/>
  <defaultStatePresentation>
    <color a="0"/>
  </defaultStatePresentation>
  <_slider name="slider1" insertBefore="slider2">
    <position x="60"/>
    <size x="60"/>
    <set name="TMP_facePanel.slider1.thumb">
      <position x="25"/>
    </set>
  </_slider>
  <_slider name="slider2" insertBefore="slider3">
    <position x="130"/>
    <size x="60"/>
    <set name="TMP_facePanel.slider2.thumb">
      <position x="25"/>
    </set>
  </_slider>
  <_slider name="slider3" insertBefore="text">
    <position x="200"/>
    <size x="60"/>
    <set name="TMP_facePanel.slider3.thumb">
      <position x="25"/>
    </set>
  </_slider>
  <_label name="text" text="eyes">
    <defaultStatePresentation>
      <color r="1" g="0" b="0"/>
    </defaultStatePresentation>
  </_label>
</createControlType>

__________________________________________________________
In new (XML) script TMP_ Facegen

Code: [Select]
<createControlType inheritFrom='TMP_Window' class='TMP_Facegen' type='TMP_Facegen' description='facegen sliders' treePath='' name="TMP_Facegen">
  <size x="270" y="240"/>
  <defaultStatePresentation>
    <color r="0" g="0" b="0" a="0.5"/>
  </defaultStatePresentation>
  <set name="TMP_Facegen.BGpanel">
    <size x="262" y="232"/>
  </set>
  <_label name="text" text="Facegen" justification="CENTER">
    <defaultStatePresentation>
      <color r="1" g="0" b="0"/>
    </defaultStatePresentation>
    <autoCenter horizontal="true"/>
  </_label>
  <_label name="text" text="weight">
    <position x="5" y="20"/>
    <defaultStatePresentation>
      <color r="1" g="0" b="0"/>
    </defaultStatePresentation>
  </_label>
  <_slider name="weightSlider">
    <position x="60" y="20"/>
    <size x="100"/>
    <set name="TMP_Facegen.weightSlider.thumb">
      <position x="45"/>
    </set>
  </_slider>
  <_label name="text" text="height">
    <position x="5" y="40"/>
    <defaultStatePresentation>
      <color r="1" g="0" b="0"/>
    </defaultStatePresentation>
  </_label>
  <_slider name="heightSlider">
    <position x="60" y="40"/>
    <size x="100"/>
    <set name="TMP_Facegen.heightSlider.thumb">
      <position x="45"/>
    </set>
  </_slider>
  <TMP_facePanel name="panel1">
    <position y="60"/>
    <set name='TMP_Facegen.panel1.text' attribute='text' value="brow"/>
  </TMP_facePanel>
  <TMP_facePanel name="panel2">
    <position y="80"/>
    <set name='TMP_Facegen.panel2.text' attribute='text' value="cheek"/>
  </TMP_facePanel>
  <TMP_facePanel name="panel3">
    <position y="100"/>
    <set name='TMP_Facegen.panel3.text' attribute='text' value="chin"/>
  </TMP_facePanel>
  <TMP_facePanel name="panel4">
    <position y="120"/>
  </TMP_facePanel>
  <TMP_facePanel name="panel5">
    <position y="140"/>
    <set name='TMP_Facegen.panel5.text' attribute='text' value="face"/>
  </TMP_facePanel>
  <TMP_facePanel name="panel6">
    <position y="160"/>
    <set name='TMP_Facegen.panel6.text' attribute='text' value="forehead"/>
  </TMP_facePanel>
  <TMP_facePanel name="panel7">
    <position y="180"/>
    <set name='TMP_Facegen.panel7.text' attribute='text' value="jaw"/>
  </TMP_facePanel>
  <TMP_facePanel name="panel8">
    <position y="200"/>
    <set name='TMP_Facegen.panel8.text' attribute='text' value="mouth"/>
  </TMP_facePanel>
  <TMP_facePanel name="panel9">
    <position y="220"/>
    <set name='TMP_Facegen.panel9.text' attribute='text' value="nose"/>
  </TMP_facePanel>
  <tmp_button name="faceOFF">
    <position x="200" y="5"/>
    <size x="50"/>
    <set name='TMP_Facegen.faceOFF.text' attribute='text' value="toggle"/>
    <set name='TMP_Facegen.faceOFF.text' attribute='displayfont' value="SMALLTEXT"/>
  </tmp_button>
</createControlType>

__________________________________________________________
In (clientside) script E_PlayerAccountClassMethods under the chatwindow

Code: [Select]
        TMP_FacegenClassMethods:Start()
« Last Edit: Jun 01, 15, 06:02:48 PM by Thazager »
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1155
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: facegen and body
« Reply #1 on: Aug 27, 14, 11:06:43 PM »

Updated to add face camera, which shows how to lock and unlock the character direction (facing). Also added more face parts and a 3rd slider, showing how they can be used in a database.
Logged