Skip to content

Commit

Permalink
svn_sync
Browse files Browse the repository at this point in the history
  • Loading branch information
LiXizhi committed Jan 22, 2020
1 parent 61a2e7b commit 5264104
Show file tree
Hide file tree
Showing 17 changed files with 1,594 additions and 62 deletions.
4 changes: 2 additions & 2 deletions script/apps/Aries/Creator/Assets/CreateAssetBagPage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ function CreateAssetBagPage.OnClickItem(obj_params)
directPosition = true,
align = "_ct",
x = -140/2,
y = -300/2,
y = -340/2,
width = 140,
height = 300,
height = 340,
});
Map3DSystem.App.Creator.ObjectInspectorPage.SetModel(filepath);
elseif(mouse_button=="left") then
Expand Down
14 changes: 5 additions & 9 deletions script/apps/Aries/Creator/Assets/ObjectInspectorPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@
Page:CloseWindow();
end
]]></script>
<div style="width:140px;height:300px;" class="window">
<div class="titlebar" width="100%">
<div class="windowlabel" >物品信息</div>
<input type="button" style="margin-top:1px;margin-right:5px" onclick="ClosePage" class="closewindow"/>
</div>
<div class="clientarea" style="margin-left:7px;margin-right:7px">
<aries:window mode="thin" title='<%=L"物品信息"%>' style="width:140px;height:340px" onclose="ClosePage">
<div class="default">
<pe:canvas3d name="modelCanvas" autoRotateSpeed="0.12" style="margin-left:3px;width:128px;height:128px"></pe:canvas3d>
<hr />
<div style="margin-left:5px;margin-right:5px">
Expand All @@ -27,11 +23,11 @@
缩略图:<div style="float:left;" class="inborder_golden"><img name="ThumbnailImg" style="width:48px;height:48px;margin:1px"/></div>
</div>
<div style="margin-left:5px;margin-top:4px">
<input type="button" class="button" style="width:60px;" name="btnSnapshot" value="快照" tooltip="生成缩略图" onclick="Map3DSystem.App.Creator.ObjectInspectorPage.OnTakeSnapShot"/>
<input type="button" class="button" style="margin-left:5px;width:40px;" name="btnCancel" value="关闭" onclick="ClosePage()"/>
<input type="button" class="button" style="width:60px;" name="btnSnapshot" value="快照" tooltip="生成缩略图" onclick="Map3DSystem.App.Creator.ObjectInspectorPage.OnTakeSnapShot"/>
<input type="button" class="button" style="margin-left:5px;width:40px;" name="btnCancel" value="关闭" onclick="ClosePage()"/>
</div>
</div>
</div>
</aries:window>
</pe:mcml>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!-- "script/apps/Aries/Creator/Game/Code/NplMicroRobot/MicrobitEmulatorPage.html" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<pe:mcml>
<script refresh="false" type="text/npl" src="MicrobitEmulatorPage.lua"><![CDATA[
NPL.load("(gl)script/apps/Aries/Creator/Game/game_logic.lua");
local GameLogic = commonlib.gettable("MyCompany.Aries.Game.GameLogic")
MicrobitEmulatorPage = NPL.load("(gl)script/apps/Aries/Creator/Game/Code/NplMicroRobot/MicrobitEmulatorPage.lua");
MicrobitEmulatorPage.OnInit();
local page = document:GetPageCtrl();

function OnMicrobitShowString(args,msg)
msg = msg or {};
local txt = msg.msg or ""
page:SetValue("console",txt);
end
function ClosePage()
GameLogic.GetCodeGlobal():UnregisterTextEvent("microbit_show_string",OnMicrobitShowString)
page:CloseWindow();
end
function OnClick(name)
GameLogic:event(System.Core.Event:new():init(name))
end
function OnSelect(name,value)
value = string.format("microbit_gesture_%s",value);
GameLogic:event(System.Core.Event:new():init(value))
end

GameLogic.GetCodeGlobal():RegisterTextEvent("microbit_show_string", OnMicrobitShowString)
]]></script>
<aries:window mode="thin" title='<%=L"Microbit模拟器"%>' onclose="ClosePage">
<div style="width:300px;height:280px;">
<div style="width:297px;height:244px;margin-left:-4px;margin-top:5px;background:url(Mod/NplMicroRobot/textures/microbit.png#0 0 366 298)" >
<div style="position:relative;margin-left:15px;margin-top:105px;">
<input type="button" name="microbit_btn_A" onclick="OnClick" style="width:35px;height:35px;"/>
</div>
<div style="position:relative;margin-left:249px;margin-top:105px;">
<input type="button" name="microbit_btn_B" onclick="OnClick" style="width:35px;height:35px;"/>
</div>
<div style="position:relative;margin-left:180px;margin-top:5px;">
<select name='options' AllowUserEdit="false" style="width:100px;height:22px" onselect="OnSelect">
<option value="Shake" selected="true">Shake</option>
<option value="LogoUp">LogoUp</option>
<option value="LogoDown">LogoDown</option>
<option value="ScreenUp">ScreenUp</option>
<option value="ScreenDown">ScreenDown</option>
<option value="TiltLeft">TiltLeft</option>
<option value="TiltRight">TiltRight</option>
<option value="FreeFall">FreeFall</option>
<option value="ThreeG">ThreeG</option>
<option value="SixG">SixG</option>
<option value="EightG">EightG</option>
</select>
</div>
<div style="position:relative;margin-left:90px;margin-top:65px;width:125px;height:120px;">
<input name="console" AlwaysShowCurLineBackground="false" rows="3" height="100%" ReadOnly="true" UseSystemControl="true" style="textcolor:#ffffff;line-height:16" fontsize="12"/>
</div>
</div>
</div>

