media @ VU
[] readme course preface I 1 2 II 3 4 III 5 6 7 IV 8 9 10 V 11 12 afterthoughts appendix references examples resources _

talk show tell print

proto-slide-element-channel.vr

proto-slide-element-channel.vr (wrl ) [ flux / bitmanagement / cortona / octaga ]


  

channel

Web3D/VR

include


  
  ##proto @vr-proto-slide-element-line.wrl
  ##proto @vr-proto-slide-element-image.wrl
  ##proto @vr-proto-slide-element-vrml.wrl
  ##proto @vr-proto-slide-element-text.wrl
  ##proto @vr-proto-slide-element-break.wrl
  ##proto @vr-proto-slide-element-bullet.wrl
  ##proto @vr-proto-slide-element-nesting.wrl
  ##proto @vr-proto-slide-element-block.wrl
  
  

text


  
  
  
  
  
  PROTO TextBlock [
      exposedField SFString   blockType      "TEXTBLOCK"
      exposedField SFBool     warnOnSize     FALSE
       
      field        SFFloat    width          25 ## AE
      field        SFFloat    height         15
      eventOut     SFFloat    realHeight     
  
      exposedField SFVec3f    location       0 0 0
      exposedField SFRotation rotation    0 1 0 0
      exposedField SFVec3f    scale          1 1 1 ## AE  
  
      exposedField SFBool     absolute    FALSE
  
      ##exposedField SFString   url   "image.gif"
      exposedField SFString   url   ""
      exposedField SFInt32    bgType  0
  
      eventIn SFColor    color
      eventIn SFFloat    alpha
      exposedField SFColor    bgColor        0 0 1
      exposedField SFFloat    bgTransparency 0.5
  
      eventIn      SFInt32    showLevel
      exposedField SFInt32    lastLevel      -1
  
      eventIn SFTime startTime
      eventIn SFTime stopTime
  
      exposedField MFNode     elements       []
  
  ] {
  

body


      Transform {
          translation IS location
          rotation    IS rotation
          scale       IS scale
          children [
              DEF BOXTRANSFORM Transform {
                  translation 0 0 -1
                  scale 1.1 1 1
              }
              DEF TRANSFORM Transform {
                  children [
                      DEF GROUP Group {}
                  ]
              }
          ]
      }
  

script


      DEF SCRIPT Script {
          mustEvaluate  TRUE
          directOutput  TRUE
  
          eventIn SFColor    color IS color
          eventIn SFFloat    alpha IS alpha
  
          eventIn SFTime startTime IS startTime
          eventIn SFTime stopTime IS stopTime
  
          field    MFNode back NULL
  
          field    SFNode  me             USE SCRIPT
          field    SFNode  groupNode      USE GROUP
          field    SFNode  transform      USE TRANSFORM
          field    SFNode  boxTransform   USE BOXTRANSFORM
  
          field    SFFloat width          IS  width
          field    SFFloat height         IS  height
          eventOut SFFloat realHeight     IS  realHeight
  
          field    SFInt32 lastLevel      IS  lastLevel
          eventOut SFInt32 lastLevel_changed IS lastLevel
  
          field    MFNode  elements       IS elements
  
          field SFString   xurl            IS url
          field SFInt32    bgType        IS bgType
          field SFColor    bgColor        IS bgColor
          field SFFloat    bgTransparency IS bgTransparency
  
          eventIn SFInt32  layoutLevel    IS showLevel
          field   SFInt32  currentLevel   -1          
  
          field SFBool absolute IS absolute
  
      
  

functions


          url "javascript:
              function initialize() {
                  // Setup translation so (0,0) is in left/top corner
                  if (!absolute) transform.translation = new SFVec3f(-width/2,height/2,0);
                  countLevels();
                  layoutLevel(0,0);
  
                  var bgBox;
                  // Setup backgroundBox to be size widthXheight
                  if ( bgType == 0 ) {
                  bgBox = Browser.createVrmlFromString('  Shape { appearance Appearance { material Material { diffuseColor  0 0 0 specularColor 0 0 0 emissiveColor ' + bgColor + ' transparency ' +  bgTransparency + ' }  }  geometry Box { size ' + width + ' ' + height + ' 0.01 } } ');
                   } else if ( bgType == 1 ) {
                  bgBox = Browser.createVrmlFromString('  Shape { appearance Appearance { material Material { diffuseColor  0 0 0 specularColor 0 0 0 emissiveColor ' + bgColor + ' transparency ' +  bgTransparency + ' } texture ImageTexture { url \"' + xurl + '\" } } geometry Box { size ' + width + ' ' + height + ' 0.01 } } ');
                   } else if ( bgType == 2 ) {
                   bgBox = Browser.createVrmlFromString('  Shape { appearance Appearance { material Material { diffuseColor  0 0 0 specularColor 0 0 0 emissiveColor ' + bgColor + ' transparency ' +  bgTransparency + ' } texture DEF MOVIE MovieTexture { loop TRUE url \"' + xurl + '\" } } geometry Box { size ' + width + ' ' + height + ' 0.01 } } Sound { source USE MOVIE } ');
                   } else if ( bgType == 3 ) {
                   bgBox = Browser.createVrmlFromString(' slide-vcr { video \"' + xurl + '\"  size ' + width + ' ' + height + ' 0.1 }'); 
                  }
  
                    back = bgBox;
                    boxTransform.children = bgBox;
  //                boxTransform.scale = new SFVec3f(width,height,1);
              }
  

color


  
  function color(value) {
          bgColor =  value;
          back[0].appearance.material.emissiveColor = value;
          //print('bgcolor ' + value);
          }
  function alpha(value) {
          bgTransparency = value;
          back[0].appearance.material.transparency = value;
          //print('alpha ' + value);
          }
  
  function startTime(value) {
          if (bgType == 3) back[0].startTime = value;
          }
  function stopTime(value) {
          if (bgType == 3) back[0].stopTime = value;
          }
  

levels


              function countLevels() {
                  var i = 0;
                  var last = -1;
                  for(i=0;i<elements.length;i++) {
                      if(elements[i].startLevel != -1) {
                          if(elements[i].startLevel > last) {
                              last = elements[i].startLevel;
                          }
                      }
                      if(elements[i].endLevel != -1) {
                          if(elements[i].endLevel > last) {
                              last = elements[i].endLevel;
                          }
                      }
                  }
                  //lastLevel = -1;
                  lastLevel = last;
                  lastLevel_changed = last;
              }
  

layout


              function layoutLevel(level,time) {
                  if(level==currentLevel) {
                          if (bgType == 3) {
                                  bgBox.stopTime = Browser.getTime();
                                  }
                          return;
                          }
                  currentLevel = level;
  
                  var nodes = getNodesForLevel(level);
                  var block = new MFNode();
  
                  var nesting = 0;
                  var i = 0;
                  var j = 0;
                  var n = 0;
                  var x = 0.0;
                  var y = -1.0; // need proper initialize !
                  var first = 0;
                  for(i=0;i<nodes.length;i++) {
                      if(nodes[i].elementType == 'NESTING' ) {
                          nesting = nesting + nodes[i].nesting;
                          if(first==n) {
                              x = nesting;
                          }
                      } else if(nodes[i].linebreak) {
                          if(first!=n && block[first].justify[0]!='BEGIN') {
                              var delta = width - x;
                              if(block[first].justify[0]=='MIDDLE') {
                                  delta = delta / 2;
                              }
                              if(delta > 0) {
                                  for(j=first;j<n;j++) {
                                      if (!block[j].absolute) {
                                      block[j].position[0] += delta;    
  				    }
                                  }
                              }
                          }
                          //x = 0;
                          x = nesting;
                          y = y - nodes[i].height;
                          first = n;
                      } else {
                          if(x > width) {
                              x = 0;
                              y = y - block[n-1].height;
                              first = n;
                          }
                          //}
                          if (!nodes[i].absolute) {
                             nodes[i].position[0] = x; 
                             nodes[i].position[1] = y; 
                             }
                          block[n] = nodes[i];
                          n = n + 1;
                          if(block[n-1].elementType == 'TEXTELEMENT') {
                              if((x + block[n-1].width) > width) {
                                  block[n-1] = copyTextElement(block[n-1]);
                              }
                              while((x + block[n-1].width) > width) {
                                  var tail = splitLine(block[n-1],width-x);
                                  x = x + block[n-1].width;
                                  if(first!=n && block[first].justify[0]!='BEGIN') {
                                      var delta = width - x;
                                      if(block[first].justify[0]=='MIDDLE') {
                                          delta = delta / 2;
                                      }
                                      if(delta > 0) {
                                          for(j=first;j<n;j++) {
                                              block[j].position[0] += delta;    
                                          }
                                      }
                                  }
  
                                  //x = 0;
                                  x = nesting;
                                  y = y - tail.height;
                                  tail.position[0] = x; 
                                  tail.position[1] = y; 
                                  block[n] = tail;
                                  first = n;
                                  n = n + 1;
                              }
                          }
                          x = x + block[n-1].width;
                      }
                  } //?
  
                  if(first!=n && block[first].justify[0]!='BEGIN') {
                      var delta = width - x;
                      if(block[first].justify[0]=='MIDDLE') {
                          delta = delta / 2;
                      }
                      if(delta > 0) {
                          for(j=first;j<n;j++) {
                              block[j].position[0] += delta;    
                          }
                      }
                  }
  
                  groupNode.children = block;
              }
  
  
              function getNodesForLevel(level) {
                  var block = new MFNode();
                  var i = 0;
                  var n = 0;
                  for(i=0;i= level) ) {
                          if(elements[i].elementType == 'BLOCKELEMENT' ) {
                              elements[i].showLevel = level;
                              block[n]              = elements[i];
                          } else {
                              block[n] = elements[i];
                          }
                          n = n + 1;
                      }
                  }
                  return block;
              }
  

