コード例 #1
0
def loadmodel(file, words, data):
  def nwprop(file, words, data):
    data['nwnprops'].write('SCENE.%s=%s\n'%(words[0], words[1]))
  modeldict={'beginmodelgeom': loadgeometry, 'donemodel': linereaderbreak,
        'classification': nwprop, 'supermodel': nwprop, 'newanim': loadanim}
  data={'scene': Scene.getCurrent(), 'nwnprops': Text.New('nwnprops'),
          'animnextframe': 2, 'nwnanims': Text.New('nwnanims'), 'fps': 30}
  raise ExitLineReader(linereader(file, modeldict, data))
  # Seems I can't modify the frame settings.
  #data['scene'].startFrame(1)
  #data['scene'].currentFrame(1)
  #data['scene'].endFrame(data['animnextframe']-1)
  data['scene'].update()
コード例 #2
0
def addCustomScriptLink():
    """
	Adds a custom script link to the scene so that all script
	windows are redrawn whenever the scene is redrawn.
	"""

    txt = Text.New(SCRIPTLINK_NAME)
    txt.write('import Blender\n')
    txt.write('from Blender import Window\n')
    txt.write('Window.Redraw(Window.Types.SCRIPT)\n')
    Scene.GetCurrent().addScriptLink(SCRIPTLINK_NAME, 'Redraw')

    # do a full scene update
    Scene.GetCurrent().update(1)
コード例 #3
0
ファイル: chicken_interface.py プロジェクト: kralf/panda3d
def Invoke(exporter=EXPORTER_NAME,
           use_stored=False,
           progress_range=None,
           filename=None,
           selection=None,
           anims=None,
           tools=None,
           optparms=None,
           mextract=False,
           animonly=False):
    '''
	Invokes Chicken exporter in Forced Background mode
	@param exporter: Specific filename for Chicken, defaults to the version that came with this module
	@param use_stored: Boolean that indicates whether to use stored parameters for export.
	@param progress_range: sequence of 2 floats that defines the range of progress this represents of the total operation
	@param filename: The destination filename. Defaults to working filename
	@param selection: A list of strings containing the names of the selected objects. Defaults to current selection
	@param anims: A list of 4-lists containing [animation-name, fps, start, end]
	@param tools: A 3-tuple containing booleans that indicate whether to invoke pview, egg2bam, and egg-optchar in that order.
	@param optparms: Optional parameters for egg-optchar. Defaults to '-inplace'
	@param mextract: Boolean that indicates whether to attempt motion extraction. Default is False.
	@param animonly: Boolean that indicates that only animation should be exported.
	@return: False if exporter not found, a tuple of the form (pre-export messages, post-export messages)
		if succesful (True is returned if messages were unattainable).
	'''
    result = True
    os.environ[
        KEY] = 'yes'  # arbitrary value, chicken only cares that it is set
    if progress_range and len(progress_range) == 2:
        os.environ[RANGE_KEY] = '%f,%f' % tuple(progress_range)
    if not use_stored:
        # make settings
        settings = Text.New('interface.chicken')
        os.environ[SETTINGS_KEY] = settings.getName()
        settings.write(
            MakeSettings(filename, selection, anims, tools, optparms, mextract,
                         animonly))
    try:
        Blender.Run(os.path.join(Blender.Get('scriptsdir'), exporter))
    except AttributeError:
        result = False
    if result:
        try:
            msg_txt = Text.Get(os.getenv(MESSAGE_KEY))
        except:
            pass
        else:
            try:
                msg_str = '\n'.join(msg_txt.asLines())
                import cPickle
                result = cPickle.loads(msg_str)
            except:
                print sys.exc_info()
            Text.unlink(msg_txt)
    if not use_stored:
        # delete temp settings
        Text.unlink(settings)
        del os.environ[SETTINGS_KEY]
    del os.environ[KEY]
    if os.environ.has_key(MESSAGE_KEY):
        del os.environ[MESSAGE_KEY]
    if os.environ.has_key(RANGE_KEY):
        del os.environ[RANGE_KEY]
    return result
