2016年12月22日 星期四

20161222 小楓兒筆記

Richo Theta S及360 Video/Image



360度照片


連線前先安裝軟體
https://theta360.com/uk/support/download/

連Theta的wifi就可以看Theta拍攝的照片
密碼會是Theta的wifi數字


*自製360度照片

下載360度的照片
https://www.facebook.com/photo.php?fbid=1401094823236670&set=gm.1855406564745433&type=3&theater

用小畫家做修改再上傳到FB
https://www.facebook.com/photo.php?fbid=1401097453236407&set=gm.1855406874745402&type=3&theater





Tango

Elementals Home AR Designer
https://www.youtube.com/watch?v=Xa85cGTRR0o

Best Augmented Reality - BikeConfig Project Tango
https://www.youtube.com/watch?v=4g6_VVDclVk

thyssenkrupp – bringing new vision to elevator maintenance with Microsoft HoloLens
https://www.youtube.com/watch?v=8OWhGiyR4Ns

擺家具





3D石雕模型





















試著成品



float H=256/10.0, D=256/10.0/3.0*2;
PVector [][] faces;
PImage img;
int faceN=0;//count: 50*N, N is (288-1)*(288-1)*2*3
void setup(){
  size(600,600,P3D);
  img=loadImage("photo.png");
  img.filter(GRAY);
  img.loadPixels();
  PVector [] depth= new PVector[img.width*img.height];
  for(int i=0;i<img.height;i++){
    for(int j=0;j<img.width;j++){
      depth[i*img.width+j]=new PVector(j-img.width/2, i-img.height/2, H-D+D*blue(img.pixels[i*img.width+j])/256.0);
      if(i<10 || j<10 || i>img.height-10 || j>img.width-10) depth[i*img.width+j].z=H;
    }
  }
  faces = new PVector[(img.width-1)*(img.height-1)*2 +10][4];
  PVector up=new PVector(0,0,1);
  for(int i=0;i<img.height-1;i++){
    for(int j=0;j<img.width-1;j++){
      faces[faceN][0]=up;
      faces[faceN][1]=depth[i*img.width+j];
      faces[faceN][3]=depth[(i+1)*img.width+j];
      faces[faceN][2]=depth[i*img.width+(j+1)];
      faceN++;
      faces[faceN][0]=up;
      faces[faceN][1]=depth[(i+1)*img.width+j];
      faces[faceN][2]=depth[(i+1)*img.width+(j+1)];
      faces[faceN][3]=depth[i*img.width+(j+1)];
      faceN++;
    }
  }
  square(-img.width/2, -img.height/2, -256/10.0,  img.width, 0,0,  0,img.height,0);//back
  square(-img.width/2, -img.height/2, -256/10.0,  0,0,H*2, 0,img.height,0);//left
  square(-img.width/2, -img.height/2, -256/10.0,  0,0,H*2, img.width,0,0);//top

  square(img.width/2, img.height/2, -256/10.0,  0,0,H*2, 0,-img.height,0);//left
  square(img.width/2, img.height/2, -256/10.0,  0,0,H*2, -img.width,0,0);//left

  //faces = stlLoad("CCE.stl");
  stlSave("photo.stl", "SLA by Jeng-Sheng Yeh, 2015-11-05 ", faces);
}
void square(float x, float y, float z, float d1x, float d1y, float d1z, float d2x, float d2y, float d2z){
  PVector up = new PVector(0, 0, 1);
  faces[faceN][0]=up;
  faces[faceN][1]=new PVector(x, y, z);
  faces[faceN][2]=new PVector(x+d1x, y+d1y, z+d1z);
  faces[faceN][3]=new PVector(x+d2x, y+d2y, z+d2z);
  faceN++;
  faces[faceN][0]=up;
  faces[faceN][1]=new PVector(x+d1x, y+d1y, z+d1z);
  faces[faceN][2]=new PVector(x+d1x+d2x, y+d1y+d2y, z+d1z+d2z);
  faces[faceN][3]=new PVector(x+d2x, y+d2y, z+d2z);
  faceN++;
}
void draw(){
  noStroke();
  //image(img,0,0);
  drawSTL();
}
boolean bStop=false;
float angleStop=0;
PShape shape2=null;
void drawSTL(){
  background(255);
  lights();
  translate(width/2, height/2);
  float angle=frameCount*3.1415/180;
  if(frameCount%360>90 &&frameCount%360<270) angle=PI-angle;
  if(bStop)rotateY(angleStop);
  else{ rotateY(angle); angleStop=angle;}
  fill(255);

  if(shape2==null){
    shape2=createShape();
    shape2.beginShape(TRIANGLES);
    for(int i=0;i<faces.length;i++){
      for(int j=1;j<4;j++){
        shape2.fill(255, 255-faces[i][j].z*10+128, 255-faces[i][j].z*10);
        shape2.vertex(faces[i][j].x, faces[i][j].y, faces[i][j].z);
      }
    }
    shape2.endShape();
  }
  shape(shape2, 0,0);
}
PVector[][] stlLoad(String filename){
  byte b[] = loadBytes(filename);
  int faceN=int(b[80]) | int(b[81])<<8 | int(b[82])<<16 | int(b[83])<<24;
  println("faceN: "+faceN);
  PVector [][] stlfaces=new PVector[faceN][4];
  float minX=99999,maxX=-99999, minY=99999,maxY=-99999, minZ=99999,maxZ=-99999;
  for(int i=0;i<faceN;i++){
    for(int j=0;j<4;j++){
      stlfaces[i][j]= stlBytesToPVector(b, 84+i*50+j*12);
      if(stlfaces[i][j].x<minX)minX=stlfaces[i][j].x;
      if(stlfaces[i][j].x>maxX)maxX=stlfaces[i][j].x;
      if(stlfaces[i][j].y<minY)minY=stlfaces[i][j].y;
      if(stlfaces[i][j].y>maxY)maxY=stlfaces[i][j].y;
      if(stlfaces[i][j].z<minZ)minZ=stlfaces[i][j].z;
      if(stlfaces[i][j].z>maxZ)maxZ=stlfaces[i][j].z;
    }
  }
  float centerX=(maxX+minX)/2, centerY=(maxY+minY)/2, centerZ=(maxZ+minZ)/2;
  float scale = width/(maxX-minX)/2;
  println("x:"+centerX+" y:"+centerY+" z:"+centerZ+" scale:"+scale);
  for(int i=0;i<faceN;i++){
    for(int j=1;j<4;j++){
      stlfaces[i][j].x -=centerX; stlfaces[i][j].x *=scale;
      stlfaces[i][j].y -=centerY; stlfaces[i][j].y *=scale;
      stlfaces[i][j].z -=centerZ; stlfaces[i][j].z *=scale;
    }
  }
  return stlfaces;
}
float stlBytesToFloat(byte b1, byte b2, byte b3, byte b4){
  int asInt = int(b1) | int(b2)*256 |int(b3)*256*256 | int(b4)*256*256*256;
  return Float.intBitsToFloat(asInt);
}
PVector stlBytesToPVector(byte []b, int s){
  float f1=stlBytesToFloat(b[s+0], b[s+1], b[s+2], b[s+3]);
  float f2=stlBytesToFloat(b[s+4], b[s+5], b[s+6], b[s+7]);
  float f3=stlBytesToFloat(b[s+8], b[s+9], b[s+10],b[s+11]);
  return new PVector(f1,f2,f3);
}
void stlSave(String filename, String header, PVector[][]faces){
  int faceN=faces.length;
  byte bw[]=new byte[80+4+faceN*50];
  stlHeader(bw, header, faceN);
  for(int i=0;i<faceN;i++){
    for(int j=0;j<4;j++){
      stlSetBits(bw, Float.floatToIntBits(faces[i][j].x), 84+i*50+j*12);
      stlSetBits(bw, Float.floatToIntBits(faces[i][j].y), 84+i*50+j*12+4);
      stlSetBits(bw, Float.floatToIntBits(faces[i][j].z), 84+i*50+j*12+8);
    }
  }
  saveBytes(filename, bw);
}
void stlSetBits(byte[] b, int bits, int i){//private function
  b[i]=byte(bits&0xff); b[i+1]=byte((bits>>8)&0xff); b[i+2]=byte((bits>>16)&0xff); b[i+3]=byte((bits>>24)&0xff);
}
void stlHeader(byte[] b, String header, int N){//private function
  for(int i=0;i<80;i++){
    if(i<header.length())b[i]=byte(header.charAt(i));
    else b[i]=byte(' ');
  }
  b[80]=byte(N&0xff); b[81]=byte((N>>8)&0xff); b[82]=byte((N>>16)&0xff); b[83]=byte((N>>24)&0xff);
}
void keyPressed(){
  if(key=='1') save("img1.jpg");
  if(key=='2') save("img2.jpg");
  if(key=='s') bStop=!bStop;
}



沒有留言:

張貼留言