简体   繁体   English

如何在搅拌机中为对象添加位置限制?

[英]how to add location constraints for an object in blender?

I want to make it so that my program will stop running and print object is out of bounds if an object goes say into the negative z part of the plane in blender. 我要使它停止运行,并且如果某个对象进入搅拌机中平面的负z部分,则打印对象将超出范围。 the objects name is Cube.031. 对象名称为Cube.031。 I will sudo code what I want to do I just am not sure about sure how to do the syntax for it. 我会用sudo代码编写我想做的事情,只是不确定如何确定语法。

 if(Cube.031.zLocation < 0)
        print(object is out of bounds)
        end

If you know some programming, learning python won't take long. 如果您知道一些编程知识,那么学习python就不会花很长时间。

For the blender specific info, almost everything is accessed through the bpy module, the API reference is online . 对于特定于Blender的信息,几乎所有内容都可以通过bpy模块访问, API参考为online

You can refer to an object by name in bpy.data.objects[] . 您可以在bpy.data.objects[]按名称引用对象。 There are also other lists available, like bpy.context.selected_objects[] and bpy.context.visible_objects[] . 还有其他可用列表,例如bpy.context.selected_objects[]bpy.context.visible_objects[]

An objects location is an array of three values (x,y,z), you can either access the z location as location.z or location[2] . 对象位置是由三个值(x,y,z)组成的数组,您可以将z位置作为location.zlocation[2]

import bpy

obj = bpy.data.objects['Cube.031']

if obj.location.z < 0:
    print('object is out of bounds')

If you wanted to go through all selected objects 如果要浏览所有选定的对象

for obj in bpy.context.selected_objects:
    if obj.location.z < 0:
        print('object {} is out of bounds'.format(obj.name))

Note that v2.80 is due for release soon and has some changes to the API , if you are just starting with blender you may want to start with 2.80. 请注意,v2.80即将发布,并对API进行了一些更改,如果您只是从Blender开始,则可能要从2.80开始。 You will also find blender.stackexchange a better place to ask for blender specific help. 您还将发现blender.stackexchange是寻求搅拌器特定帮助的更好场所。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM