Skip to content

Commit

Permalink
3.2 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Grumoth committed Mar 8, 2020
1 parent 019a636 commit 2c71cad
Show file tree
Hide file tree
Showing 26 changed files with 204 additions and 182 deletions.
56 changes: 28 additions & 28 deletions GUI/EditBehaviour.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,22 @@ var currentShape:String ; var previousShape:String
onready var camera:Camera = get_parent().get_parent().get_node("CameraMenu")
var mouseTarget:MeshInstance ;
var headMat:Material;var torsoMat:Material;var armsMat:Material;var legsMat:Material
onready var mainRig:Skeleton=get_parent().get_parent().get_node("MainCharacter/MainRig")
onready var mainRig:Skeleton=get_parent().get_parent().get_node("MainCharacter/MainRig/Skeleton")
var head:MeshInstance;var currentBeard:MeshInstance;var currentHair:MeshInstance
func _ready():
mouseTarget = get_parent().get_parent().get_node("MainCharacter/MouseTarget")
yield(get_tree(),"idle_frame")



yield(get_tree(),"idle_frame")
head = mainRig.get_node("head")
headMat = mainRig.get_node("head").get_surface_material(0)
torsoMat = mainRig.get_node("torso").get_surface_material(0)
armsMat = mainRig.get_node("arms").get_surface_material(0)
legsMat = mainRig.get_node("legs").get_surface_material(0)


yield(get_tree(),"idle_frame")
currentBeard = mainRig.find_node("beard?",true,false)
currentHair = mainRig.find_node("hair?",true,false)

currentBeard = mainRig.get_parent().find_node("beard?",true,false)
currentHair = mainRig.get_parent().find_node("hair?",true,false)

func _process(delta):
#BLOCK INPUT ON THE BOTTON MENU
Expand Down Expand Up @@ -60,7 +59,7 @@ func _rayCastFromMouse(mousePos):
var rayStart = get_viewport().get_camera().get_camera_transform().origin
var rayEnd = rayStart+camera.project_ray_normal(mousePos)*1000

var spaceState:BulletPhysicsDirectSpaceState = get_parent().get_parent().get_world().direct_space_state
var spaceState:PhysicsDirectSpaceState = get_parent().get_parent().get_world().direct_space_state
return spaceState.intersect_ray(rayStart,rayEnd,[],1)

func _highLight():
Expand All @@ -74,7 +73,7 @@ func _highLight():
armsMat.set_shader_param("idMask",ResourceLoader.load(maskNull))
legsMat.set_shader_param("idMask",ResourceLoader.load(maskNull))
else:
if currentShape=="spine1" or currentShape=="spine2" or currentShape=="spine3":
if currentShape=="spine_1" or currentShape=="spine_2" or currentShape=="spine_3":
torsoMat.set_shader_param("idMask",ResourceLoader.load(mask))
armsMat.set_shader_param("idMask",ResourceLoader.load(maskNull))
legsMat.set_shader_param("idMask",ResourceLoader.load(maskNull))
Expand Down Expand Up @@ -116,7 +115,6 @@ func _grab():
_grabBones(mouseX,mouseY)

func _grabHeadShapes(mouseX,mouseY):
# return
#--------------GET THE CHARACTER ROTATION
var rot:float = rad2deg(mainRig.get_parent().rotation.y)
var limit:float = 10
Expand Down Expand Up @@ -176,57 +174,59 @@ func _grabBones(mouseX:float,mouseY:float):
var thisBone = mainRig.find_bone(currentShape)
var t:Transform
var t2:Transform
if currentShape=="spine1" or currentShape=="spine2":


if currentShape=="spine_1" or currentShape=="spine_2":
var scaleLimit:float = 0.02

if scaleAmountY>=-scaleLimit and scaleAmountY<=scaleLimit:
t=t.translated(Vector3(0,-scaleAmountY,0))
mainRig.set_bone_custom_pose(thisBone,t)


