This commit is contained in:
indigo 2025-12-29 10:12:09 +08:00
parent 7d25bb8f2f
commit a2bf3236b0
2 changed files with 40 additions and 29 deletions

View File

@ -21,7 +21,7 @@ global proc AEInputDeviceReplace(string $attr)
global proc AEadjustInputDevice(string $attr) global proc AEadjustInputDevice(string $attr)
{ {
string $value = `optionMenuGrp -q -v a2vAEInputDevice`; string $value = `optionMenuGrp -q -v a2vAEInputDevice`;
setAttr $attr $value -type "string"; setAttr -type "string" $attr $value;
} }
global proc AEInputTypeNew(string $attr) global proc AEInputTypeNew(string $attr)
@ -51,11 +51,13 @@ global proc AEVideoPathNew(string $attr)
{ {
setUITemplate -pst attributeEditorTemplate; setUITemplate -pst attributeEditorTemplate;
textFieldButtonGrp -l "Video Path" a2VAEVideoPath; textFieldButtonGrp -l "Video Path" a2VAEVideoPath;
setUITemplate -ppt; setUITemplate -ppt;
textFieldButtonGrp -e textFieldButtonGrp -e
-tx ""
-buttonCommand ("AEVideoPathBrowse "+$attr) -buttonCommand ("AEVideoPathBrowse "+$attr)
-changeCommand ("AEAdjustVideoPath "+$attr) -changeCommand ("AEAdjustVideoPath "+$attr)
-buttonLabel "..."
-placeholderText "Select Video File"
-forceChangeCommand -forceChangeCommand
a2VAEVideoPath; a2VAEVideoPath;
@ -72,18 +74,23 @@ global proc AEVideoPathBrowse(string $attr)
string $value = `getAttr $attr`; string $value = `getAttr $attr`;
string $currentDir = `dirname $value`; string $currentDir = `dirname $value`;
string $videoFilters = "MP4 Files (*.mp4);;MOV Files (*.mov);;AVI Files (*.avi);;MPEG Files (*.mpg);;All Files (*.*)"; string $videoFilters = "MP4 Files (*.mp4);;MOV Files (*.mov);;AVI Files (*.avi);;MPEG Files (*.mpg);;All Files (*.*)";
string $result[] = `fileDialog2 -caption "Select Video File" -fileMode 1 -fileFilter $videoFilters -selectFileFilter "MP4 Files" -dialogStyle 2` string $result[] = `fileDialog2 -dialogStyle 2
-caption "Select Video File"
-fileMode 1
-fileFilter $videoFilters
-startingDirectory $currentDir
-selectFileFilter "MP4 Files"`;
if($result){ if(`size $result`){
textFieldButtonGrp -e -tx $result[0] a2VAEVideoPath; textFieldButtonGrp -e -tx $result[0] a2VAEVideoPath;
setAttr $attr $result[0] -type "string"; setAttr -type "string" $attr $result[0];
} }
} }
global proc AEAdjustVideoPath(string $attr) global proc AEAdjustVideoPath(string $attr)
{ {
string $value = `textFieldButtonGrp -q -tx a2VAEVideoPath`; string $value = `textFieldButtonGrp -q -tx a2VAEVideoPath`;
setAttr $attr $value; setAttr -type "string" $attr $value;
} }
global proc AEVideo2ARKitTemplate(string $nodeName) global proc AEVideo2ARKitTemplate(string $nodeName)
@ -109,11 +116,11 @@ global proc AEVideo2ARKitTemplate(string $nodeName)
// editorTemplate -addControl "inputDevice"; // editorTemplate -addControl "inputDevice";
editorTemplate -callCustom "AEInputDeviceNew" editorTemplate -callCustom "AEInputDeviceNew"
"AEInputDeviceReplace" "AEInputDeviceReplace"
$nodeName; "inputDevice";
//editorTemplate -addControl "videoPath"; //editorTemplate -addControl "videoPath";
editorTemplate -callCustom "AEVideoPathNew" editorTemplate -callCustom "AEVideoPathNew"
"AEVideoPathReplace" "AEVideoPathReplace"
$nodeName; "videoPath";
editorTemplate -addControl "networkUrl"; editorTemplate -addControl "networkUrl";
editorTemplate -addControl "networkPort"; editorTemplate -addControl "networkPort";
editorTemplate -addControl "modelPath"; editorTemplate -addControl "modelPath";

View File

@ -49,31 +49,35 @@ class Video2ARKitNode(om.MPxNode):
def compute(self, plug, data_block): def compute(self, plug, data_block):
# 如果正在請求輸出屬性 (52個中的任何一個) # 如果正在請求輸出屬性 (52個中的任何一個)
if plug in self.output_attrs.values(): print(self.output_attrs.values())
# 獲取輸入值 if all(plug != o_attr for o_attr in self.output_attrs.values()):
current_time = data_block.inputValue(self.aInTime).asMTime().asUnits(om.MTime.kFilm) # 假設 24fps return
trigger = data_block.inputValue(self.aProcessTrigger).asBool() # if plug in self.output_attrs.values():
video_path = data_block.inputValue(self.aVideoPath).asString()
model_path = data_block.inputValue(self.aModelPath).asString()
input_type = data_block.inputValue(self.aInputType).asInt()
# 檢查是否需要重新分析影片 # 獲取輸入值
if trigger and not self._cache: current_time = data_block.inputValue(self.aInTime).asTime().asUnits(om.MTime.kFilm) # 假設 24fps
self._cache = process.process_video(video_path, model_path) trigger = data_block.inputValue(self.aProcessTrigger).asBool()
video_path = data_block.inputValue(self.aVideoPath).asString()
model_path = data_block.inputValue(self.aModelPath).asString()
input_type = data_block.inputValue(self.aInputType).asInt()
# 獲取當前幀數的權重 # 檢查是否需要重新分析影片
frame_idx = int(current_time) if trigger and not self._cache:
frame_data = self._cache.get(frame_idx, {}) self._cache = process.process_video(video_path, model_path)
# 輸出對應的值 # 獲取當前幀數的權重
for name, attr_obj in self.output_attrs.items(): frame_idx = int(current_time)
if plug == attr_obj: frame_data = self._cache.get(frame_idx, {})
val = frame_data.get(name, 0.0)
handle = data_block.outputValue(attr_obj) # 輸出對應的值
handle.setFloat(val) for name, attr_obj in self.output_attrs.items():
data_block.setClean(plug) if plug == attr_obj:
return val = frame_data.get(name, 0.0)
handle = data_block.outputValue(attr_obj)
handle.setFloat(val)
data_block.setClean(plug)
return
def setDependencyDirty(self, plug, affectedPlugs): def setDependencyDirty(self, plug, affectedPlugs):
if plug == self.aProcessTrigger: if plug == self.aProcessTrigger: