据我检查,缩进是正确的,没有括号丢失,我只在前面的行中导入了包但是我仍然得到无效的语法错误。
#!/usr/bin/python
import bpy
import mathutils
import numpy as np
from math import radians
from mathutils import Vector
from math import radians
from mathutils import Matrix
from bpy import context
def transform_mesh('parent', 'obj_to_be_transformed', (translate_x, translate_y, translate_z), (rot_x,rot_y,rot_z)):
obj= bpy.data.objects[parent]
obj1= bpy.data.objects[obj_to_be_transformed]
initial_mat = obj1.matrix_world
...some code
(x,y,z) = (translate_x, translate_y, translate_z)
orig_loc_mat = Matrix.Translation(orig_loc+ mathutils.Vector((x,y,z)))
...some more code
eul = mathutils.Euler((radians(rot_x), radians(rot_y), radians(rot_z)), 'XYZ')
rot_mat = eul.to_matrix().to_4x4()
obj.matrix_world = orig_loc_mat * rot_mat * orig_rot_mat * orig_scale_mat
bpy.context.scene.update()
return [initial_loc,initial_rot,initial_scale,loc,rot,scale]
transform_result= transform_mesh('Armature','Coil',(5,0,0),(0,0,1))
print (transform_result)
错误是:
Error: File "D:\users\gayathri\Gayathri\Synthetic_data_generation\Final\HMI_Depth_coilA_final_final.blend\Untitled", line 18
def transform_mesh('parent', 'obj_to_be_transformed', (translate_x, translate_y, translate_z), (rot_x,rot_y,rot_z)):
^
SyntaxError: invalid syntax
location: <unknown location>:-1
答案 0 :(得分:3)
def transform_mesh('parent', 'obj_to_be_transformed',
应该是
def transform_mesh(parent, obj_to_be_transformed,
确实
答案 1 :(得分:2)
1-从参数中删除字符串
2-从参数中删除元组并将它们归因于函数(添加一些检查可能很有用)
所以,你在这里:
def transform_mesh(parent, obj_to_be_transformed, translate, rot):
translate_x, translate_y, translate_z= translate
rot_x,rot_y,rot_z = rot
# etc
transform_result= transform_mesh('Armature','Coil',(5,0,0),(0,0,1))
print (transform_result)
答案 2 :(得分:0)
Python3中不支持元组参数,但您可以将其作为变量传递,并在定义函数后将其解压缩。
def transform_mesh(translate_xyz):
translate_x, translate_y, translate_z = translate_xyz
答案 3 :(得分:0)
您需要提供变量作为函数的参数。
尝试类似:
def transform_mesh(parent, obj_to_be_transformed, t1, t2):
虽然在你共享的代码中,你总是使用t1和t2作为元组。但是如果你想分别使用x,y和z,可以通过引用索引来实现:
x = t1[0]
y = t1[1]
答案 4 :(得分:0)
在这一行中,函数参数以不正确的方式传递,
const commentSchema = mongoose.Schema({
title: {
type: String,
trim: true
},
_creator: {
type: ObjectId,
ref: 'user'
},
_post: {
type: ObjectId,
ref: 'post'
}
}, {
timestamps: true
});
// get posts from all users
postRoutes.get('/', authMiddleware, async(req, res) => {
try {
const user = req.user;
const posts = await Post.find({})
.populate('_creator likes comments')
.sort({
createdAt: -1
})
.limit(1);
return res.send(posts);
} catch (e) {
return res.status(400).send(e);
}
});
正确的语法是:
def transform_mesh('parent', 'obj_to_be_transformed', (translate_x, translate_y, translate_z), (rot_x,rot_y,rot_z)):