</aries:window>
</pe:mcml>
</body>
</html>

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--[[
Title: MicrobitEmulatorPage
Author(s): leio
Date: 2020.1.17
Desc:
use the lib:
------------------------------------------------------------
local MicrobitEmulatorPage = NPL.load("(gl)script/apps/Aries/Creator/Game/Code/NplMicroRobot/MicrobitEmulatorPage.lua");
MicrobitEmulatorPage.ShowPage();
------------------------------------------------------------
]]
local MicrobitEmulatorPage = NPL.export();
MicrobitEmulatorPage.url = "script/apps/Aries/Creator/Game/Code/NplMicroRobot/MicrobitEmulatorPage.html";
function MicrobitEmulatorPage.OnInit()
MicrobitEmulatorPage.page = document:GetPageCtrl();
end
function MicrobitEmulatorPage.ShowPage()
local params = {
url = MicrobitEmulatorPage.url,
name = "MicrobitEmulatorPage.ShowPage",
app_key=MyCompany.Aries.app.app_key,
isShowTitleBar = false,
DestroyOnClose = true,
bToggleShowHide = false,
enable_esc_key = true,
style = CommonCtrl.WindowFrame.ContainerStyle,
allowDrag = true,
zorder = -1,
click_through = false,
directPosition = true,
align = "_lt",
x = 0,
y = 80,
width = 300,
height = 280,
}
System.App.Commands.Call("File.MCMLWindowFrame", params);
end
150 changes: 101 additions & 49 deletions script/apps/Aries/Creator/Game/Code/NplMicroRobot/NplMicroRobot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ commonlib.setfield("MyCompany.Aries.Game.Code.NplMicroRobot.NplMicroRobot", NplM

NPL.load("(gl)script/apps/Aries/Creator/Game/Code/CodeAPI_Microbit.lua");

NplMicroRobot.exportNoneAnimatedMotors = true;

local is_installed = false;
local all_cmds = {};
Expand Down Expand Up @@ -89,7 +90,75 @@ function NplMicroRobot.GetAllCmds()
NplMicroRobot.AppendAll();
return all_cmds;
end
function NplMicroRobot.OnClickExport(type,code,bx, by, bz)

function NplMicroRobot.CreateActorFromMovieClip(movieEntity)
local itemStack = movieEntity:GetFirstActorStack();
if(itemStack) then
local item = itemStack:GetItem();
if(item and item.CreateActorFromItemStack) then
local actor = item:CreateActorFromItemStack(itemStack, movieEntity, false, "ActorForNplMicroRobot_");
if(actor) then
return actor
end
end
end
end

-- return nil or array of exported motor bones
function NplMicroRobot.GetBonesFromMovieEntity(movieEntity)
if(movieEntity and movieEntity.inventory)then
local actor = NplMicroRobot.CreateActorFromMovieClip(movieEntity)
if(actor) then
actor:SetTime(0);
actor:FrameMove(0);
local bonesVars = actor:GetBonesVariable();
local bones = actor:GetTimeSeries():GetChild("bones");

NPL.load("(gl)script/ide/System/Scene/Animations/Bones/BoneProxy.lua");
local BoneProxy = commonlib.gettable("System.Scene.Animations.Bones.BoneProxy");
local obj_attr = actor:GetEntity():GetInnerObject():GetAttributeObject();
local bones_ = {};
local motor_bones = {};
local animInstance = obj_attr:GetChildAt(1,1);
-- because time series may contain redundent bone info, we will only export those in X file.
if(animInstance and animInstance:IsValid()) then
local bone_count = animInstance:GetChildCount(1);
for i = 0, bone_count-1 do
local boneProxy = BoneProxy:new():init(animInstance:GetChildAt(i, 1), bones_);
local serverId = boneProxy:GetBoneProperty("servoId")
if(serverId) then
local name = boneProxy.name.."_rot";
local bone = bones:GetData()[name]
if(bone) then
bone = commonlib.copy(bone)
end
if(not bone and NplMicroRobot.exportNoneAnimatedMotors) then
-- Note: bones without animation will have default 0 values
bone = {ranges={{1,1},}, times={0}, data={{0,0,0,1}}, name=name}
end
if(bone) then
bone.properties = boneProxy:GetProperties();
motor_bones[#motor_bones+1] = bone;
end
end
end
end

actor:OnRemove();
actor:Destroy();

motor_bones = NplMicroRobot.fixeRangesToJsIndex(motor_bones)
motor_bones = NplMicroRobot.fixRotationValuesAndID(motor_bones);

--echo("1111111111111111111")
--echo(motor_bones)

return motor_bones;
end
end
end

function NplMicroRobot.OnClickExport(exportType,code,bx, by, bz)
local codeblock = CodeBlockWindow.GetCodeBlock()
if(not codeblock)then
return
Expand All @@ -109,40 +178,34 @@ function NplMicroRobot.OnClickExport(type,code,bx, by, bz)
end
local filename_really = string.format("test/robot/%s_really.json",filename);
filename = string.format("test/robot/%s.json",filename);
if(movieEntity and movieEntity.inventory)then
local inventory = movieEntity.inventory;

local bones = NplMicroRobot.getBonesDataFromInventory(inventory) or {};
bones = commonlib.copy(bones);
bones = NplMicroRobot.fixeRangesToJsIndex(bones)
bones = NplMicroRobot.fixRotationValuesAndID(bones);

local values = bones;
-- test animation data
ParaIO.CreateDirectory(filename);
local file = ParaIO.open(filename,"w");
if(file:IsValid()) then
file:WriteString(NPL.ToJson(values));
file:close();
end

if(type == "view")then
local NplMicroRobotAdapterPage = NPL.load("(gl)script/apps/Aries/Creator/Game/Code/NplMicroRobot/NplMicroRobotAdapterPage.lua");
NplMicroRobotAdapterPage.ShowPage(values);
return
end
local bones = NplMicroRobot.GetBonesFromMovieEntity(movieEntity)
if(bones) then
local values = bones;
-- test animation data
ParaIO.CreateDirectory(filename);
local file = ParaIO.open(filename,"w");
if(file:IsValid()) then
file:WriteString(NPL.ToJson(values));
file:close();
end

if(exportType == "view")then
local NplMicroRobotAdapterPage = NPL.load("(gl)script/apps/Aries/Creator/Game/Code/NplMicroRobot/NplMicroRobotAdapterPage.lua");
NplMicroRobotAdapterPage.ShowPage(values);
return
end

values = NplMicroRobot.helper_clear_names(values)

values = NplMicroRobot.helper_clear_names(values)

-- test running animation data
local data = NPL.ToJson(values);
local file = ParaIO.open(filename_really,"w");
if(file:IsValid()) then
file:WriteString(data);
file:close();
end
code = NplMicroRobot.fixCode(code);
NplMicroRobot.Run(type,data,code);
-- test running animation data
local data = NPL.ToJson(values);
local file = ParaIO.open(filename_really,"w");
if(file:IsValid()) then
file:WriteString(data);
file:close();
end
code = NplMicroRobot.fixCode(code);
NplMicroRobot.Run(exportType, data, code);
end
end
function NplMicroRobot.fixCode(code)
Expand Down Expand Up @@ -204,17 +267,6 @@ function NplMicroRobot.fixeRangesToJsIndex(bones)
return result;
end

function NplMicroRobot.helper_ReadBonePropertiesFromName(name)
if(not name)then
return
end
local display_name, properties = name:match("^(.*)%s*(%{[^%}]+%})_rot");
if(properties) then
properties = NPL.LoadTableFromString(properties);
end
return display_name, properties;
end

function NplMicroRobot.helper_radianToDegreeInt(v)
v = v * 180 / 3.1415926;
v = math.floor(v + 0.5);
Expand All @@ -240,10 +292,10 @@ function NplMicroRobot.fixRotationValuesAndID(bones)
end
local result = {};
for k,v in pairs(bones) do
if(type(v) == "table" and v.data)then
local name = v.name
local display_name, properties = NplMicroRobot.helper_ReadBonePropertiesFromName(name);
properties = properties or {};
if(type(v) == "table" and v.data and v.properties)then
local display_name = v.name;
local properties = v.properties;
v.properties = nil;
local rotAxis = properties.rotAxis;
local servoId = properties.servoId;
local servoOffset = properties.servoOffset; -- input is radian
Expand Down
Loading

0 comments on commit 5264104

Please sign in to comment.