[Index for tmp_for_tar/vrml.doc] [Return to Master Index]

vrml_faces

(tmp_for_tar/vrml.doc/vrml_faces.m)


Function Synopsis

s = vrml_faces(x,f,...)

Help text

 s = vrml_faces(x,f,...)

 x : 3xP   : The 3D points
 f : 3xQ   : The indexes of the points forming the faces. Indexes
             should have values in 1:P.

 Returns a Shape -> IndexedFaceSet vrml node.

 No check is done on anything

 Options :

 "col" , col  : 3   : Color,                      default = [0.3,0.4,0.9]
             or 3xP : color of vertices (vrml colorPerVertex is TRUE).

 "tran", tran : 1x1 : Transparency,                           default = 0

 "creaseAngle", a 
              :  1  : vrml creaseAngle value. The browser may smoothe the
                      crease between facets whose angle is less than a.
                                                              default = 0
 "tex", texfile 
              : string : File containing texture.          default : none

 "imsz", sz   : 2   : Size of texture image 
                                       default is determined by imginfo()

 "tcoord", tcoord
              : 2x3Q : Coordinates of vertices in texture image. Each 2x3
                       block contains coords of one facet's corners. The
                       coordinates should be in [0,1], as in a VRML
                       TextureCoordinate node.
                                       default assumes faces are returned
                                       by extex()

 "smooth"           : same as "creaseAngle",pi.

 Last modified: December 2000



Cross-Reference Information

This function calls
This function is called by

Listing of function file tmp_for_tar/vrml.doc/vrml_faces.m

## s = vrml_faces(x,f,...)
##
## x : 3xP   : The 3D points
## f : 3xQ   : The indexes of the points forming the faces. Indexes
##             should have values in 1:P.
##
## Returns a Shape -> IndexedFaceSet vrml node.
##
## No check is done on anything
##
## Options :
## 
## "col" , col  : 3   : Color,                      default = [0.3,0.4,0.9]
##             or 3xP : color of vertices (vrml colorPerVertex is TRUE).
## 
## "tran", tran : 1x1 : Transparency,                           default = 0
##
## "creaseAngle", a 
##              :  1  : vrml creaseAngle value. The browser may smoothe the
##                      crease between facets whose angle is less than a.
##                                                              default = 0
## "tex", texfile 
##              : string : File containing texture.          default : none
##
## "imsz", sz   : 2   : Size of texture image 
##                                       default is determined by imginfo()
##
## "tcoord", tcoord
##              : 2x3Q : Coordinates of vertices in texture image. Each 2x3
##                       block contains coords of one facet's corners. The
##                       coordinates should be in [0,1], as in a VRML
##                       TextureCoordinate node.
##                                       default assumes faces are returned
##                                       by extex()
##
## "smooth"           : same as "creaseAngle",pi.

## Author:        Etienne Grossmann  <etienne@isr.ist.utl.pt>
## Last modified: December 2000

function s = vrml_faces(x,f,...)
tran = 0 ;
col = [0.3, 0.4, 0.9] ;
tcoord = imsz = tex = smooth = creaseAngle = nan ;


opt1 = " tex imsz tcoord tran col creaseAngle " ;
opt0 = " smooth " ;

verbose = 0 ;

nargin -= 2 ;
while nargin>0 ,
  tmp = va_arg() ; nargin-- ;
  if ! isstr(tmp) ,
    printf("vrml_faces : Non-string option : \n") ;
    keyboard

  end
  if index(opt1,[" ",tmp," "]) ,
    
    tmp2 = va_arg() ; nargin-- ;
    ## nargin-- ;
    eval([tmp,"=tmp2;"]) ;

    sayif(verbose ,"vrml_faces : Read option : %s.\n",tmp) ;

  elseif index(opt0,[" ",tmp," "]) ,
    
    eval([tmp,"=1;"]) ;
    sayif(verbose ,"vrml_faces : Read boolean option : %s\n",tmp) ;

  else
    printf("vrml_faces : Unknown option : %s\n",tmp) ;
    keyboard
  end
endwhile