copy elements


              function copyTextElement(line) {
                  var copy = Browser.createVrmlFromString(' TextElement { bgTransparency '+ line.bgTransparency + ' bgColor ' + line.bgColor + ' } ');
                  copy[0].height         = line.height;
                  copy[0].linebreak      = line.linebreak;
                  copy[0].nochange      = line.nochange;
                  copy[0].color          = line.color;
                  copy[0].alpha          = line.alpha;
                  copy[0].justify        = line.justify;
                  copy[0].family         = line.family;
                  copy[0].style          = line.style;
                  copy[0].position       = line.position; 
                  copy[0].width          = line.width;
                  copy[0].string[0]      = line.string[0];
                  return copy[0];
              }
              function splitLine(line,maxWidth) {
                 if (line.nochange) return line;
  //                print('input char= '+line.string[0].length+'  width= '+line.width+'    '+line.string[0]);
  //                print('Should be splitting now...');
                  var tail = Browser.createVrmlFromString(' TextElement { bgTransparency '+ line.bgTransparency + ' bgColor ' + line.bgColor + ' } ');
  //                tail[0].bgTransparency = line.bgTransparency;
  //                tail[0].bgColor        = line.bgColor;
                  tail[0].height         = line.height;
                  tail[0].linebreak      = line.linebreak;
                  tail[0].color          = line.color;
                  tail[0].justify        = line.justify;
                  tail[0].family         = line.family;
                  tail[0].style          = line.style;
  
                  var fraction      = maxWidth/line.width;
                  var characters    = Math.floor(fraction*line.string[0].length);
  
                  characters = characters + 3;
                  while(line.string[0].charAt(characters) != ' ' &&
                        characters > 0) characters--;
  
                  fraction          = characters/line.string[0].length;
                  tail[0].width     = line.width - fraction * line.width;
                  line.width        = line.width - tail[0].width;
                  tail[0].string[0] = 
                      line.string[0].substring(characters+1,
                                               line.string[0].length);
                  line.string[0]    = line.string[0].substring(0,characters+1);
  
  //                print('characters = '+characters);
  //                print('line char= '+line.string[0].length+'  width= '+line.width+'     ' + line.string[0]);
  //                print('tail char= '+tail[0].string[0].length+'  width= '+tail[0].width+'    ' + tail[0].string[0]);
                  return tail[0];
              }
          "
      }
  }
  
  


(C) A. Eliëns 21/5/2007

You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.