JSON

ÐéÄâÏÖʵ(VR)Ä£Äâ·ÂÕæÐÐÒµ×ÊѶ µÚÈýά¶È(2)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2016-01-20 18:00 ÎÒÒªÆÀÂÛ( )

42vPosition ÈÃÎÒÃÇÔÙÀ´¿´¿´Rm¡£ÕâÀïÔ­±¾Ó¦¸ÃÊǺÜÂé·³µÄ£¬µ«ÐÒºÃÎÒÃÇÓÐÒ»¸öGLSLº¯Êýreflect£¬Õâ¾Í·½±ã¶àÁË¡£Õâ¸öº¯ÊýÊÇÕâÑù¶¨ÒåµÄ£º reflect (I, N) ÆäÖÐIÊÇÈëÉäÏòÁ¿£¬NÊÇÎïÌå±íÃ泯Ïò£¬º¯Êý·µ»ØÖµÊÇ·´Éä·½Ïò¡£ Èë

42 vPosition

    ÈÃÎÒÃÇÔÙÀ´¿´¿´Rm¡£ÕâÀïÔ­±¾Ó¦¸ÃÊǺÜÂé·³µÄ£¬µ«ÐÒºÃÎÒÃÇÓÐÒ»¸öGLSLº¯Êýreflect£¬Õâ¾Í·½±ã¶àÁË¡£Õâ¸öº¯ÊýÊÇÕâÑù¶¨ÒåµÄ£º

    reflect (I, N)

    ÆäÖÐIÊÇÈëÉäÏòÁ¿£¬NÊÇÎïÌå±íÃ泯Ïò£¬º¯Êý·µ»ØÖµÊÇ·´Éä·½Ïò¡£

    ÈëÉäÏòÁ¿¾ÍÊǹâÏßÕÕÔÚÎïÌå±íÃæÉϵÄÈëÉä·½Ïò£¬Ò²¾ÍÊÇ´ÓƬԪµ½¹âÏߵķ½ÏòµÄ·´·½Ïò£¬¶øƬԪµ½¹âÏߵķ½ÏòÎÒÃÇÒѾ­ÓÐÁË£¬´¢´æÔÚlightDirectionÖС£N£¬Ò²¾ÍÊÇÎïÌå±íÃ泯Ïò£¬Êµ¼ÊÉϾÍÊÇ·¨Ïߣ¬ÎÒÃÇÒ²ÒѾ­¼ÆËã³öÁË¡£ÕâÑù£¬ÎÒÃǾͿÉÒÔºÜÇáËɵļÆËã³ö·´Éä·½Ïò¡£

43 lightDirection, normal);

    ºÃÁË£¬Íòʾ㱸£¬×îºóÒ»²½·Ç³£¼òµ¥¡£

45 46 specularLightWeighting reflectionDirectionuMaterialShininess

    ÒÔÉϾÍÊÇÎÒÃÇÈçºÎ¼ÆËã¾µÃæ·´Éä¹±Ï×µÄÁÁ¶È£¬È»ºóÎÒÃÇÔÙÀ´¿´¿´Âþ·¢Éä¹±Ï×µÄÁÁ¶È¡£ÎÒÃÇ»¹ÊÇÓÃ֮ǰµÄÂß¼­£¨ÕâÀïÎÒÃÇÓñ¾µØ±äÁ¿À´´¢´æ¹éÒ»»¯µÄ·¨ÏßÏòÁ¿£©¡£

48 normal

    ×îºó£¬ÎÒÃǽ«¾µÃæ·´ÉäµÄÁÁ¶È¡¢Âþ·´ÉäµÄÁÁ¶ÈºÍ»·¾³¹âµÄÑÕÉ«½áºÏÆðÀ´£¬¼ÆËã³öƬԪµÄ×ÜÁÁ¶È¡£¼ÆËã·½·¨ÊÇÎÒÃÇ֮ǰʹÓõķ½·¨µÄÀ©Õ¹¡£