コード例 #4
0
def buttonEvt(evt):
    global evtExport, evtPathChanged, evtBrows, evtExportSelection, exportSelection, exportNormals, exportTriangulated
    global exportPath
    global guiPopup
    if evt == evtExport:
        i3d = I3d()
        sce = bpy.data.scenes.active
        if exportSelection:
            for obj in sce.objects.selected:
                i3d.addObject(obj)
        else:
            for obj in sce.objects:
                i3d.addObject(obj)
        i3d.printToFile(exportPath.val)

        print("exported to %s" % exportPath.val)
    if evt == evtPathChanged:
        pass
    if evt == evtBrows:
        Window.FileSelector(selectExportFile, "Ok", exportPath.val)
    if evt == evtExportSelection:
        exportSelection = 1 - exportSelection
        Draw.Redraw(1)
    if evt == evtExportNormals:
        exportNormals = 1 - exportNormals
        Draw.Redraw(1)
    if evt == evtExportTriangulated:
        exportTriangulated = 1 - exportTriangulated
        Draw.Redraw(1)
    if evt == evtAddObjExtension:
        activeObj = bpy.data.scenes.active.objects.active
        slName = "%s.i3d" % activeObj.name
        sl = None
        try:
            sl = Text.Get(slName)
        except:
            sl = None
        if not sl is None:
            guiPopup = Draw.PupMenu(
                "%s already exists. Find it in the Text Editor" % slName)
        else:
            sl = Text.New(slName)
            sl.write("""<!--
this describes some i3d properties of the object it is linked to via Script Links.
the name of this text file must end with ".i3d".
all attributes of the SceneType node are copied to the Object in the final i3d.
"i3dNodeId" is replaced by the id the object gets in the i3d scene.
For the UserAttributes to work the attribute nodeId must be "i3dNodeId".
-->
<i3D>
	<Scene>
		<SceneType static="true" dynamic="false" kinematic="false"/>
	</Scene>
	<UserAttributes>
		<UserAttribute nodeId="i3dNodeId">
			<Attribute name="onCreate" type="scriptCallback" value="print"/>
		</UserAttribute>
	</UserAttributes>
</i3D>""")
            activeObj.addScriptLink(sl.getName(), "FrameChanged")
            guiPopup = Draw.PupMenu(
                "Check ScriptLink panel and Text Editor for %s" % sl.getName())
    if evt == evtAddMatExtension:
        activeObj = bpy.data.scenes.active.objects.active
        activeMat = activeObj.getData().materials[activeObj.activeMaterial - 1]
        slName = "%s.i3d" % activeMat.name
        sl = None
        try:
            sl = Text.Get(slName)
        except:
            sl = None
        if not sl is None:
            guiPopup = Draw.PupMenu(
                "%s already exists. Find it in the Text Editor" % slName)
        else:
            sl = Text.New(slName)
            sl.write("""<!--
this describes some i3d properties of the material it is linked to via Script Links.
the name of this text file must end with ".i3d".
all attribute values starting with "assets/" are added to the Files Node and replaced with the id.
in order for file references to work the path must start with "assets/".
-->
<i3D>
	<Materials>
		<Material customShaderId="assets/exampleCustomShader.xml">
			<Custommap name="colorRampTexture" fileId="assets/exampleCustomMap.png"/>
			<CustomParameter name="exampleParameter" value="2 0 0 0"/>	
		</Material>
	</Materials>
</i3D>""")
            activeMat.addScriptLink(sl.getName(), "FrameChanged")
            guiPopup = Draw.PupMenu(
                "Check ScriptLink panel and Text Editor for %s" % sl.getName())
コード例 #5
0
		show = 0
		for objectLayer in object.layers:
			for windowLayer in Window.ViewLayers():
				if objectLayer == windowLayer: show = 1
		if show:
			try:
				if object.getProperty('SpecialType').getData() == 'PhysicProxy':
					if object.getProperty('proxy_type').getData() == 'Box':
						drawPrimitiveCube(object)
					elif object.getProperty('proxy_type').getData() == 'Mesh':
						drawMesh(object)
			except:
				a=1 #for nothing,just a placeholder thingy

# Disable alpha blending and point smoothing.
glDisable(GL_BLEND)
glDisable(GL_POINT_SMOOTH)
"""

try:
    txt = Text.Get("Rastullah Visualizer")
    Text.unlink(txt)
    txt = Text.New("Rastullah Visualizer")
    txt.write(script_text)
except:
    txt = Text.New("Rastullah Visualizer")
    txt.write(script_text)

scene = Scene.GetCurrent()
scene.clearScriptLinks(['Rastullah Visualizer'])
scene.addScriptLink('Rastullah Visualizer', 'Redraw')