if ! isnan (smooth), creaseAngle = pi ; end

## printf ("creaseAngle = %8.3f\n",creaseAngle);

## if exist("col")!=1,  col = [0.5, 0.5, 0.8]; end
				# col_str_1 is the appearance node
				# col_str_2 goes in the geometry node

if isstr (tex),			# Assume triangles

  ## printf ("Using texture\n");

#    if isnan (imsz),
#      tmpim = ims_load (tex);
#      imsz = ims_size (tmpim);
#      printf ("found image size : %i x %i\n",imsz);
#    end

  col_str_1 = sprintf (["  appearance Appearance {\n",...
			"    texture ImageTexture {\n",...
			"      url "%s"\n",...
			"    }\n",...
			"  }\n"],...
		       tex);
  nt = columns (f);		# n of triangles

				# Eventually determine size of image
  if isnan(imsz), imsz = imginfo (tex); end

  if isnan (tcoord),

    nb = ceil (nt/2);		# n of blocks
    lo = [0:nb-1]/nb; hi = [1:nb]/nb;
    on = ones (1,nb); ze = zeros (1,nb);
    
    sm = (1/nb) /(imsz(2)+1);	
    tcoord = [lo; on; lo; ze; hi-sm; ze;  lo+sm; on; hi-sm; on; hi-sm; ze];
    tcoord = reshape (tcoord, 2, 6*nb);
    tcoord = tcoord (:,1:3*nt);
  end

  col_str_2 = sprintf (["  texCoord TextureCoordinate {\n",\
			"    point [\n      %s]\n",\
			"  }\n",\
			"  texCoordIndex [\n      %s]\n",\
			"  coordIndex [\n      %s]\n",\
			],\
		       sprintf ("%10.8f %10.8f,\n      ",tcoord),\
		       sprintf ("%-4d, %-4d, %-4d, -1,\n     ",0:3*nt-1),\
		       sprintf ("%-4d, %-4d, %-4d, -1,\n     ",f-1)
		       );
				
  
elseif prod (size (col))==3,
  col_str_1 = sprintf (["  appearance Appearance {\n",...
			"    material Material {\n",...
			"      diffuseColor %8.3f %8.3f %8.3f \n",...
			"      transparency %8.3f\n",...
			"    }\n",...
			"  }\n"],...
		       col,tran);
##		       col,col,tran);
##			"      emissiveColor %8.3f %8.3f %8.3f\n",...

  col_str_2 = "";
else
  ##  col_str_1 = sprintf(["  appearance Appearance {\n",...
  ##  		       "    material Material {\n",...
  ##  		       "      diffuseColor  0.3 0.4 0.9\n",...
  ##  		       "      emissiveColor  0.9 0.4 0.1\n",...
  ##  		       "    }\n",...
  ##  		       "  }\n"]);
  col_str_1 = "";
  col_str_2 = sprintf (["     colorPerVertex TRUE\n",...
			"     color Color {\n",...
			"       color [\n%s\n",...
			"       ]\n",...
			"     }"],...
                       sprintf("         %8.3f %8.3f %8.3f,\n",col)) ;
end
		     
etc_str = "" ;
if ! isnan (creaseAngle),
  etc_str = [etc_str, sprintf ("    creaseAngle    %8.3f\n",creaseAngle)];
end


s = sprintf([... 			# string of indexed face set
	     "Shape {\n",...
	     col_str_1,...
	     "  geometry IndexedFaceSet {\n",...
	     "    solid FALSE     # Show back of faces too\n",...
	     col_str_2,...
	     etc_str,...
	     "    coordIndex [\n%s]\n",...
	     "    coord Coordinate {\n",...
	     "      point [\n%s]\n",...
	     "    }\n",...
	     "  }\n",...
	     "}\n",...
	     ],...
	    sprintf("                    %4d, %4d, %4d, -1,\n",f-1),...
	    sprintf("                 %8.3f %8.3f %8.3f,\n",x)) ;



Produced by oct2html on Sat Dec 2 19:08:39 2000
Cross-Directory links are: ON