diff --git a/components/3d/__init__.py b/components/3d/__init__.py new file mode 100644 index 0000000..e343595 --- /dev/null +++ b/components/3d/__init__.py @@ -0,0 +1,22 @@ +""" +----------------------------------------------------------------------------- +This source file is part of OSTIS (Open Semantic Technology for Intelligent Systems) +For the latest info, see http://www.ostis.net + +Copyright (c) 2010 OSTIS + +OSTIS is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +OSTIS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with OSTIS. If not, see . +----------------------------------------------------------------------------- +""" +__all__ = ['base'] \ No newline at end of file diff --git a/components/3d/base/_3d2sc.py b/components/3d/base/_3d2sc.py new file mode 100644 index 0000000..26a7014 --- /dev/null +++ b/components/3d/base/_3d2sc.py @@ -0,0 +1,54 @@ +""" +----------------------------------------------------------------------------- +This source file is part of OSTIS (Open Semantic Technology for Intelligent Systems) +For the latest info, see http://www.ostis.net + +Copyright (c) 2010 OSTIS + +OSTIS is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +OSTIS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with OSTIS. If not, see . +----------------------------------------------------------------------------- +""" + +from suit.core.objects import Translator +import suit.core.objects as objects +import suit.core.kernel as core + + +class Translator3D2Sc(Translator): + + def __init__(self): + Translator.__init__(self) + + def __del__(self): + Translator.__del__(self) + + def translate_impl(self, _input, _output): + """Translator implementation + """ + # translating objects + objs = objects.ScObject._sc2Objects(_input) + + assert len(objs) > 0 + sheet = objs[0] + assert type(sheet) is objects.ObjectSheet + + segment = sheet.getTmpSegment() + + errors = [] + session = core.Kernel.session() + import suit.core.sc_utils as sc_utils + + + + return errors \ No newline at end of file diff --git a/components/3d/base/_3d_controls.py b/components/3d/base/_3d_controls.py new file mode 100644 index 0000000..37432a7 --- /dev/null +++ b/components/3d/base/_3d_controls.py @@ -0,0 +1,80 @@ + +""" +----------------------------------------------------------------------------- +This source file is part of OSTIS (Open Semantic Technology for Intelligent Systems) +For the latest info, see http://www.ostis.net + +Copyright (c) 2010 OSTIS + +OSTIS is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +OSTIS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with OSTIS. If not, see . +----------------------------------------------------------------------------- +""" + +from suit.core.objects import ObjectOverlay +import suit.core.render.engine as render_engine +import suit.core.render.mygui as mygui + +class _3DInfoPanel(ObjectOverlay): + + def __init__(self): + ObjectOverlay.__init__(self) + + self.width = 250 + self.height = 450 + self._widget = render_engine.Gui.createWidgetT("Window", "Panel", + mygui.IntCoord(-10, (render_engine.Window.height - self.height) / 2, + self.width, self.height), + mygui.Align()) + self.infoText = self._widget.createWidgetT("StaticText", "StaticText", + mygui.IntCoord(15, 15, self.width - 30, self.height - 30), + mygui.Align()) + self.setVisible(False) + self.setEnabled(True) + + self.object = None + + # flag to update information + self.needInfoUpdate = False + + def __del__(self): + ObjectOverlay.__del__(self) + + def delete(self): + ObjectOverlay.delete(self) + + def setObject(self, _object): + """Sets new object to show information + """ + self.object = _object + self.needInfoUpdate = True + self.needViewUpdate = True + + def getObject(self): + return self.object + + def update(self): + self.needInfoUpdate = True + self.needViewUpdate = True + + def _updateView(self): + ObjectOverlay._updateView(self) + + if self.needInfoUpdate: + if self.object is not None: + self.infoText.setCaption(self.object.getPropertiesAsString()) + else: + self.infoText.setCaption("") + self.needInfoUpdate = False + + \ No newline at end of file diff --git a/components/3d/base/_3d_dotscene.py b/components/3d/base/_3d_dotscene.py new file mode 100644 index 0000000..d751c4f --- /dev/null +++ b/components/3d/base/_3d_dotscene.py @@ -0,0 +1,161 @@ +#!/usr/bin/python +""" +this file parses .scene node (dotscene) files and +creates them in OGRE with user data + +Doesn't do any fancy stuff (skydome, XODE, lightmapping, etc) but you can use this as a base for adding those features.) + +cpp: +http://www.ogre3d.org/wiki/index.php/DotScene_Loader_with_User_Data_Class +""" +from xml.dom import minidom, Node +import ogre.renderer.OGRE as ogre + +""" +self.dotscene = DotScene(self.fileName, self.sceneManager, rootnode) +""" + +class DotScene: + def __init__ (self, fileName, sceneManager, rootNode=None, prefix = ''): + self.fileName = fileName + self.sceneManager = sceneManager + self.cameras = [] + self.lights = [] + self.entities = [] + self.prefix = prefix # used to prefix the node name when creating nodes + nodes = self.findNodes(minidom.parse(self.fileName).documentElement,'nodes') + self.root = nodes[0].childNodes + + if rootNode: + self.rootNode = rootNode + else: + self.rootNode= self.sceneManager.getRootSceneNode() + + self.parseDotScene() + + # allows self['nodeName'] to reference xml node in '' + def __getitem__ (self,name): + return self.findNodes(self.root,name) + + def parseDotScene (self): + # TODO: check DTD to make sure you get all nodes/attributes + # TODO: Use the userData for sound/physics + for node in self.root: + if node.nodeType == Node.ELEMENT_NODE and node.nodeName == 'node': + realName = node.attributes['name'].nodeValue + # create new scene node + newNode = self.rootNode.createChildSceneNode() # self.prefix + realName) + + #position it + pos = self.findNodes(node, 'position')[0].attributes + newNode.position = (float(pos['x'].nodeValue), float(pos['y'].nodeValue), float(pos['z'].nodeValue)) + + # rotate it + try: + rot = self.findNodes(node, 'rotation')[0].attributes + newNode.orientation = ogre.Quaternion(float(rot['qw'].nodeValue), float(rot['qx'].nodeValue), + float(rot['qy'].nodeValue), float(rot['qz'].nodeValue)) +# print float(rot['qw'].nodeValue), float(rot['qx'].nodeValue), float(rot['qy'].nodeValue),float(rot['qz'].nodeValue) + except IndexError: # probably doesn't have rotation attribute + rot = self.findNodes(node, 'quaternion')[0].attributes + newNode.orientation = ogre.Quaternion(float(rot['w'].nodeValue), float(rot['x'].nodeValue), + float(rot['y'].nodeValue), float(rot['z'].nodeValue)) +# print float(rot['w'].nodeValue), float(rot['x'].nodeValue), float(rot['y'].nodeValue), float(rot['z'].nodeValue) + + # scale it + scale = self.findNodes(node, 'scale')[0].attributes + newNode.scale = (float(scale['x'].nodeValue), float(scale['y'].nodeValue), float(scale['z'].nodeValue)) + + # is it a light? + try: + thingy = self.findNodes(node, 'light')[0].attributes + name = str(thingy['name'].nodeValue) + attachMe = self.sceneManager.createLight(name) + ltypes={'point':ogre.Light.LT_POINT,'directional':ogre.Light.LT_DIRECTIONAL,'spot':ogre.Light.LT_SPOTLIGHT,'radPoint':ogre.Light.LT_POINT} + try: + attachMe.type = ltypes[thingy['type'].nodeValue] + except IndexError: + pass + + lightNode = self.findNodes(node, 'light')[0] + + try: + tempnode = self.findNodes(lightNode, 'colourSpecular')[0] + attachMe.specularColour = (float(tempnode.attributes['r'].nodeValue), float(tempnode.attributes['g'].nodeValue), float(tempnode.attributes['b'].nodeValue), 1.0) + except IndexError: + pass + + try: + tempnode = self.findNodes(lightNode, 'colourDiffuse')[0] + attachMe.diffuseColour = (float(tempnode.attributes['r'].nodeValue), float(tempnode.attributes['g'].nodeValue), float(tempnode.attributes['b'].nodeValue), 1.0) + except IndexError: + pass + + try: + tempnode = self.findNodes(lightNode, 'colourDiffuse')[0] + attachMe.diffuseColour = (float(tempnode.attributes['r'].nodeValue), float(tempnode.attributes['g'].nodeValue), float(tempnode.attributes['b'].nodeValue), 1.0) + except IndexError: + pass + self.lights.append( attachMe ) + + print 'added light: "%s"' % name + except IndexError: + pass + + # is it an entity? + try: + thingy = self.findNodes(node, 'entity')[0].attributes + name = str(thingy['name'].nodeValue) + mesh = str(thingy['meshFile'].nodeValue) + attachMe = self.sceneManager.createEntity(name,mesh) + self.entities.append(attachMe) +# print 'added entity: "%s" %s' % (name, mesh) + except IndexError: + pass + except ogre.OgreFileNotFoundException: # mesh is missing + print "Missing Mesh:",mesh + pass + + # is it a camera? + # TODO: there are other attributes I need in here + try: + thingy = self.findNodes(node, 'camera')[0].attributes + name = str(thingy['name'].nodeValue) + fov = float(thingy['fov'].nodeValue) + projectionType= str(thingy['projectionType'].nodeValue) + attachMe = self.sceneManager.createCamera(name) + try: + tempnode = self.findNodes(node, 'clipping')[0] + attachMe.nearClipDistance = float(tempnode.attributes['near'].nodeValue) + attachMe.farClipDistance = float(tempnode.attributes['far'].nodeValue) + except IndexError: + pass + attachMe.setFOVy ( ogre.Radian( fov ) ) #fOVy = fov + + self.cameras.append ( attachMe ) + print 'added camera: "%s" fov: %f type: %s clipping: %f,%f' % (name, fov, projectionType,attachMe.nearClipDistance,attachMe.farClipDistance) + except IndexError: + pass + + # attach it to the scene + try: + newNode.attachObject(attachMe) + except: + print "could not attach:",realName + + def __del__(self): + for camera in self.cameras: + self.sceneManager.destroyCamera(camera) + for light in self.lights: + self.sceneManager.destroyLight(light) + for entity in self.entities: + self.sceneManager.destroyEntity(entity) + + def findNodes (self,root, name): + out=minidom.NodeList() + if root.hasChildNodes: + nodes = root.childNodes + for node in nodes: + if node.nodeType == Node.ELEMENT_NODE and node.nodeName == name: + out.append(node) + return out \ No newline at end of file diff --git a/components/3d/base/_3d_env.py b/components/3d/base/_3d_env.py new file mode 100644 index 0000000..1d9d7c2 --- /dev/null +++ b/components/3d/base/_3d_env.py @@ -0,0 +1,37 @@ + +""" +----------------------------------------------------------------------------- +This source file is part of OSTIS (Open Semantic Technology for Intelligent Systems) +For the latest info, see http://www.ostis.net + +Copyright (c) 2010 OSTIS + +OSTIS is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +OSTIS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with OSTIS. If not, see . +----------------------------------------------------------------------------- +""" + + +import os + +# resources +resource_group = '3d' +media_dir = os.path.join(os.path.dirname(__file__), "media") +resource_dir = os.path.join(media_dir, resource_group) + +res_scene_location = os.path.join(resource_dir, 'scenes') + +material_state_pat = "3d_%s" + +# segment for searching +search_segments = ["/seb/3d"] diff --git a/components/3d/base/_3d_init.py b/components/3d/base/_3d_init.py new file mode 100644 index 0000000..3a3c6c5 --- /dev/null +++ b/components/3d/base/_3d_init.py @@ -0,0 +1,91 @@ + +""" +----------------------------------------------------------------------------- +This source file is part of OSTIS (Open Semantic Technology for Intelligent Systems) +For the latest info, see http://www.ostis.net + +Copyright (c) 2010 OSTIS + +OSTIS is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +OSTIS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with OSTIS. If not, see . +----------------------------------------------------------------------------- +""" +from suit import core + +import os +import _3d_env +import _3d_viewer +import _3d2sc + + +_version_ = "0.2.0" +_name_ = "3D-Viewver-interface" + +def initialize(): + + import suit.core.kernel as core + import suit.core.keynodes as keyn + from suit.core.objects import Factory + + global view_factory + global edit_factory + global trans_geom2sc_factory + + # register viewers and editors + kernel = core.Kernel.getSingleton() + # registering components + view_factory = Factory(viewer_creator) + trans_geom2sc_factory = Factory(transGeom2Sc_creator) + kernel.registerViewerFactory(view_factory, [keyn.ui.format_3d]) + kernel.registerTranslatorFactory(trans_geom2sc_factory, [keyn.ui.format_3d], [keyn.ui.format_sc]) + + +def shutdown(): + import suit.core.kernel as core + kernel = core.Kernel.getSingleton() + + global view_factory + global edit_factory + global trans_geom2sc_factory + + #TODO: make language unloading + + # unregister components + kernel.unregisterViewerFactory(view_factory) + kernel.unregisterTranslatorFactory(trans_geom2sc_factory) + + +def _resourceLocations(): + """Specified resources for a geometry module + """ + import suit.core.kernel as core + + res = [] + for directory in os.listdir ( _3d_env.res_scene_location ): + fullPath = os.path.join ( _3d_env.res_scene_location, directory ) + if os.path.isdir( fullPath ): + res.append((fullPath, "FileSystem", getResourceGroup())) + + return res + +def getResourceGroup(): + """Return resource group name + """ + return _3d_env.resource_group + +def viewer_creator(): + return _3d_viewer._3DViewer() + + +def transGeom2Sc_creator(): + return _3d2sc.Translator3D2Sc() \ No newline at end of file diff --git a/components/3d/base/_3d_modes.py b/components/3d/base/_3d_modes.py new file mode 100644 index 0000000..1a91966 --- /dev/null +++ b/components/3d/base/_3d_modes.py @@ -0,0 +1,152 @@ + +""" +----------------------------------------------------------------------------- +This source file is part of OSTIS (Open Semantic Technology for Intelligent Systems) +For the latest info, see http://www.ostis.net + +Copyright (c) 2010 OSTIS + +OSTIS is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +OSTIS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with OSTIS. If not, see . +----------------------------------------------------------------------------- +""" + +from suit.cf import BaseEditMode +from suit.cf.flymode import FlyMode +from suit.cf.VisualMenu import VisualMenu + + +import suit.core.render.engine as render_engine +import ogre.renderer.OGRE as ogre +import ogre.io.OIS as ois + + +class _3DViewMode(FlyMode, BaseEditMode): + """Mode that allows user to view and navigate in scg window + """ + def __init__(self, _logic): + FlyMode.__init__(self, _logic) + # highlighted object + self.main3dObject = None + self._shift = False + self._ctrl = False + self.highlighted_obj = None + + # widgets + self.type_combo = None + self.content_combo = None + + # object we worked on in current state + self.object_active = None + + # current mouse position + self.mouse_pos = (0, 0) + self.moveSpeed = 60 + + # # object we worked on in previous state + # self.object_prev = none + + # visual menu + self.vis_menu = None + self._createVisualMenu() + + def __del__(self): + FlyMode.__del__(self) + + def delete(self): + """Deletion message + """ + self.vis_menu.delete() + self.object_active = None + + + def activate(self): + """Activation message + """ + FlyMode.activate(self) + self._updateVisualMenu() + + def deactivate(self): + """Deactivation message + """ + FlyMode.deactivate(self) + self._updateVisualMenu() + + def _update(self, timeSinceLastFrame): + """Updates mode + """ + if FlyMode.isActive(self): + FlyMode._update(self,timeSinceLastFrame) + + def _onMouseMoved(self, _evt): + """Mouse moved event + """ + if FlyMode.isActive(self): + FlyMode._onMouseMoved(self, _evt) + return False + + def _onMousePressed(self, _evt, _id): + """Mouse button pressed event + """ + if FlyMode.isActive(self): + FlyMode._onMousePressed(self, _evt, _id) + return False + + def _createVisualMenu(self): + """Creates visual menu + """ + self.vis_menu = VisualMenu() + + + def _updateVisualMenu(self): + """Updates visual menu depending on selection + """ + if self._logic is None or self._logic._getSheet() is None: + return + + sel_objects = [] + self._logic._getSheet().getSelected() + + if self.vis_menu.isShow(): + self.vis_menu.hide() + + if not self.active: return + + n = len(sel_objects) + if n > 0: self.vis_menu.show(render_engine.pos3dTo2dWindow(sel_objects[0].getPosition())) + + def processInput(self): + # processing mouse input + ms = render_engine._oisMouse.getMouseState() + if ms.buttonDown(ois._ois_.MB_Right): + self.rotX = ogre.Degree(-ms.X.rel * 0.13) + self.rotY = ogre.Degree(-ms.Y.rel * 0.13) + + # processing keyboard input + if render_engine._oisKeyboard.isKeyDown(ois.KC_A): + self.move.x = -self.moveScale # Move camera left + + if render_engine._oisKeyboard.isKeyDown(ois.KC_D): + self.move.x = self.moveScale # Move camera RIGHT + + if render_engine._oisKeyboard.isKeyDown(ois.KC_W): + self.move.z = -self.moveScale # Move camera forward + + if render_engine._oisKeyboard.isKeyDown(ois.KC_S): + self.move.z = self.moveScale # Move camera backward + + if render_engine._oisKeyboard.isKeyDown(ois.KC_Q): + self.move.y = self.moveScale # Move camera up + + if render_engine._oisKeyboard.isKeyDown(ois.KC_E): + self.move.y = -self.moveScale # Move camera down + \ No newline at end of file diff --git a/components/3d/base/_3d_objects.py b/components/3d/base/_3d_objects.py new file mode 100644 index 0000000..83c53ca --- /dev/null +++ b/components/3d/base/_3d_objects.py @@ -0,0 +1,61 @@ + +""" +----------------------------------------------------------------------------- +This source file is part of OSTIS (Open Semantic Technology for Intelligent Systems) +For the latest info, see http://www.ostis.net + +Copyright (c) 2010 OSTIS + +OSTIS is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +OSTIS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with OSTIS. If not, see . +----------------------------------------------------------------------------- +""" +import os + +import suit.core.objects as objects +import suit.core.render.engine as render_engine +import _3d_dotscene as scene +import _3d_env as env + +# material postfix +state_post = {objects.Object.OS_Normal: '_Normal', + objects.Object.OS_Selected: '_Selected', + objects.Object.OS_Highlighted: '_Highlighted', + objects.Object.OS_WasInMemory: '_Normal', + objects.Object.OS_NewInMemory: '_Normal', + objects.Object.OS_Merged: '_Normal'} + +class _3DObject(objects.ObjectDepth): + def __init__(self, name = "roadster"): + """constructor + """ + objects.ObjectDepth.__init__(self) + # creating entity + path = os.path.abspath(os.path.join(env.res_scene_location, name, name + '.scene')) + self.__scene = scene.DotScene(path, render_engine.SceneManager, self.sceneNode) + + + def __del__(self): + objects.ObjectDepth.__del__(self) + self.__scene.__del__() + + def get_idtf(self): + """Returns object identificator. + It parse structures like: Point(A), Point A, pA and return A + """ + #FIXME: add parsing for Point(A), Point A and etc. structures + idtf = self.getText() + if idtf is None or len(idtf) == 0: + idtf = str(self)[-9:-2] # FIXME: make identification more useful + + return idtf diff --git a/components/3d/base/_3d_viewer.py b/components/3d/base/_3d_viewer.py new file mode 100644 index 0000000..b6a396c --- /dev/null +++ b/components/3d/base/_3d_viewer.py @@ -0,0 +1,149 @@ + +""" +----------------------------------------------------------------------------- +This source file is part of OSTIS (Open Semantic Technology for Intelligent Systems) +For the latest info, see http://www.ostis.net + +Copyright (c) 2010 OSTIS + +OSTIS is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +OSTIS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with OSTIS. If not, see . +----------------------------------------------------------------------------- +""" + + +import suit.core.objects as objects +from suit.cf.BaseModeLogic import BaseModeLogic +from _3d_modes import _3DViewMode +import suit.core.render.engine as render_engine +import ogre.io.OIS as ois +import ogre.renderer.OGRE as ogre +import _3d_objects + +class _3DViewer(BaseModeLogic): + """Geometry viewer logic realization + """ + def __init__(self): + """constructor + """ + + BaseModeLogic.__init__(self) + # view modes + # self.appendMode(ois.KC_X, FlyMode(self)) + # self._active_mode = self._modes[ois.KC_X] + self.appendMode(ois.KC_S, _3DViewMode(self)) + self.switchMode(ois.KC_S) + self.is_root = False + + def __del__(self): + """Destruction + """ + BaseModeLogic.__del__(self) + + def delete(self): + """Deletion message + """ + BaseModeLogic.delete(self) + + def _setSheet(self, _sheet): + BaseModeLogic._setSheet(self, _sheet) + + _sheet.eventRootChanged = self._onRootChanged + _sheet.eventUpdate = self._onUpdate + + _sheet.eventChildAppend = self._onAppendChild + _sheet.eventChildRemove = self._onRemoveChild + _sheet.eventContentUpdate = self._onContentUpdate + + + def _onRootChanged(self, _isRoot): + """Root changed event + """ + global prev_background + global prev_back_visible + BaseModeLogic._onRootChanged(self, _isRoot) + if _isRoot: + render_engine.setMode(render_engine.Mode_Perspective) + self.prev_cam_pos = render_engine._ogreCamera.getPosition() + self.prev_cam_dir = render_engine._ogreCamera.getOrientation() + self.prev_cam_node_pos = render_engine._ogreCameraNode.getPosition() + self.prev_cam_node_dir = render_engine._ogreCameraNode.getOrientation() + prev_background = render_engine._ogreViewport.getBackgroundColour() + render_engine._ogreViewport.setBackgroundColour(ogre.ColourValue(0, 0, 0)) + + prev_back_visible = render_engine.SceneManager.isBackVisible() + if prev_back_visible: + render_engine.SceneManager.hideBack() + + self.main3dObject = _3d_objects._3DObject() + self._getSheet().addChild(self.main3dObject) + render_engine._ogreCamera.setPosition(80,40,100) + render_engine._ogreCamera.lookAt(0,0,0) + else: + render_engine._ogreCameraNode.setPosition(self.prev_cam_node_pos) + render_engine._ogreCameraNode.setOrientation(self.prev_cam_node_dir) + render_engine._ogreCamera.setPosition(self.prev_cam_pos) + render_engine._ogreCamera.setOrientation(self.prev_cam_dir) + render_engine.setMode(render_engine.Mode_Isometric) + render_engine._ogreViewport.setBackgroundColour(prev_background) + self.main3dObject.__del__() + self._getSheet().removeChild(self.main3dObject) + self.main3dObject = None + + if prev_back_visible: + render_engine.SceneManager.showBack() + self.is_root = _isRoot + + def _onUpdate(self, _timeSinceLastFrame): + """Notification on update + """ + if self._getSheet().isRoot: + if self._active_mode: + self._active_mode._update(_timeSinceLastFrame) + + def _onContentUpdate(self): + + import suit.core.keynodes as keynodes + sheet = self._getSheet() + + sheet.content_type = objects.ObjectSheet.CT_String + sheet.content_data = str("") + sheet.content_format = keynodes.ui.format_3d + + def _onAppendChild(self, _object): + """Listener for sheet child objects appending + """ + pass + + def _onRemoveChild(self, _object): + """Listener for sheet child objects removing + """ + pass + + def _getObjectsUnderMouse(self, sortDistance = True, forced = False, mpos = None): + """@see: suit.core.objects.ObjectSheet._getObjectsUnderMouse + """ + res = [] + for child in self._getSheet().getChilds(): + res.extend(child.getChildsRecursively()) + + return res + + def _haveChild(self, child): + + res = [] + for _child in self._getSheet().getChilds(): + res.extend(_child.getChildsRecursively()) + res.append(_child) + + return res.count(child) > 0 diff --git a/components/3d/base/__init__.py b/components/3d/base/__init__.py new file mode 100644 index 0000000..807c94e --- /dev/null +++ b/components/3d/base/__init__.py @@ -0,0 +1,32 @@ +""" +----------------------------------------------------------------------------- +This source file is part of OSTIS (Open Semantic Technology for Intelligent Systems) +For the latest info, see http://www.ostis.net + +Copyright (c) 2010 OSTIS + +OSTIS is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +OSTIS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with OSTIS. If not, see . +----------------------------------------------------------------------------- +""" +__all__ = ["_3d_controls", + "_3d_editor", + "_3d_env", + "_3d_init", + "_3d_keynodes", + "_3d_modes", + "_3d_objects", + "_3d_panel", + "_3d_viewer", + "_3d2sc" + ] \ No newline at end of file diff --git a/components/3d/base/media/3d/scenes/roadster/Scene.material b/components/3d/base/media/3d/scenes/roadster/Scene.material new file mode 100644 index 0000000..f5cfaaf --- /dev/null +++ b/components/3d/base/media/3d/scenes/roadster/Scene.material @@ -0,0 +1,131 @@ +material glass +{ + //receive_shadows on + technique + { + pass + { + //ambient 0.500000 0.500000 0.500000 1.000000 + //diffuse 0.640000 0.640000 0.640000 1.000000 + //specular 0.500000 0.500000 0.500000 1.000000 12.500000 + //emissive 0.000000 0.000000 0.000000 1.000000 + scene_blend alpha_blend + add depth_write off + texture_unit + { + texture glass.tga + //tex_address_mode wrap + //filtering trilinear + //colour_op alpha_blend + } + } + } +} + +material gibs +{ +// receive_shadows on + technique + { + pass + { + ambient 0.500000 0.500000 0.500000 1.000000 + diffuse 0.640000 0.640000 0.640000 1.000000 + specular 0.500000 0.500000 0.500000 1.000000 12.500000 + emissive 0.000000 0.000000 0.000000 1.000000 + scene_blend alpha_blend + add depth_write off + texture_unit + { + texture gibs.png + tex_address_mode wrap + filtering trilinear + colour_op alpha_blend + } + } + } +} +material under +{ + receive_shadows on + technique + { + pass + { + ambient 0.500000 0.500000 0.500000 1.000000 + diffuse 0.640000 0.640000 0.640000 1.000000 + specular 0.500000 0.500000 0.500000 1.000000 12.500000 + emissive 0.000000 0.000000 0.000000 1.000000 + texture_unit + { + texture under.tga + tex_address_mode wrap + filtering trilinear + colour_op alpha_blend + } + } + } +} +material hlites +{ + receive_shadows on + technique + { + pass + { + ambient 0.500000 0.500000 0.500000 1.000000 + diffuse 0.640000 0.640000 0.640000 1.000000 + specular 0.500000 0.500000 0.500000 1.000000 12.500000 + emissive 0.000000 0.000000 0.000000 1.000000 + texture_unit + { + texture hlites.tga + tex_address_mode wrap + filtering trilinear + colour_op alpha_blend + } + } + } +} +material no_texture +{ + receive_shadows on + technique + { + pass + { + ambient 0.500000 0.500000 0.500000 1.000000 + diffuse 0.640000 0.640000 0.640000 1.000000 + specular 0.500000 0.500000 0.500000 1.000000 12.500000 + emissive 0.000000 0.000000 0.000000 1.000000 + texture_unit + { + texture int.tga + tex_address_mode wrap + filtering trilinear + colour_op alpha_blend + } + } + } +} +material red_main +{ + receive_shadows on + technique + { + pass + { + ambient 0.500000 0.500000 0.500000 1.000000 + diffuse 0.640000 0.640000 0.640000 1.000000 + specular 0.500000 0.500000 0.500000 1.000000 12.500000 + emissive 0.000000 0.000000 0.000000 1.000000 + texture_unit + { + texture green_main.tga + tex_address_mode wrap + filtering trilinear + colour_op alpha_blend + } + } + } +} diff --git a/components/3d/base/media/3d/scenes/roadster/b_glass.mesh b/components/3d/base/media/3d/scenes/roadster/b_glass.mesh new file mode 100644 index 0000000..372ba9d Binary files /dev/null and b/components/3d/base/media/3d/scenes/roadster/b_glass.mesh differ diff --git a/components/3d/base/media/3d/scenes/roadster/b_hlites.mesh b/components/3d/base/media/3d/scenes/roadster/b_hlites.mesh new file mode 100644 index 0000000..53f6ec5 Binary files /dev/null and b/components/3d/base/media/3d/scenes/roadster/b_hlites.mesh differ diff --git a/components/3d/base/media/3d/scenes/roadster/b_int.mesh b/components/3d/base/media/3d/scenes/roadster/b_int.mesh new file mode 100644 index 0000000..eabb0ad Binary files /dev/null and b/components/3d/base/media/3d/scenes/roadster/b_int.mesh differ diff --git a/components/3d/base/media/3d/scenes/roadster/b_main.mesh b/components/3d/base/media/3d/scenes/roadster/b_main.mesh new file mode 100644 index 0000000..e0cef53 Binary files /dev/null and b/components/3d/base/media/3d/scenes/roadster/b_main.mesh differ diff --git a/components/3d/base/media/3d/scenes/roadster/b_main1.mesh b/components/3d/base/media/3d/scenes/roadster/b_main1.mesh new file mode 100644 index 0000000..4961b60 Binary files /dev/null and b/components/3d/base/media/3d/scenes/roadster/b_main1.mesh differ diff --git a/components/3d/base/media/3d/scenes/roadster/b_steer.mesh b/components/3d/base/media/3d/scenes/roadster/b_steer.mesh new file mode 100644 index 0000000..da5a22e Binary files /dev/null and b/components/3d/base/media/3d/scenes/roadster/b_steer.mesh differ diff --git a/components/3d/base/media/3d/scenes/roadster/b_tlites.mesh b/components/3d/base/media/3d/scenes/roadster/b_tlites.mesh new file mode 100644 index 0000000..026fc8d Binary files /dev/null and b/components/3d/base/media/3d/scenes/roadster/b_tlites.mesh differ diff --git a/components/3d/base/media/3d/scenes/roadster/b_under.mesh b/components/3d/base/media/3d/scenes/roadster/b_under.mesh new file mode 100644 index 0000000..6e02f45 Binary files /dev/null and b/components/3d/base/media/3d/scenes/roadster/b_under.mesh differ diff --git a/components/3d/base/media/3d/scenes/roadster/pPlane2.mesh b/components/3d/base/media/3d/scenes/roadster/pPlane2.mesh new file mode 100644 index 0000000..ef4b18b Binary files /dev/null and b/components/3d/base/media/3d/scenes/roadster/pPlane2.mesh differ diff --git a/components/3d/base/media/3d/scenes/roadster/pPlane3.mesh b/components/3d/base/media/3d/scenes/roadster/pPlane3.mesh new file mode 100644 index 0000000..1553d20 Binary files /dev/null and b/components/3d/base/media/3d/scenes/roadster/pPlane3.mesh differ diff --git a/components/3d/base/media/3d/scenes/roadster/roadster.scene b/components/3d/base/media/3d/scenes/roadster/roadster.scene new file mode 100644 index 0000000..6384105 --- /dev/null +++ b/components/3d/base/media/3d/scenes/roadster/roadster.scene @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/3d/base/media/3d/scenes/textures/gibs.png b/components/3d/base/media/3d/scenes/textures/gibs.png new file mode 100644 index 0000000..ddf08a7 Binary files /dev/null and b/components/3d/base/media/3d/scenes/textures/gibs.png differ diff --git a/components/3d/base/media/3d/scenes/textures/glass.tga b/components/3d/base/media/3d/scenes/textures/glass.tga new file mode 100644 index 0000000..7dba226 Binary files /dev/null and b/components/3d/base/media/3d/scenes/textures/glass.tga differ diff --git a/components/3d/base/media/3d/scenes/textures/green_main.tga b/components/3d/base/media/3d/scenes/textures/green_main.tga new file mode 100644 index 0000000..48fe35f Binary files /dev/null and b/components/3d/base/media/3d/scenes/textures/green_main.tga differ diff --git a/components/3d/base/media/3d/scenes/textures/hlites.tga b/components/3d/base/media/3d/scenes/textures/hlites.tga new file mode 100644 index 0000000..824e3da Binary files /dev/null and b/components/3d/base/media/3d/scenes/textures/hlites.tga differ diff --git a/components/3d/base/media/3d/scenes/textures/int.tga b/components/3d/base/media/3d/scenes/textures/int.tga new file mode 100644 index 0000000..636532e Binary files /dev/null and b/components/3d/base/media/3d/scenes/textures/int.tga differ diff --git a/components/3d/base/media/3d/scenes/textures/under.tga b/components/3d/base/media/3d/scenes/textures/under.tga new file mode 100644 index 0000000..d4e6295 Binary files /dev/null and b/components/3d/base/media/3d/scenes/textures/under.tga differ diff --git a/components/__init__.py b/components/__init__.py index 0dab6bd..f430678 100644 --- a/components/__init__.py +++ b/components/__init__.py @@ -19,7 +19,7 @@ along with OSTIS. If not, see . ----------------------------------------------------------------------------- """ -__all__ = ['scg', +__all__ = ['3d', 'scg', 'common', 'geometry', 'text', @@ -42,7 +42,6 @@ modules = [ 'common.menu', 'panels.mainpanel', - 'panels.userpanel', # 'panels.windowpanel', 'panels.taskpanel', 'scg.base.scg_init', @@ -53,12 +52,14 @@ 'graph.graph_init', 'image.image_init', # 'map.map_init', - #'space.space_init', + 'space.space_init', 'video.video_init', 'geometry.base.geom_init', + '3d.base._3d_init', + # 'LUI.lui_init', # 'LUI_voice_output.vo_init', 'questions.questions_init', - 'math.math_init' +# 'math.math_init' 'logic.logic_init' ] \ No newline at end of file diff --git a/repo/fs_repo_src/ui/core_src/3d.gwf b/repo/fs_repo_src/ui/core_src/3d.gwf new file mode 100644 index 0000000..05af3f4 --- /dev/null +++ b/repo/fs_repo_src/ui/core_src/3d.gwf @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/repo/fs_repo_src/ui/core_src/ui_keynodes.gwf b/repo/fs_repo_src/ui/core_src/ui_keynodes.gwf index 59047cf..82ec235 100644 --- a/repo/fs_repo_src/ui/core_src/ui_keynodes.gwf +++ b/repo/fs_repo_src/ui/core_src/ui_keynodes.gwf @@ -1,473 +1,470 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/suit/core/render/engine.py b/suit/core/render/engine.py index 9c0d383..3e11ec2 100644 --- a/suit/core/render/engine.py +++ b/suit/core/render/engine.py @@ -849,14 +849,26 @@ def SceneManager_createSceneNode(_name = None): """Creates ogre scene node @param _name: scene node name (if it will be None, then will be used default name) @type _name: str - + @return: returns created scene node - """ + """ if _name: return _ogreSceneManager.createSceneNode(_name) - + return _ogreSceneManager.createSceneNode() +def SceneManager_createLight(_name): + return _ogreSceneManager.createLight(_name) + +def SceneManager_createCamera(_name): + return _ogreSceneManager.createCamera(_name) + +def SceneManager_destroyLight(_light): + _ogreSceneManager.destroyLight(_light) + +def SceneManager_destroyCamera(_camera): + _ogreSceneManager.destroyCamera(_camera) + def SceneManager_destroyEntity(_entity): """Destroys entity @@ -994,11 +1006,15 @@ class SceneManager: createEntity = staticmethod(SceneManager_createEntity) createManualObject = staticmethod(SceneManager_createManualObject) createSceneNode = staticmethod(SceneManager_createSceneNode) + createLight = staticmethod(SceneManager_createLight) + createCamera = staticmethod(SceneManager_createCamera) destroyEntity = staticmethod(SceneManager_destroyEntity) destroyManualObject = staticmethod(SceneManager_destroyManualObject) destroySceneNode = staticmethod(SceneManager_destroySceneNode) - + destroyLight = staticmethod(SceneManager_destroyLight) + destroyCamera = staticmethod(SceneManager_destroyCamera) + resetScale = staticmethod(SceneManager_resetScale) setScale = staticmethod(SceneManager_setScale) setBackMaterial = staticmethod(SceneManager_setBackMaterial)