Browse Source

process_atlas also adding edges to atlasses

dmuratshin 10 years ago
parent
commit
d52ca1895a
3 changed files with 31 additions and 9 deletions
  1. 2 4
      examples/Demo/src/TestEdges.h
  2. 6 0
      oxygine/src/res/ResAtlas.cpp
  3. 23 5
      tools/resbuild/process_atlas.py

+ 2 - 4
examples/Demo/src/TestEdges.h

@@ -11,20 +11,18 @@ public:
         for (int y = 0; y < 3; ++y)
         for (int y = 0; y < 3; ++y)
             for (int x = 0; x < 3; ++x)
             for (int x = 0; x < 3; ++x)
             {
             {
-                //spSprite sp = new ColorRectSprite;
                 spSprite sp = new Sprite;
                 spSprite sp = new Sprite;
                 sp->setResAnim(resources.getResAnim("edges"));
                 sp->setResAnim(resources.getResAnim("edges"));
-
                 sp->setSize(100.0f, 100.0f);
                 sp->setSize(100.0f, 100.0f);
                 sp->setPosition(x * 100.0f, y * 100.0f);
                 sp->setPosition(x * 100.0f, y * 100.0f);
                 sp->attachTo(parent);
                 sp->attachTo(parent);
             }
             }
 
 
         content->addChild(parent);
         content->addChild(parent);
-        parent->setPosition(100.0f, 100.0f);
+        parent->setPosition(getStage()->getSize() / 2 - Vector2(200, 200));
         parent->setAnchor(0.5f, 0.5f);
         parent->setAnchor(0.5f, 0.5f);
         parent->setSize(300.0f, 300.0f);
         parent->setSize(300.0f, 300.0f);
-        parent->addTween(Actor::TweenPosition(1000.0f, 1000.0f), 30000, -1);
+        parent->addTween(Actor::TweenPosition(getStage()->getSize() / 2 + Vector2(200, 200)), 30000, -1, true);
         parent->addTween(Actor::TweenRotationDegrees(360.0f), 10000, -1);
         parent->addTween(Actor::TweenRotationDegrees(360.0f), 10000, -1);
         parent->addTween(Actor::TweenScale(1.5f), 3000, -1, true);
         parent->addTween(Actor::TweenScale(1.5f), 3000, -1, true);
     }
     }

+ 6 - 0
oxygine/src/res/ResAtlas.cpp

@@ -531,6 +531,12 @@ namespace oxygine
                         operations::copy(src.getRect(Rect(0, 0, 1, src.h)),         mt.lock(&Rect(dest.pos.x - 1, dest.pos.y,    1, src.h)));
                         operations::copy(src.getRect(Rect(0, 0, 1, src.h)),         mt.lock(&Rect(dest.pos.x - 1, dest.pos.y,    1, src.h)));
                         operations::copy(src.getRect(Rect(src.w - 1, 0, 1, src.h)), mt.lock(&Rect(dest.pos.x + src.w, dest.pos.y, 1, src.h)));
                         operations::copy(src.getRect(Rect(src.w - 1, 0, 1, src.h)), mt.lock(&Rect(dest.pos.x + src.w, dest.pos.y, 1, src.h)));
 
 
+                        operations::copy(src.getRect(Rect(0, 0, 1, 1)), mt.lock(&Rect(dest.pos.x - 1, dest.pos.y - 1, 1, 1)));
+                        operations::copy(src.getRect(Rect(src.w - 1, 0, 1, 1)), mt.lock(&Rect(dest.pos.x + src.w, dest.pos.y - 1, 1, 1)));
+
+                        //operations::copy(src.getRect(Rect(0, src.h - 1, 1, 1)), mt.lock(&Rect(dest.pos.x - 1, dest.pos.y + src.h, 1, 1)));
+                        //operations::copy(src.getRect(Rect(src.w - 1, src.h - 1, 1, 1)), mt.lock(&Rect(dest.pos.x + src.w, dest.pos.y + src.h, 1, 1)));
+
 
 
                         float iw = 1.0f;
                         float iw = 1.0f;
                         float ih = 1.0f;
                         float ih = 1.0f;

+ 23 - 5
tools/resbuild/process_atlas.py

@@ -54,6 +54,9 @@ def premultipliedAlpha(image):
 
 
     return image    
     return image    
 
 
+def bbox(x, y, w, h):
+    return (x, y, x + w, y + h)
+
 class alphaData:
 class alphaData:
     def __init__(self, w, h, data):
     def __init__(self, w, h, data):
         self.w = w
         self.w = w
@@ -70,7 +73,7 @@ class frame:
 
 
         self.node = None
         self.node = None
         self.resanim = rs
         self.resanim = rs
-        self.border_top = self.border_left = 0
+        self.border_top = self.border_left = 2
         self.border_right = self.border_bottom = 1
         self.border_right = self.border_bottom = 1
 
 
         if not bbox:
         if not bbox:
@@ -524,10 +527,10 @@ class atlas_Processor(process.Process):
         st.max_w = context.args.max_width
         st.max_w = context.args.max_width
         st.max_h = context.args.max_height
         st.max_h = context.args.max_height
         st.square = context.compression == "pvrtc"
         st.square = context.compression == "pvrtc"
-
+        st.padding = 0
+        
         if len(frames) == 1:
         if len(frames) == 1:
-            st.get_size = get_original_frame_size
-            st.padding = 0
+            st.get_size = get_original_frame_size            
 
 
         pck(st, frames) 
         pck(st, frames) 
 
 
@@ -541,8 +544,23 @@ class atlas_Processor(process.Process):
                 x = node.rect.x + fr.border_left
                 x = node.rect.x + fr.border_left
                 y = node.rect.y + fr.border_top
                 y = node.rect.y + fr.border_top
                 sz = fr.image.size
                 sz = fr.image.size
-                rect = (x, y, x + sz[0], y + sz[1])
+                rect = bbox(x, y, sz[0], sz[1])
+                
+                part = fr.image.crop(bbox(0, 0,     sz[0], 1))
+                image.paste(part,    bbox(x, y - 1, sz[0], 1))
+
+                part = fr.image.crop(bbox(0, sz[1] - 1, sz[0], 1))
+                image.paste(part,    bbox(x, y + sz[1], sz[0], 1))
+
+
+                part = fr.image.crop(bbox(0    , 0,     1, sz[1]))
+                image.paste(part,    bbox(x - 1, y,     1, sz[1]))
+                
+                part = fr.image.crop(bbox(sz[0]- 1, 0,  1, sz[1]))
+                image.paste(part,    bbox(x+sz[0],  y,  1, sz[1]))
+
                 image.paste(fr.image, rect)
                 image.paste(fr.image, rect)
+
                 fr.atlas_id = atlas_id
                 fr.atlas_id = atlas_id
 
 
             image_atlas_el = walker.root_meta.ownerDocument.createElement("atlas")                
             image_atlas_el = walker.root_meta.ownerDocument.createElement("atlas")