Skip to content
This repository was archived by the owner on Sep 25, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions components/3d/__init__.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
-----------------------------------------------------------------------------
"""
__all__ = ['base']
54 changes: 54 additions & 0 deletions components/3d/base/_3d2sc.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
-----------------------------------------------------------------------------
"""

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
80 changes: 80 additions & 0 deletions components/3d/base/_3d_controls.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
-----------------------------------------------------------------------------
"""

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


161 changes: 161 additions & 0 deletions components/3d/base/_3d_dotscene.py
Original file line number Diff line number Diff line change
@@ -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 '<nodes>'
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
37 changes: 37 additions & 0 deletions components/3d/base/_3d_env.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
-----------------------------------------------------------------------------
"""


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"]
Loading