if currentShape=="spine3":
if currentShape=="spine_3":
var scaleLimit:float = 0.03
if scaleAmountX>=-scaleLimit and scaleAmountX<=scaleLimit:
t=t.translated(Vector3(0,scaleAmountX,0))
mainRig.set_bone_custom_pose(mainRig.find_bone("shoulder_L"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("shoulder_R"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("shoulder_l"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("shoulder_r"),t)
#t2-----Different transform to avoid problems
if scaleAmountY>=-scaleLimit and scaleAmountY<=scaleLimit:
t2=t2.translated(Vector3(0,-scaleAmountY,0))
mainRig.set_bone_custom_pose(mainRig.find_bone("spine3"),t2)
mainRig.set_bone_pose(mainRig.find_bone("spine_3"),t2)

if currentShape=="upper":
var scaleLimit:float = 0.03
if scaleAmountY>=-scaleLimit and scaleAmountY<=scaleLimit:
t=t.translated(Vector3(0,scaleAmountY,0))
mainRig.set_bone_custom_pose(mainRig.find_bone("upper_arm_R"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("upper_arm_L"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("upper_arm_l"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("upper_arm_r"),t)
if currentShape=="forearm":
var scaleLimit:float = 0.08
if scaleAmountY>=-0.02 and scaleAmountY<=scaleLimit:
t=t.translated(Vector3(0,scaleAmountY,0))
mainRig.set_bone_custom_pose(mainRig.find_bone("forearm_R"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("forearm_L"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("forearm_r"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("forearm_l"),t)
if currentShape=="thigh":
var scaleLimit:float = 0.05
if scaleAmountY>=-scaleLimit and scaleAmountY<=scaleLimit:
t=t.translated(Vector3(0,-scaleAmountY,0))
mainRig.set_bone_custom_pose(mainRig.find_bone("thigh_R"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("thigh_L"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("spine"),t*mainRig.get_bone_custom_pose(mainRig.find_bone("shin_R")))
mainRig.set_bone_custom_pose(mainRig.find_bone("thigh_r"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("thigh_l"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("spine"),t*mainRig.get_bone_custom_pose(mainRig.find_bone("shin_l")))
if currentShape=="shin":
var scaleLimit:float = 0.05
if scaleAmountY>=-scaleLimit and scaleAmountY<=scaleLimit:
t=t.translated(Vector3(0,-scaleAmountY,0))
mainRig.set_bone_custom_pose(mainRig.find_bone("shin_R"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("shin_L"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("spine"),t*mainRig.get_bone_custom_pose(mainRig.find_bone("thigh_R")))
mainRig.set_bone_custom_pose(mainRig.find_bone("shin_r"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("shin_l"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("spine"),t*mainRig.get_bone_custom_pose(mainRig.find_bone("thigh_r")))
if currentShape=="foot":
var scaleLimit:float = 0.05
if scaleAmountX>=-scaleLimit and scaleAmountX<=scaleLimit:
t=t.translated(Vector3(0,scaleAmountX,0))
mainRig.set_bone_custom_pose(mainRig.find_bone("toe_R"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("toe_L"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("toe_r"),t)
mainRig.set_bone_custom_pose(mainRig.find_bone("toe_l"),t)
if currentShape=="fullHead":
var scaleLimit:float = 0.1
if scaleAmountX>=-scaleLimit and scaleAmountX<=scaleLimit:
Expand All @@ -236,5 +236,5 @@ func _grabBones(mouseX:float,mouseY:float):
_adjustFaceCamHeight()

func _adjustFaceCamHeight():
var faceCam:Camera = mainRig.get_parent().get_node("faceViewport/faceCam")
var faceCam:Camera = mainRig.get_parent().get_parent().get_node("faceViewport/faceCam")
faceCam.translation.y = mainRig.get_bone_global_pose(mainRig.find_bone("head")).origin.y +0.1
18 changes: 9 additions & 9 deletions GUI/Randomizer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func _randomizeGUIvalues():
p.get_node("Panel/vb/head/vb/facePaintColor_head")._on_colorPicker_color_changed(randPaintColor)

func _randomizeBones():
var sk = p.character.get_node("MainRig")
var sk = p.character.sk
randomize()
#-------3 STEPS FOR READABILITY
for i in 3:
Expand All @@ -58,22 +58,22 @@ func _randomizeBones():

var t2:Transform
t2=t2.translated(Vector3(0,rand_range(-scaleLimit,scaleLimit),0))
sk.set_bone_custom_pose(sk.find_bone("shoulder_L"),t2)
sk.set_bone_custom_pose(sk.find_bone("shoulder_R"),t2)
sk.set_bone_custom_pose(sk.find_bone("shoulder_l"),t2)
sk.set_bone_custom_pose(sk.find_bone("shoulder_r"),t2)

var t3:Transform
t3=t3.translated(Vector3(0,rand_range(-scaleLimit,scaleLimit),0))
sk.set_bone_custom_pose(sk.find_bone("spine3"),t3)
sk.set_bone_custom_pose(sk.find_bone("spine_3"),t3)

if i==1:
var scaleLimit:float=0.02
var t:Transform
t=t.translated(Vector3(0,rand_range(-scaleLimit,scaleLimit),0))
sk.set_bone_custom_pose(sk.find_bone("spine1"),t)
sk.set_bone_custom_pose(sk.find_bone("spine_1"),t)

var t2:Transform
t2=t2.translated(Vector3(0,rand_range(-scaleLimit,scaleLimit),0))
sk.set_bone_custom_pose(sk.find_bone("spine2"),t2)
sk.set_bone_custom_pose(sk.find_bone("spine_2"),t2)

var t3:Transform
t3=t3.translated(Vector3(0,rand_range(-scaleLimit,scaleLimit),0))
Expand Down Expand Up @@ -107,9 +107,9 @@ func _randomizeBones():
p.get_node("EditBehaviour")._adjustFaceCamHeight()

func _randomizeShapes():
var head = p.character.get_node("MainRig/head")
var currentBeard:MeshInstance = p.character.get_node("MainRig").find_node("beard?",true,false)
var currentHair:MeshInstance = p.character.get_node("MainRig").find_node("hair?",true,false)
var head = p.character.sk.get_node("head")
var currentBeard:MeshInstance = p.character.sk.find_node("beard?",true,false)
var currentHair:MeshInstance = p.character.sk.find_node("hair?",true,false)
randomize()

for b in head.mesh.get_blend_shape_count():
Expand Down
2 changes: 1 addition & 1 deletion Game/CameraMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func _ready():
_setZoomTarget()

func _setZoomTarget():
var y =character.get_node("MainRig/attachHead").transform.origin +zoomOffset
var y =character.get_node("MainRig/Skeleton/attachHead").transform.origin +zoomOffset
zoomTarget=Vector3(0,y.y,y.z)

func _input(event):
Expand Down
2 changes: 0 additions & 2 deletions Game/Save.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ func _loadCharacter(n):
fileSave.open(savePathCharacter+n+ext,File.READ)
var charData:Dictionary = parse_json(fileSave.get_line())
return charData
pass


func _savePreset(n:String,data:Dictionary):
Expand All @@ -28,5 +27,4 @@ func _loadPreset(n):
fileSave.open(savePathPreset+n+ext,File.READ)
var charData:Dictionary = parse_json(fileSave.get_line())
return charData
pass

35 changes: 18 additions & 17 deletions MainCharacter/MainCharacter.gd
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tool
extends Spatial
tool

onready var sk:Skeleton = get_node("MainRig")
onready var sk:Skeleton = $MainRig/Skeleton
var parts:Array = ["head","torso","arms","legs"]
var bonesMod:Array = ["spine3","spine2","spine1","thigh_L","thigh_R","shin_L","forearm_L","forearm_R","shin_R","upper_arm_L","upper_arm_R","foot_L","foot_R","shoulder_L","shoulder_R"]
var bonesMod:Array = ["spine_3","spine_2","spine_1","thigh_l","thigh_r","shin_l","forearm_l","forearm_r","shin_r","upper_arm_l","upper_arm_r","foot_l","foot_r","shoulder_l","shoulder_r"]

onready var faceCam:Camera ;onready var faceViewport:Viewport

Expand Down Expand Up @@ -35,16 +35,17 @@ var preset:Dictionary={
}
func _ready():
# if not Engine.editor_hint:
$AnimationPlayer.play("idle")
$AnimationPlayer.get_animation("idle").loop=true
$AnimationPlayer.play("idle")
# $AnimationPlayer.play("idle2")
_generate()
$MouseTarget.set_as_toplevel(true)
faceCam=$faceViewport/faceCam
faceViewport = $faceViewport


func _generate():
$MainRig/dummy.queue_free()
$MainRig/Skeleton/dummy.queue_free()
for p in parts:
var scenePart:Spatial = ResourceLoader.load("res://MainCharacter/Mesh/Parts/"+p+".glb").instance()
var mesh:MeshInstance = scenePart.get_child(0).get_child(0).duplicate()
Expand All @@ -53,8 +54,8 @@ func _generate():
var mat:ShaderMaterial = matSkin.duplicate()
mesh.set_surface_material(0,mat)
#----------------------MESH RENAME BECAUSE IT WAS IMPOSSIBLE TO IMPORT IT AS "HEAD"
if mesh.name=="head 2":
mesh.name="head"
if mesh.name=="head":
# mesh.name="head"
headMat=mat
mat.set_shader_param("hairMask",ResourceLoader.load("res://MainCharacter/Material/Textures/subHair/subHair1_mask.jpg"))
else:
Expand Down Expand Up @@ -83,14 +84,13 @@ func _generate():
mesh.set_surface_material(2,matCornea)
if p =="legs":
mesh.set_surface_material(1,matUnderwear)
$MainRig.add_child(mesh)
sk.add_child(mesh)
#--HAIR
head=$MainRig.get_node("head")
head=sk.get_node("head")
arrayMat=[headMat,torsoMat,armsMat,legsMat]


func _setMaterialParameter(param:String,part:String,col):
var mat:Material
var mat:ShaderMaterial
if part=="eyes":
mat=matEye
elif part=="hair":
Expand All @@ -100,9 +100,9 @@ func _setMaterialParameter(param:String,part:String,col):
else:
mat=headMat
mat.set_shader_param(param,col)

func _setParameterTexture(v,part,prop):
var mat = $MainRig.get_node(part).get_surface_material(0)
var mat = sk.get_node(part).get_surface_material(0)
mat.set_shader_param(prop,ResourceLoader.load("res://MainCharacter/Material/Textures/"+prop+"/"+prop+str(v)+"_mask.jpg"))

func _setChubbiness(v):
Expand All @@ -124,12 +124,12 @@ func _setChubbiness(v):

func _setBlendShape(part:String,prop:String,v:float):
yield(get_tree(),"idle_frame")
var n = $MainRig.find_node(part+"?",true,false)
var n = sk.find_node(part+"?",true,false)
n.set("blend_shapes/"+prop,v)


func _setMesh(part,v):
var n = $MainRig.find_node(part+"?",true,false)
var n = sk.find_node(part+"?",true,false)
if n:
n.queue_free()
yield(n,"tree_exited")
Expand All @@ -156,7 +156,7 @@ func _setMesh(part,v):
beardMat=matHair.duplicate()
mesh.set_surface_material(0,beardMat)

$MainRig.add_child(mesh)
sk.add_child(mesh)
_matchBlendShapes(mesh)

func _matchBlendShapes(mesh):
Expand All @@ -170,6 +170,7 @@ func _setSkinColor(c):
var sum = c[0]+c[1]+c[2]
var roughTweak = range_lerp(sum,0,3,1,0.5)
for mat in arrayMat:
print(mat)
mat.set_shader_param("skinTone",c)
mat.set_shader_param("rPunch",roughTweak)

Expand Down Expand Up @@ -200,7 +201,7 @@ func _setBone(b:String,data):
var bone = sk.find_bone(b)
t=t.translated(Vector3(0,data.bonesY[b],0))
sk.set_bone_custom_pose(bone,t)
var t4 = sk.get_bone_custom_pose(sk.find_bone("thigh_R")) *sk.get_bone_custom_pose(sk.find_bone("shin_R"))
var t4 = sk.get_bone_custom_pose(sk.find_bone("thigh_r")) *sk.get_bone_custom_pose(sk.find_bone("shin_r"))
sk.set_bone_custom_pose(sk.find_bone("spine"),t4)


Expand Down
Loading

0 comments on commit 2c71cad

Please sign in to comment.