Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,55 @@
{
"description": "",
"materialType": "Materials/Types/StandardPBR.materialtype",
"parentMaterial": "",
"propertyLayoutVersion": 3,
"properties": {
"ambientOcclusion": {
"factor": 1.0,
"useTexture": true,
"textureMap": "EngineAssets/TextureMsg/DefaultNoUVs.tif"
},
"baseColor": {
"color": [ 1.0, 1.0, 1.0 ],
"factor": 1.0,
"useTexture": true,
"textureMap": "EngineAssets/TextureMsg/DefaultNoUVs.tif"
},
"emissive": {
"color": [ 1.0, 1.0, 1.0 ],
"intensity": 1.0,
"useTexture": false,
"textureMap": "EngineAssets/TextureMsg/DefaultNoUVs.tif"
},
"metallic": {
"factor": 0.0,
"useTexture": false,
"textureMap": ""
},
"roughness": {
"factor": 1.0,
"useTexture": true,
"textureMap": "EngineAssets/TextureMsg/DefaultNoUVs_spec.tif"
},
"specularF0": {
"factor": 0.5,
"useTexture": false,
"textureMap": ""
},
"normal": {
"factor": 1.0,
"useTexture": true,
"textureMap": "EngineAssets/TextureMsg/DefaultNoUVs_ddn.tif"
},
"opacity": {
"doubleSided": false,
"factor": 1.0,
"cutoutAlpha": false,
"cutoutThreshold": 0.5,
"useBaseColorTextureAlpha": false,
"useTexture": false,
"textureMap": ""
}
}
}
@@ -0,0 +1,14 @@
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
__all__ = ['atom_mat',
'fbx_to_atom',
'stingraypbs_converter',
'stingraypbs_converter_maya']
@@ -0,0 +1,66 @@
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
#
# -- This line is 75 characters -------------------------------------------
"""
Module Documentation: To Do
"""
# -------------------------------------------------------------------------
# built-ins
import json
# 3rdParty
from box import Box
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
class AtomMaterial:
def __init__(self, material_file):
'''To Do: document'''
# loading .material Files
self.material_file = material_file
self.input_data = open(self.material_file, "r")
self.material = json.load(self.input_data)
self.mat_box = Box(self.material)
self.input_data.close()
# Texture map dictionary:
self.texture_map = {'ambientOcclusion': 'ambientOcclusion',
'baseColor': 'baseColor',
'emissive': 'emissive',
'metallic': 'metallic',
'roughness': 'roughness',
'specularF0': 'specular',
'normal': 'normal',
'opacity': 'opacity'
}
def load(self, material_file):
input_data = open(material_file, "r")
self.material = json.load(input_data)
self.mat_box = Box(self.material)
input_data.close()
def getBaseMaterial(self):
return self.mat_box.material.baseMaterial
def getMap(self, tex_slot):
return self.mat_box.properties[tex_slot].textureMap
def setMap(self, tex_slot, tex_map):
self.mat_box.properties[tex_slot].textureMap = tex_map
self.mat_box.properties[tex_slot].useTexture = True
self.mat_box.properties[tex_slot].factor = 1.0
def write(self, material_out):
output_data = open(material_out, "w+")
output_data.write(json.dumps(self.mat_box, indent=4))
output_data.close()
# -------------------------------------------------------------------------
@@ -0,0 +1,67 @@
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
#
# -- This line is 75 characters -------------------------------------------
import simplejson as json
from box import Box
from atom_mat import AtomMaterial as atomMat
"""
The idea behind this script is to convert FBX to glTF in order to take advantage of glTF format
FBX2glTF CLT:
https://github.com/facebookincubator/FBX2glTF
ToDo:
Add FBX2glTF subprocess to the script.
"""
atom_material = atomMat("C:\\atom\\dev\\AtomTest\\Editor\\Scripts\\atom\\maya\\StandardPBR_AllProperties.material")
""" All these path could be in configure file or bootstrapped """
fbx_root = 'C:\\atom\\dev\\Gems\\AtomContent\\AtomDemoContent\\Assets\\Objects\\Peccy\\'
rel_root = "C:\\atom\\dev\\Gems\\AtomContent\\AtomDemoContent\\Assets\\"
texture_root = 'Objects\\Peccy\\'
# -------------------------------------------------------------------------
class FBX:
def __init__(self, fbx_file):
self.fbx_file = fbx_file
self.glTF_file = self.fbx_file.replace("fbx", "gltf")
self.input_data = open(self.glTF_file, "r")
self.glTF_properties = json.load(self.input_data)
self.glTF_box = Box(self.glTF_properties)
self.input_data.close()
def get_material_names(self):
return self.glTF_box.materials
def get_textures(self, index):
return self.glTF_box.images[index]
def create_atom_material(self):
for mat_index in range(len(fbx01.get_material_names())):
baseColorTexture_index = self.get_material_names()[mat_index].pbrMetallicRoughness.baseColorTexture.index
atom_material.setMap(atom_material.texture_map['baseColor'], texture_root +
self.get_textures(baseColorTexture_index).uri)
normalTexture_index = self.get_material_names()[mat_index].normalTexture.index
atom_material.setMap(atom_material.texture_map['normal'], texture_root +
self.get_textures(normalTexture_index).uri)
roughnessTexture_index = self.get_material_names()[mat_index].\
pbrMetallicRoughness.metallicRoughnessTexture.index
atom_material.setMap(atom_material.texture_map['roughness'], texture_root +
self.get_textures(roughnessTexture_index).uri)
atom_material.write(rel_root + "\\Materials\\" + fbx01.get_material_names()[mat_index].name + ".material")
# -------------------------------------------------------------------------
if __name__ == "__main__":
fbx01 = FBX(fbx_root + 'peccy_01.fbx')
fbx01.create_atom_material()
@@ -0,0 +1,121 @@
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
import os
import site
from unipath import Path
import click
import glob
# -------------------------------------------------------------------------
def returnStubDir(stub):
_DIRtoLastFile = None
'''Take a file name (stub) and returns the directory of the file (stub)'''
if _DIRtoLastFile is None:
path = os.path.abspath(__file__)
while 1:
path, tail = os.path.split(path)
if (os.path.isfile(os.path.join(path, stub))):
break
if (len(tail) == 0):
path = ""
if _G_DEBUG:
print('~ Debug Message: I was not able to find the '
'path to that file (stub) in a walk-up from currnet path')
break
_DIRtoLastFile = path
return _DIRtoLastFile
# --------------------------------------------------------------------------
# Paths for the quick tests. These could throw a UI or a configuration on it.
_DEV_ROOT = Path(returnStubDir('engineroot.txt')).resolve() #hopefully safe
_REL_ROOT = Path(_DEV_ROOT, 'AtomTest').resolve()
_MAYA_SCRIPTS = Path(_REL_ROOT, 'Editor/Scripts/atom/maya').resolve()
site.addsitedir(_MAYA_SCRIPTS)
from atom_mat import AtomMaterial as atomMAT
_ATOM_MAT_TEMPLATE = atomMAT(Path(_MAYA_SCRIPTS,
'StandardPBR_AllProperties.material').resolve())
_model_asset_dir = Path(_REL_ROOT, 'Objects/Characters/Peccy').resolve()
_atom_mat_path = Path(_REL_ROOT, 'Objects/Characters/Peccy').resolve()
import pymel.core as pm
def converter(_model_asset_dir, _atom_mat_path):
_maya_file = glob.glob(_model_asset_dir + '*.ma')
print(_maya_file)
for maya in range(len(_maya_file)):
pm.openFile(_maya_file[maya], f=True, prompt=False)
set_stingray_properties()
# This is ugly but work.
# To to: remove all of duplications.
def set_stingray_properties():
nodes = pm.ls(dag=1, o=1, s=1)
shade_eng = pm.listConnections(nodes, type=pm.nt.ShadingEngine)
materials = pm.ls(pm.listConnections(shade_eng), materials=1)
mat = []
for i in materials:
if i not in mat:
mat.append(i)
print(mat)
for j in range(len(mat)):
file_node_baseColor = pm.listConnections(mat[j].TEX_color_map)
if (file_node_baseColor and pm.objectType(file_node_baseColor[0]) == 'file'
and pm.getAttr(mat[j].use_color_map)):
tex_baseColor = Path(pm.getAttr(file_node_baseColor[0].fileTextureName)).norm().replace(_REL_ROOT, "")
_ATOM_MAT_TEMPLATE.setMap(_ATOM_MAT_TEMPLATE.texture_map['baseColor'], tex_baseColor)
# else:
# _baseColor = pm.getAttr(mat[j].base_color)
# _ATOM_MAT_TEMPLATE.setColor(_ATOM_MAT_TEMPLATE.texture_map['baseColor'], _baseColor)
# print(mat[j])
# print(baseColor)
file_node_normal = pm.listConnections(mat[j].TEX_normal_map)
if (file_node_normal and pm.objectType(file_node_normal[0]) == 'file'
and pm.getAttr(mat[j].use_normal_map)):
tex_normal = Path(pm.getAttr(file_node_normal[0].fileTextureName)).norm().replace(_REL_ROOT, "")
_ATOM_MAT_TEMPLATE.setMap(_ATOM_MAT_TEMPLATE.texture_map['normal'], tex_normal)
file_node_metallic = pm.listConnections(mat[j].TEX_metallic_map)
if (file_node_metallic and pm.objectType(file_node_metallic[0]) == 'file'
and pm.getAttr(mat[j].use_metallic_map)):
tex_metallic = Path(pm.getAttr(file_node_metallic[0].fileTextureName)).norm().replace(_REL_ROOT, "")
_ATOM_MAT_TEMPLATE.setMap(_ATOM_MAT_TEMPLATE.texture_map['metallic'], tex_metallic)
file_node_roughness = pm.listConnections(mat[j].TEX_roughness_map)
if (file_node_roughness and pm.objectType(file_node_roughness[0]) == 'file'
and pm.getAttr(mat[j].use_roughness_map)):
file_node_roughness = pm.listConnections(mat[j].TEX_roughness_map)
tex_roughness = Path(pm.getAttr(file_node_roughness[0].fileTextureName)).norm().replace(_REL_ROOT, "")
_ATOM_MAT_TEMPLATE.setMap(_ATOM_MAT_TEMPLATE.texture_map['roughness'], tex_roughness)
file_node_ao = pm.listConnections(mat[j].TEX_ao_map)
if (file_node_ao and pm.objectType(file_node_ao[0]) == 'file'
and pm.getAttr(mat[j].use_ao_map)):
tex_ao = Path(pm.getAttr(file_node_ao[0].fileTextureName)).norm().replace(_REL_ROOT, "")
_ATOM_MAT_TEMPLATE.setMap(_ATOM_MAT_TEMPLATE.texture_map['ambientOcclusion'], tex_ao)
_ATOM_MAT_TEMPLATE.write(_REL_ROOT + "\\Materials\\" + str(mat[j])+".material")
@click.command()
@click.option('--maya', default=_model_asset_dir, help='Maya file folder')
@click.option('--output', default=_atom_mat_path, help='Atom Material output path')
def stingrayPBS_converter(maya, output):
click.echo(converter(maya, output))
if __name__ == '__main__':
stingrayPBS_converter()
@@ -0,0 +1,117 @@
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
#
# -- This line is 75 characters -------------------------------------------
import os
import site
from unipath import Path
import maya.cmds as cmds
# -------------------------------------------------------------------------
def returnStubDir(stub, start_path):
_DIRtoLastFile = None
'''Take a file name (stub) and returns the directory of the file (stub)'''
if _DIRtoLastFile is None:
path = os.path.abspath(start_path)
while 1:
path, tail = os.path.split(path)
if (os.path.isfile(os.path.join(path, stub))):
break
if (len(tail) == 0):
path = ""
if _G_DEBUG:
print('~ Debug Message: I was not able to find the '
'path to that file (stub) in a walk-up from currnet path')
break
_DIRtoLastFile = path
return _DIRtoLastFile
# --------------------------------------------------------------------------
# Paths for the quick tests. These could throw a UI or a configuration on it.
_ASSET_PATH = Path(cmds.file(q=True, sn=True)).parent.resolve()
_DEV_ROOT = Path(returnStubDir('engineroot.txt', _ASSET_PATH)).resolve() # hopefully safe
_REL_ROOT = Path(_DEV_ROOT, 'AtomTest').resolve()
_MAYA_SCRIPTS = Path(_REL_ROOT, 'Editor/Scripts/atom/maya').resolve()
site.addsitedir(_MAYA_SCRIPTS)
from atom_mat import AtomMaterial as atomMAT
_ATOM_MAT_TEMPLATE = atomMAT(Path(_MAYA_SCRIPTS,
'StandardPBR_AllProperties.material').resolve())
import pymel.core as pm
class StingrayPBS(object):
def __init__(self):
# Append material from selected object(S)
nodes = pm.ls(dag=1, o=1, s=1, sl=1)
shade_eng = pm.listConnections(nodes, type=pm.nt.ShadingEngine)
material = pm.ls(pm.listConnections(shade_eng), materials=1)
self.mat = []
for i in material:
if i not in self.mat:
self.mat.append(i)
# Make a StringrayPBS instance
strpbs = StingrayPBS()
# This is ugly but work.
# To to: remove all of duplications.
for i in range(len(strpbs.mat)):
file_node_baseColor = pm.listConnections(strpbs.mat[i].TEX_color_map)
if (file_node_baseColor and pm.objectType(file_node_baseColor[0]) == 'file'
and pm.getAttr(strpbs.mat[i].use_color_map)):
tex_baseColor = Path(pm.getAttr(file_node_baseColor[0].fileTextureName)).resolve()
tex_baseColor = _REL_ROOT.rel_path_to(tex_baseColor)
tex_baseColor = tex_baseColor.replace('\\', '/')
_ATOM_MAT_TEMPLATE.setMap(_ATOM_MAT_TEMPLATE.texture_map['baseColor'], tex_baseColor)
# else:
# _baseColor = pm.getAttr(strpbs.mat[i].base_color)
# _ATOM_MAT_TEMPLATE.setColor(_ATOM_MAT_TEMPLATE.texture_map['baseColor'], _baseColor)
# print(strpbs.mat[i])
# print(baseColor)
file_node_normal = pm.listConnections(strpbs.mat[i].TEX_normal_map)
if (file_node_normal and pm.objectType(file_node_normal[0]) == 'file'
and pm.getAttr(strpbs.mat[i].use_normal_map)):
tex_normal = Path(pm.getAttr(file_node_normal[0].fileTextureName)).resolve()
tex_normal = _REL_ROOT.rel_path_to(tex_normal)
tex_normal = tex_normal.replace('\\', '/')
_ATOM_MAT_TEMPLATE.setMap(_ATOM_MAT_TEMPLATE.texture_map['normal'], tex_normal)
file_node_metallic = pm.listConnections(strpbs.mat[i].TEX_metallic_map)
if (file_node_metallic and pm.objectType(file_node_metallic[0]) == 'file'
and pm.getAttr(strpbs.mat[i].use_metallic_map)):
tex_metallic = Path(pm.getAttr(file_node_metallic[0].fileTextureName)).resolve()
tex_metallic = _REL_ROOT.rel_path_to(tex_metallic)
tex_metallic = tex_metallic.replace('\\', '/')
_ATOM_MAT_TEMPLATE.setMap(_ATOM_MAT_TEMPLATE.texture_map['metallic'], tex_metallic)
file_node_roughness = pm.listConnections(strpbs.mat[i].TEX_roughness_map)
if (file_node_roughness and pm.objectType(file_node_roughness[0]) == 'file'
and pm.getAttr(strpbs.mat[i].use_roughness_map)):
file_node_roughness = pm.listConnections(strpbs.mat[i].TEX_roughness_map)
tex_roughness = Path(pm.getAttr(file_node_roughness[0].fileTextureName)).resolve()
tex_roughness = _REL_ROOT.rel_path_to(tex_roughness)
tex_roughness = tex_roughness.replace('\\', '/')
_ATOM_MAT_TEMPLATE.setMap(_ATOM_MAT_TEMPLATE.texture_map['roughness'], tex_roughness)
file_node_ao = pm.listConnections(strpbs.mat[i].TEX_ao_map)
if (file_node_ao and pm.objectType(file_node_ao[0]) == 'file'
and pm.getAttr(strpbs.mat[i].use_ao_map)):
tex_ao = Path(pm.getAttr(file_node_ao[0].fileTextureName)).resolve()
tex_ao = _REL_ROOT.rel_path_to(tex_ao)
tex_ao = tex_ao.replace('\\', '/')
_ATOM_MAT_TEMPLATE.setMap(_ATOM_MAT_TEMPLATE.texture_map['ambientOcclusion'], tex_ao)
_ATOM_MAT_TEMPLATE.write(Path(_ASSET_PATH, "{}.material".format(str(strpbs.mat[i]))).resolve())