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
25 changes: 23 additions & 2 deletions components/scg/base/scg_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,28 @@ def _createContour(self, points):
sheet.addChild(contour)
contour.setPoints(points)
contour.setState(objects.Object.OS_Normal)
return contour



def _createLine(self,begin, end):
"""Create line
"""
import random
line = render_engine._ogreSceneManager.createManualObject("temp_"+str(random.random()))
myManualObjectNode = render_engine._ogreSceneManager.getRootSceneNode().createChildSceneNode("temp_node"+str(random.random()))
line.setDynamic(True)

manualObjectMaterial = ogre.MaterialManager.getSingleton().create("temp_material","General")
manualObjectMaterial.setReceiveShadows(False);
manualObjectMaterial.getTechnique(0).setLightingEnabled(True);
manualObjectMaterial.getTechnique(0).getPass(0).setDiffuse(0,0,1,0);
manualObjectMaterial.getTechnique(0).getPass(0).setAmbient(0,0,1);
manualObjectMaterial.getTechnique(0).getPass(0).setSelfIllumination(0,0,1);

line.begin("temp_material", ogre.RenderOperation.OT_LINE_LIST)
line.position(begin)
line.position(end)
line.end()
myManualObjectNode.attachObject(line)

return myManualObjectNode

39 changes: 35 additions & 4 deletions components/scg/base/scg_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ def __init__(self, _logic):
# button.eventPush = self._onToolBarButtonPush
#
# self.toolbar.setButtonSize(38)

#contour points
self.contour_points = []
self.contour_lines = []


def __del__(self):
Expand Down Expand Up @@ -397,12 +401,20 @@ def _onMousePressed(self, _evt, _id):
# * if pressed left button and there are no objects under mouse, then
# creating new scg-node
elif _id == ois.MB_Right:
#check if modifire key pressed
is_modifire_down = render_engine._oisKeyboard.isModifierDown(render_engine._oisKeyboard.Modifier.Shift)
# check objects under mouse
if self.state is SCgEditMode.ES_None:
if len(mobjects) is 0:
self._logic._createNode((mstate.X.abs, mstate.Y.abs))
self.state = SCgEditMode.ES_None
return True
#check if contour draw mode
if is_modifire_down:
self.contour_points.append(render_engine.pos2dTo3dIsoPos([mstate.X.abs, mstate.Y.abs]))
self.state = SCgEditMode.ES_ContourCreate

else:
self._logic._createNode((mstate.X.abs, mstate.Y.abs))
self.state = SCgEditMode.ES_None
return True
else:
if self.line_mode_beg is None:
self.state = SCgEditMode.ES_LineCreate
Expand All @@ -417,7 +429,26 @@ def _onMousePressed(self, _evt, _id):
self._updateLineCreationObjects()

return True

# contour creation state
elif self.state is SCgEditMode.ES_ContourCreate:
sheet=self._logic._getSheet()
self.contour_points.append(render_engine.pos2dTo3dIsoPos(((mstate.X.abs, mstate.Y.abs))))
self.contour_lines.append(self._logic._createLine(self.contour_points[-1],self.contour_points[-2]))
if is_modifire_down and len(self.contour_points)>2:
contour = self._logic._createContour(self.contour_points)
for line in self.contour_lines:
render_engine._ogreSceneManager.getRootSceneNode().removeChild(line)
self.contour_lines = []
sheet.removeChild(contour)
childs = sheet.getChilds()
for i in range(len(childs)):
current = childs[0]
if scg_utils.checkOnPointInContour(current.position,self.contour_points):
sheet.removeChild(current)
render_engine.SceneNode.addChild(contour.sceneNode, current.sceneNode)
self._logic._getSheet().addChild(contour)
self.contour_points = []
self.state = SCgEditMode.ES_None
# line creation state
elif (self.state is SCgEditMode.ES_LineCreate) and (self.line_mode_beg is not None):
# check if is there
Expand Down
35 changes: 35 additions & 0 deletions components/scg/base/scg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,38 @@ def createWindowFromNode(_node, _format, _is_edit):


return sheet

def checkOnPointInContour(point, polygon):
if len(polygon) < 3:
return False
q_patt = ((0,1), (3,2));

import ogre.renderer.OGRE as ogre

pred_pt = ogre.Vector3(polygon[-1].x, polygon[-1].y, 0)
pred_pt.x -= point.x
pred_pt.y -= point.y

pred_q=q_patt[pred_pt.y<0][pred_pt.x<0];

w = 0

for cur_pt in polygon:
cur_pt = ogre.Vector3(cur_pt.x, cur_pt.y, 0)
cur_pt.x -= point.x
cur_pt.y -= point.y

q=q_patt[cur_pt.y<0][cur_pt.x<0];

if q-pred_q == -3:
w+=1
if q-pred_q == 3:
w-=1
if q-pred_q == -2:
if pred_pt[0]*cur_pt[1]>=pred_pt[1]*cur_pt[0]: w+=1
if q-pred_q == 2:
if not (pred_pt[0]*cur_pt[1]>=pred_pt[1]*cur_pt[0]): w-=1

pred_pt = cur_pt
pred_q = q
return w != 0