I am working on real time mapping of model with the user data obtained from Kinect.
I am able to get access to the individual bone using bge.types.BL_ArmatureObject().channels
which give the list of bones. I am not able to change the position bone. I tried to use rotation_euler to give it some rotation but it had no effect. Please tell me how to do it.
Maybe a little late, but for blender >= 2.5 this should do the trick:
# Get the whole bge scene
scene = bge.logic.getCurrentScene()
# Helper vars for convenience
source = scene.objects
# Get the whole Armature
main_arm = source.get('NAME OF YOUR ARMATURE')
main_arm.channels['NAME OF THE BONE YOU WANT TO ROTATE'].joint_rotation[ x, y ,z] # x,y,z = FLOAT VALUE
main_arm.update()
I also wrote this down in an extensive tutorial, starting here: http://www.warp1337.com/content/blender-robotics-part-1-introduction-and-modelling
Related
I'm trying to render a cube (default blender scene) with a camera facing it. I have added a spotlight at the same location as the camera. Spotlight direction also faces towards the cube.
When I render, location changes take effect for both camera and spotlight but, rotations don't. scene context update is deprecated now. I have seen other update answers, but they don't seem to help.
I have done some workarounds and they seem to work, but this is not the correct way.
If I render the same set of commands twice (in a loop), I get the correct render.
If I run the script from the blender's python console (only once), I get the correct render. But If the same code is run as a script inside the blender, render is again wrong.
import pdb
import numpy as np
import bpy
def look_at(obj_camera, point):
loc_camera = obj_camera.matrix_world.to_translation()
direction = point - loc_camera
rot_quat = direction.to_track_quat('-Z', 'Y')
obj_camera.rotation_euler = rot_quat.to_euler()
data_path='some folder'
locs=np.array([ 0.00000000e+00, -1.00000000e+01, 3.00000011e-06]) #Assume, (I have big array where camera and spotlight needs to be placed, and then made to look towards cube)
obj_camera = bpy.data.objects["Camera"]
obj_other = bpy.data.objects["Cube"]
bpy.data.lights['Light'].type='SPOT'
obj_light=bpy.data.objects['Light']
loc=locs
i=0
##### if I run following lines two times, correct render is obtained.
obj_camera.location = loc
obj_light.location= obj_camera.location
look_at(obj_light, obj_other.matrix_world.to_translation())
look_at(obj_camera, obj_other.matrix_world.to_translation())
bpy.context.scene.render.filepath = data_path+'image_{}.png'.format(i)
bpy.ops.render.render(write_still = True)
You might need to call bpy.context.view_layer.update() (bpy.context.scene.update() with older versions than blender 2.8) after changing the camera orientation by obj_camera.rotation_euler = rot_quat.to_euler() and make sure that the layers that are going to be rendered are active when calling update() (see here https://blender.stackexchange.com/questions/104958/object-locations-not-updating-before-render-python).
(A bit late ;-) but this was one of the rare questions I found for a related issue.)
I'm pretty new to coding and I need to create a code that generates an object along the normal of a selected geo surface.
Anything to start me on the right path would be appreciated.
I initially tried to use duplicate, but I was told that command instancer is the better option.
def ChainmailSurfaceGenerator():
thing = MC.ls(sl=True)
print thing
if not thing:
MC.error("select a torus")
#create a group for your chainmail*
grp = MC.group(empty=True, name=thing[0] + '_grp#'
#create hierarchy of grouped toruses
MC.polyTorus( radius=1, n = 'chainmail_link')
MC.duplicate('chainmail_link')
#query the direction of UV normals off the face
#lessen the amount of geometry if its too dense
#try it out on a plane surface first
#keep things simple early
#what if chains don't connect perfectly? add a randomizer so that the chains aren't all completely symmetrical
#don't use MC.duplicate; use Instancer
You might not actually need to query the UV direction of the target geometry.
Try looking into the commands for constraints like cmds.normalConstraint or cmds.geometryConstraint. As for the number of objects to make, consider using a for loop in a range of how many objects you want. If you want to apply a random rotation, I would recommend using a group or a locator as an offset for transforming the group around (either with setAttr or xform) so that you can move the group while maintaining the ability to rotate the duplicate in it's y axis. If you go the route of normal constraints, be sure to use the aim flag to point the object up in its y axis! Googling the commands should come up with documentation on what flags to use.
Using Python to interface with Paraview, I want to get the "Points" data from an integrate variable filter.
I tried the GetArray("Points") but it can't find it even though you can clearly see it in the GUI if you go to spreadsheet view.
My code is below. With the GUI approach I get for Point ID = 0 the array "Points" has three values (0.54475, -1.27142e-18, 4.23808e-19) which makes sense because the default arrow is symmetric in y and z.
Is there any way to get the value 0.54475 inside python?
MWE
#Import Paraview Libraries
#import sys
#sys.path.append('Path\\To\\Paraview\\bin\\Lib\\site-packages')
from paraview.simple import *
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()
# create a new 'Arrow'
arrow1 = Arrow()
# create a new 'Integrate Variables'
integrateVariables1 = IntegrateVariables(Input=arrow1)
pdata = paraview.servermanager.Fetch(integrateVariables1).GetPointData()
print pdata.GetArray("Points") # prints None
You are very close. For all other arrays, you can access the value using the method you have written.
However VTK treats the point coordinates slightly differently, so the code you need for the point coordinates is:
arrow1 = Arrow()
integrateVariables1 = IntegrateVariables(Input=arrow1)
integrated_filter = paraview.servermanager.Fetch(integrateVariables1)
print integrated_filter.GetPoint(0)
This gives me: (0.5447500348091125, -1.2714243711743785e-18, 4.238081064918634e-19)
I would also suggest that you might want to do this in a Python Programmable Filter. Passing the filter from the server back to the client is not the best practice, and it is preferred to do all calculation on the server.
How do I select the surfaces on part in Abaqus? I have tried:
tubePart.surface(faces = tubePart.faces[4:8],name = 'innerFaces')
but it keeps saying part object has no attribute surface.
Ideally, you should create a new surface by calling Surface() function (not surface()), i.e.
tubePart.Surface(...)
Secondly, there must be side1Faces instead of faces (thanks to agentp for comment). Thus, the final peace of code should look like this:
tubePart.Surface(side1Faces = tubePart.faces[4:8],name = 'innerFaces')
i've been having this weird error after starting to try out "masking" (halfway through an activity given by a lecturer). The lecturer recommended that i create a new solution. However, after making 3 solutions which produced the same error.
http://puu.sh/1foxu <- Picture of the error
http://pastebin.com/GPsLTjdm <- Pastebin for code (used pastebin because Panda3D thingy is indent sensitive)
Thank you!
Try moving your box model before reparenting it to its bullet node.
self.world.attachRigidBody(np.node())
model = loader.loadModel('models/box.egg')
model.setPos(-0.5,-0.5,-0.5) # <- Add this line
model.reparentTo(np)
Adjusting the model position is needed because Bullet shapes assume that the center of the model is its (0,0,0) coordinates, but in most cases the (0,0,0) is actually the bounds of the model.
EDIT:
To solve your texture problem try:
model.setTexture(tex, 1)
...instead of...
model.setTexture(tex)
A fragment from the manual:
Normally, you simply pass 1 as the second parameter to setTexture().
Without this override, the texture that is assigned directly at the
Geom level will have precedence over the state change you make at the
model node, and the texture change won't be made.