Hi All ,
I want to share Great news :
Defold Proto files are now accessed from python api :
check pip install pydefold
Any one has a need for more info contact me on mhadhbixissam@gmail.com .
I have implemented also for the editor an api which match same behavior of the Defold editor ,and is very stable allow to get rid of editor and create your game : collections , materials …etc from only python .
i am on the road of implementing the editor inside blender but the road is very long , any one want be help and support are welcome , were are on the goal of create your defold game inside blender and build it and run it inside blender also .
for demo show the editor has implented like this demo show :
Defold Python Api :
the Defold Python Api , is made in python , here is how to use it :
Create a defold project :
import os
from Defold import Editor
game_name = "test"
game_path = os.path.join(Editor.config['Projects']['dir'] , game_name)
game =Editor.newproject(game_name) if not os.path.exists(game_path) else Editor.project(game_path)
c = game.newCollection(name = "main")
game.update()
Create sript and add it to a game object :
c = game.newCollection(name = "main")
go = c.addGameObject(id = "go")
# this will create /main/logic.script
script = go.addScriptFile(id = "logic")
# this will set the current lua code to this content if already exists else it will write current content in the new created script file
script.filename = "/main/mmm.script"
# this will overide script code
script.script = '-----lua code goes here'
Creating Material :
modelMaterial= game.newMaterial(name = "pbr" , tags = ['model'])
modelMaterial.setvertex_constant(name='mtx_worldview',typ='Worldview')
modelMaterial.setvertex_constant(name='mtx_view',typ='View')
modelMaterial.setvertex_constant(name='mtx_proj',typ='Projection')
modelMaterial.setvertex_constant(name='mtx_normal',typ='Normal')
modelMaterial.setvertex_constant(name='light',typ='User')
modelMaterial.setfragment_constant(name = 'tint' , typ='User')
modelMaterial.setTexture(name='tex0')
modelMaterial.setvertex_space('local')
modelMaterial.vp = '''
attribute highp vec4 position;
attribute mediump vec2 texcoord0;
attribute mediump vec3 normal;
uniform mediump mat4 mtx_worldview;
uniform mediump mat4 mtx_view;
uniform mediump mat4 mtx_proj;
uniform mediump mat4 mtx_normal;
uniform mediump vec4 light;
varying highp vec4 var_position;
varying mediump vec3 var_normal;
varying mediump vec2 var_texcoord0;
varying mediump vec4 var_light;
void main()
{
vec4 p = mtx_worldview * vec4(position.xyz, 1.0);
var_light = mtx_view * vec4(light.xyz, 1.0);
var_position = p;
var_texcoord0 = texcoord0;
var_normal = normalize((mtx_normal * vec4(normal, 0.0)).xyz);
gl_Position = mtx_proj * p;
}
'''
modelMaterial.fp = '''
varying highp vec4 var_position;
varying mediump vec3 var_normal;
varying mediump vec2 var_texcoord0;
varying mediump vec4 var_light;
uniform lowp sampler2D tex0;
uniform lowp vec4 tint;
void main()
{
// Pre-multiply alpha since all runtime textures already are
vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
vec4 color = texture2D(tex0, var_texcoord0.xy) ;
// Diffuse light calculations
vec3 ambient_light = vec3(0.2);
vec3 diff_light = vec3(normalize(var_light.xyz - var_position.xyz));
diff_light = max(dot(var_normal,diff_light), 0.0) + ambient_light;
diff_light = clamp(diff_light, 0.0, 1.0);
gl_FragColor = vec4(color.rgb*diff_light,1.0);
}
'''
Creating game object :
c = game.newCollection(name = "main")
go = c.addGameObject(id = "go")
go.position.update(
x = game.gameproject.display.width * 0.5 , y = game.gameproject.display.height * 0.5
)
go.scale3.update(
x = game.gameproject.display.width * 0.5 , y = game.gameproject.display.height * 0.5
)
go2 = go.addGameObject(id = "go2")