49 50 51 52 lightWeighting = uAmbientColor + uPointLightingSpecularColor * specularLightWeighting + uPointLightingDiffuseColor * diffuseLightWeighting; }

    Íê³ÉÁËÒÔÉϹ¤×÷£¬ÎÒÃǾͿÉÒÔʹÓÃÓëµÚ13¿ÎÖÐÍêÈ«ÏàͬµÄ´úÂëÀ´¼ÆË㣬»ùÓÚµ±Ç°ÎÆÀí£¬Ã¿¸öƬԪµÄÑÕÉ«¡£

54 55 56 57 58 59 60 61 uUseTextures) { fragmentColor uSamplervTextureCoordvTextureCoordfragmentColor fragmentColorlightWeighting

    µ½ÕâÀƬԪ×ÅÉ«Æ÷¾Í¹¤×÷Íê±Ï¡£

    ÔÙÍùÏ¿´¿´£¬Äã»á·¢ÏÖÏÂÒ»¸öÓëµÚ13¿Î²»Í¬µÄµØ·½£¬Î»ÓÚinitShadersº¯ÊýÖУ¬Õâ¸öº¯ÊýÓֻص½Á˸üÔç֮ǰµÄÀÏÑù×Ó£¬·Ç³£¼òµ¥¡£ÆäÖÐÖ»´´½¨ÁËÒ»¸öprogram£¬È»ºóÀíËùµ±È»µÄ£¬ÎªÐÂÔö¼ÓµÄ¾µÃæ¸ß¹â³õʼ»¯ÁËÒ»Á½¸öеÄuniformµØÖ·¡£ÔÙÍùÏÂÒ»µã£¬initTexturesº¯ÊýÔØÈëÁ˵ØÇòÎÆÀíºÍµç¶Æ½ðÊôÎÆÀí£¬¶ø²»ÊÇʲôÔÂÇòºÍľÖʵİåÌõÏäÁË¡£ÔÙÍùÏ£¬ÔÚsetMatrixUniformsº¯ÊýÖУ¬ºÍinitShadersÒ»Ñù£¬Óֻص½µÄÔ­À´µÄÑù×Ó£¬Ö»Éæ¼°µ½Ò»¸öprogram£¬¶ø²»ÊǶà¸ö¡£ÔÙÍùÏ£¬ÎÒÃǾ͵½Á˱¾½Ú¿ÎÖÐÁíÒ»¸ö±È½ÏÓÐȤµÄµØ·½ÁË¡£

    ÎÒÃDz»ÔÙʹÓÃinitBuffersº¯ÊýÀ´´´½¨°üº¬²»Í¬µÄ¶¥µãÊôÐÔÓÃÓÚ¶¨Òå²èºøÍâ¹ÛµÄWebGLÊý×é¶ÔÏóÁË£¬ÎÒÃÇÓÐÁËÁ½¸öÐÂÅóÓÑ£¬handleLoadedTeapotºÍloadTeapotº¯Êý¡£´úÂëµÄģʽ¿´ÆðÀ´ºÜÏñµÚ10¿ÎÖÐÔØÈëÊÀ½çµÄ´úÂ룬µ«ÊÇ»¹ÊÇÖµµÃÔÙÖØп´Ò»±éµÄ¡£ÈÃÎÒÃÇÏÈÀ´¿´¿´loadTeapotº¯Êý£¨ËäÈ»ÔÚ´úÂëÖÐËüÊÇÆäÖеڶþ¸öº¯Êý£©¡£

284 285 286 287 288 289 290 291 292 293 request request.request.request.handleLoadedTeapotrequest.

    ´úÂëµÄ×ÜÌå½á¹¹¿´ÆðÀ´ºÍµÚ10¿ÎºÜÏñ£¬ÎÒÃÇ´´½¨ÁËÒ»¸öеÄXMLHttpRequest¶ÔÏó£¬È»ºóÓÃËüÀ´ÔØÈëTeapot.jsonÎļþ¡£ÒòΪÊÇÒì²½¼ÓÔØ£¬ËùÒÔÎÒÃÇ»¹¼ÓÈëÁËÒ»¸ö»Øµ÷º¯Êý£¬Ëü»áÔÚÔØÈëÎļþ¹ý³ÌÖеIJ»Í¬½×¶Î±»´¥·¢£¬È»ºóµ±readyStateµÈÓÚ4ʱ£¬Ò²¾ÍÊÇ˵Îļþ±»ÍêÈ«ÔØÈëÁË£¬ÎÒÃÇ×öÒ»ÏÂÏàÓ¦µÄ´¦Àí¡£

    ½ÓÏÂÀ´·¢ÉúµÄÊÂÇé·Ç³£ÓÐÒâ˼¡£ÎÒÃÇÔØÈëµÄÎļþÊÇJSON¸ñʽµÄ£¬»ù±¾ÉÏÒ²¾ÍÊÇ˵£¬ËüÊÇÒѾ­ÓÃJavascriptдºÃµÄ£¬´ò¿ªÕâ¸öÎļþ¿´¿´Äã¾ÍÃ÷°×ÎÒ˵µÄÒâ˼ÁË¡£ÎļþÃèÊöÁËÒ»¸öJavascript¶ÔÏó£¬ÆäÖеÄÁÐ±í´¢´æÁË×é³É²èºøËùÐèµÄ¶¥µãλÖᢷ¨Ïß¡¢ÎÆÀí×ø±êºÍ¶¥µãË÷Òý¡£ÎÒÃǵ±È»¿ÉÒÔ½«ÕâЩ´úÂëÖ±½Óдµ½index.htmlÀïÃ棬µ«Êǵ±Äã¹¹½¨¸ü¸´ÔÓµÄÄ£ÐÍʱ£¬ÓÈÆäÊÇÓɲ»Í¬µÄ¶ÀÁ¢Ä£Ð͵ÄÎïÌå×é³ÉµÄ£¬Äã×îºÃ»¹ÊÇ°ÑËüÃǶ¼·Åµ½Ò»¸öµ¥¶ÀµÄÎļþÖС£

    ÖÁÓÚ¾ßÌåʹÓÃʲôÑùµÄ¸ñʽÀ´´¢´æÄ£ÐÍ£¬ÕâÊǸöºÜÖµµÃ̽ÌÖµÄÎÊÌâ¡£Äã¿ÉÒÔÔÚÈκÎÄãϲ»¶µÄÈí¼þÖн¨Ä££¬ÕâЩÈí¼þ¿ÉÒÔ½«Ä£Ð͵¼³öΪ²»Í¬µÄ¸ñʽ£¬±ÈÈç3DsMaxÖеÄ.objÎļþ¡£ÔÚδÀ´£¬Ò²ÐíһЩÈí¼þÄܹ»½«Ä£Ð͵¼³öΪÔÚJavascriptÖпÉÒÔÖ±½ÓʹÓõĸñʽ£¬¾ÍºÃÏñÎÒÃÇÕâ½Ú¿ÎÖÐÓÃÀ´´¢´æ²èºøÄ£Ð͵ÄJSONÎļþ¡£ÄÇÏÂÃ棬ÄãÓ¦µ±½«±¾½Ì³Ì½ö½ö×÷Ϊһ¸öʾÀý£¬Õ¹Ê¾ÁËÈçºÎÔØÈëÒ»¸öÔ¤ÏÈÉè¼ÆºÃµÄJSONÄ£ÐÍÎļþ£¬¶ø²»ÊÇÒ»¸ö×îºÃµÄµä·¶¡£

250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 teapotVertexTextureCoordBuffer; var teapotVertexIndexBuffer;   function handleLoadedTeapot(teapotData) { teapotVertexNormalBuffer gl.teapotVertexNormalBuffer); gl.Float32Arraygl.teapotVertexNormalBuffer.teapotVertexNormalBuffer.  teapotVertexTextureCoordBuffer gl.teapotVertexTextureCoordBuffer); gl.Float32Arraygl.teapotVertexTextureCoordBuffer.teapotVertexTextureCoordBuffer.  teapotVertexPositionBuffer gl.teapotVertexPositionBuffer); gl.Float32Arraygl.teapotVertexPositionBuffer.teapotVertexPositionBuffer.  teapotVertexIndexBuffer gl.teapotVertexIndexBuffer); gl.Uint16Arraygl.teapotVertexIndexBuffer.teapotVertexIndexBuffer.  document..

    ÕâЩ´úÂëÀïʵÔÚÊÇûÓÐʲôºÃÇ¿µ÷µÄ¶«Î÷¡£¾ÍÊÇ´ÓÔØÈëµÄJSON¶ÔÏóÖÐÌáÈ¡²»Í¬µÄÁÐ±í£¬È»ºó·Åµ½WebGLµÄÊý×é¶ÔÏóÖУ¬È»ºóÍÆË͵½ÏÔ¿¨¶Ë¡£ÔÚÕâÖ®ºó£¬ÎÒÃÇÇå¿ÕÁËHTMLÖеÄdiv±êÇ©£¬ºÍµÚ10¿ÎÒ»Ñù£¬ËüÓÃÀ´¸æËßÓû§Ä£ÐÍÕýÔÚÔØÈëÖС£

    ºÃÁË£¬Ä£ÐÍÔØÈëÍê±ÏÁË£¬»¹ÓÐʲôҪ˵µÄÂºÃ°É£¬»¹ÓÐdrawSceneº¯Êý¡£ÔÚÈ·ÈÏÄ£ÐÍÒѾ­ÔØÈëÖ®ºó£¬ÎÒÃÇÒªÔÚÒ»¸öºÏÊʵĽǶÈÀ´»æÖƲèºø£¬ÕâÀïûʲôж«Î÷¡£¿´Ò»Ï´úÂ룬ȷÈÏÄãÖªµÀÆäÖз¢ÉúÁËʲô£¨Èç¹ûÓÐÈκβ»Ã÷°×µÄµØ·½£¬ÇëÁôÏÂÆÀÂÛ£©£¬²»¹ýÎÒÏëÄãÓ¦¸ÃÕÒ²»³öʲôÈÃÄã³Ô¾ªµÄµØ·½¡£

    ÕâÖ®ºó£¬animateº¯ÊýÀïÒ²ÓÐһЩËöËéµÄ¸Ä±ä£¬ÓÃÀ´ÈòèºøÐýת¶ø²»ÊÇʲôÔÂÁÁºÍÏä×Ó£»webGLStartº¯Êýµ÷ÓÃÁËloadTeapot¶ø²»ÊÇinitBuffers¡£×îºó£¬µ±ÔØÈëÄ£ÐÍʱ£¬HTMLÀïµÄdiv±êÇ©ÖлáÏÔʾ¡°Loading world¡­¡±£¬»¹ÓÐÏàÓ¦µÄCSSÑùʽ¡£µ±È»£¬»¹ÐÂÔö¼ÓÁËÒ»¸öÎı¾ÓòÓÃÀ´ÊäÈëеľµÃæ¸ß¹âµÄÏà¹Ø²ÎÊýµÄ¡£

    ºÃÁË£¬±¾½Ú¿Îµ½ÕâÀï¾Í½áÊøÁË¡£Äãѧ»áÁËÈçºÎʵÏÖ¾µÃæ¸ß¹â£¬ÈçºÎÔØÈëÒ»¸ö´¢´æÔÚJSONÎļþÖÐÔ¤ÏÈÖÆ×÷ºÃµÄÄ£ÐÍ¡£Ï½ڿÎÎÒÃǽ«»áѧϰһ¸öÉÔ΢Óеã¸ß¶ËµÄ¶«Î÷£¬ÕâÊÇÒ»ÖÖ²»Í¬µÄ¡¢¸ü¼ÓÓÐȤµÄʹÓÃÎÆÀíµÄ·½Ê½¡ª¡ª¸ß¹âÌùͼ¡£

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • WebGL½Ì³Ì£ºµÚ14¿Î£¬¾µÃæ¸ß¹âºÍÔØÈëJSONÄ£ÐÍ

    WebGL½Ì³Ì£ºµÚ14¿Î£¬¾µÃæ¸ß¹âºÍÔØÈëJSONÄ£ÐÍ

    2015-10-03 14:05

ÍøÓѵãÆÀ
Ï