Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
98711f49
T
three.js
项目概览
Ablesons
/
three.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
three.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
98711f49
编写于
5月 06, 2014
作者:
M
Mu Daosheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support tga format texture
上级
8e7fdff1
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
1160 addition
and
209 deletion
+1160
-209
build/three.js
build/three.js
+472
-1
build/three.min.js
build/three.min.js
+214
-207
examples/textures/crate_color8.tga
examples/textures/crate_color8.tga
+0
-0
examples/textures/crate_grey8.tga
examples/textures/crate_grey8.tga
+0
-0
src/extras/ImageUtils.js
src/extras/ImageUtils.js
+448
-0
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+5
-1
src/textures/TGATexture.js
src/textures/TGATexture.js
+19
-0
utils/build/includes/common.json
utils/build/includes/common.json
+1
-0
utils/build/includes/webgl.json
utils/build/includes/webgl.json
+1
-0
未找到文件。
build/three.js
浏览文件 @
98711f49
...
...
@@ -14275,6 +14275,25 @@ THREE.CompressedTexture.prototype.clone = function () {
};
/**
* @author Daosheng Mu / https://github.com/DaoshengMu/
*/
THREE.TGATexture = function ( format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
};
THREE.TGATexture.prototype = Object.create( THREE.Texture.prototype );
THREE.TGATexture.prototype.clone = function() {
var texture = new THREE.TGATexture();
THREE.Texture.prototype.clone.all( this. texture );
return texture;
};
/**
* @author alteredq / http://alteredqualia.com/
*/
...
...
@@ -25157,6 +25176,10 @@ THREE.WebGLRenderer = function ( parameters ) {
}
} else if ( texture instanceof THREE.TGATexture ) {
var tgaImg = texture.image;
_gl.texImage2D( _gl.TEXTURE_2D, 0, glFormat, tgaImg.width, tgaImg.height, 0, glFormat, glType, tgaImg.data );
} else { // regular Texture (image, video, canvas)
// use manually created mipmaps if available
...
...
@@ -26660,6 +26683,7 @@ THREE.GeometryUtils = {
/**
* @author alteredq / http://alteredqualia.com/
* @author mrdoob / http://mrdoob.com/
* @author Daosheng Mu / https://github.com/DaoshengMu/
*/
THREE.ImageUtils = {
...
...
@@ -26890,6 +26914,453 @@ THREE.ImageUtils = {
},
// reference from vthibault, https://github.com/vthibault/roBrowser/blob/master/src/Loaders/Targa.js
decodeTGA: function ( arrayBuffer ) {
// TGA Constants
var TGA_TYPE_NO_DATA = 0,
TGA_TYPE_INDEXED = 1,
TGA_TYPE_RGB = 2,
TGA_TYPE_GREY = 3,
TGA_TYPE_RLE_INDEXED = 9,
TGA_TYPE_RLE_RGB = 10,
TGA_TYPE_RLE_GREY = 11,
TGA_ORIGIN_MASK = 0x30,
TGA_ORIGIN_SHIFT = 0x04,
TGA_ORIGIN_BL = 0x00,
TGA_ORIGIN_BR = 0x01,
TGA_ORIGIN_UL = 0x02,
TGA_ORIGIN_UR = 0x03;
if ( arrayBuffer.length < 19 )
console.error( 'ImageUtils::decodeTGA()- Not enough data to contain header.' );
var content = new Uint8Array( arrayBuffer ),
offset = 0,
header = {
id_length: content[ offset++ ],
colormap_type: content[ offset++ ],
image_type: content[offset++],
colormap_index: content[offset++] | content[offset++] << 8,
colormap_length: content[offset++] | content[offset++] << 8,
colormap_size: content[offset++],
origin: [
content[offset++] | content[offset++] << 8,
content[offset++] | content[offset++] << 8
],
width: content[offset++] | content[offset++] << 8,
height: content[offset++] | content[offset++] << 8,
pixel_size: content[offset++],
flags: content[offset++]
};
function tgaCheckHeader( header ) {
switch( header.image_type ) {
// Check indexed type
case TGA_TYPE_INDEXED:
case TGA_TYPE_RLE_INDEXED:
if ( header.colormap_length > 256 || header.colormap_size !== 24 || header.colormap_type !== 1) {
console.error('Targa::tgaCheckHeader() - Invalid type colormap data for indexed type');
}
break;
// Check colormap type
case TGA_TYPE_RGB:
case TGA_TYPE_GREY:
case TGA_TYPE_RLE_RGB:
case TGA_TYPE_RLE_GREY:
if (header.colormap_type) {
console.error('ImageUtils::tgaCheckHeader() - Invalid type colormap data for colormap type');
}
break;
// What the need of a file without data ?
case TGA_TYPE_NO_DATA:
console.error('ImageUtils::tgaCheckHeader() - No data');
// Invalid type ?
default:
console.error('ImageUtils::tgaCheckHeader() - Invalid type " '+ header.image_type + '"');
}
// Check image width and height
if ( header.width <= 0 || header.height <=0 ) {
console.error( 'ImageUtils::tgaCheckHeader() - Invalid image size' );
}
// Check image pixel size
if (header.pixel_size !== 8 &&
header.pixel_size !== 16 &&
header.pixel_size !== 24 &&
header.pixel_size !== 32) {
console.error('ImageUtils::tgaCheckHeader() - Invalid pixel size "' + header.pixel_size + '"');
}
}
// Check tga if it is valid format
tgaCheckHeader( header );
if ( header.id_length + offset > arrayBuffer.length ) {
console.error('ImageUtils::load() - No data');
}
// Skip the needn't data
offset += header.id_length;
// Get targa information about RLE compression and palette
var use_rle = false,
use_pal = false,
use_grey = false;
switch ( header.image_type ) {
case TGA_TYPE_RLE_INDEXED:
use_rle = true;
use_pal = true;
break;
case TGA_TYPE_INDEXED:
use_pal = true;
break;
case TGA_TYPE_RLE_RGB:
use_rle = true;
break;
case TGA_TYPE_RGB:
break;
case TGA_TYPE_RLE_GREY:
use_rle = true;
use_grey = true;
break;
case TGA_TYPE_GREY:
use_grey = true;
break;
}
// Parse tga image buffer
function tgaParse( use_rle, use_pal, header, offset, data ) {
var pixel_data,
pixel_size,
pixel_total,
palettes;
pixel_size = header.pixel_size >> 3;
pixel_total = header.width * header.height * pixel_size;
// Read palettes
if ( use_pal ) {
palettes = data.subarray( offset, offset += header.colormap_length * 3 );
}
// Read RLE
if ( use_rle ) {
pixel_data = new Uint8Array(pixel_total);
var c, count, i;
var shift = 0;
var pixels = new Uint8Array(pixel_size);
while (shift < pixel_total) {
c = data[offset++];
count = (c & 0x7f) + 1;
// RLE pixels.
if (c & 0x80) {
// Bind pixel tmp array
for (i = 0; i < pixel_size; ++i) {
pixels[i] = data[offset++];
}
// Copy pixel array
for (i = 0; i < count; ++i) {
pixel_data.set(pixels, shift + i * pixel_size);
}
shift += pixel_size * count;
}
// Raw pixels.
else {
count *= pixel_size;
for (i = 0; i < count; ++i) {
pixel_data[shift + i] = data[offset++];
}
shift += count;
}
}
}
// RAW Pixels
else {
pixel_data = data.subarray(
offset, offset += (use_pal ? header.width * header.height : pixel_total)
);
}
return {
pixel_data: pixel_data,
palettes: palettes
};
}
function tgaGetImageData8bits(imageData, y_start, y_step, y_end, x_start, x_step, x_end
, image, palettes ) {
var colormap = palettes;
var color, i = 0, x, y;
var width = header.width;
for (y = y_start; y !== y_end; y += y_step) {
for (x = x_start; x !== x_end; x += x_step, i++) {
color = image[i];
imageData[(x + width * y) * 4 + 3] = 255;
imageData[(x + width * y) * 4 + 2] = colormap[(color * 3) + 0];
imageData[(x + width * y) * 4 + 1] = colormap[(color * 3) + 1];
imageData[(x + width * y) * 4 + 0] = colormap[(color * 3) + 2];
}
}
return imageData;
};
function tgaGetImageData16bits(imageData, y_start, y_step, y_end, x_start, x_step, x_end
, image) {
var color, i = 0, x, y;
var width = header.width;
for (y = y_start; y !== y_end; y += y_step) {
for (x = x_start; x !== x_end; x += x_step, i += 2) {
color = image[i + 0] + (image[i + 1] << 8); // Inversed ?
imageData[(x + width * y) * 4 + 0] = (color & 0x7C00) >> 7;
imageData[(x + width * y) * 4 + 1] = (color & 0x03E0) >> 2;
imageData[(x + width * y) * 4 + 2] = (color & 0x001F) >> 3;
imageData[(x + width * y) * 4 + 3] = (color & 0x8000) ? 0 : 255;
}
}
return imageData;
};
function tgaGetImageData24bits(imageData, y_start, y_step, y_end, x_start, x_step, x_end, image) {
var i = 0, x, y;
var width = header.width;
for (y = y_start; y !== y_end; y += y_step) {
for (x = x_start; x !== x_end; x += x_step, i += 3) {
imageData[(x + width * y) * 4 + 3] = 255;
imageData[(x + width * y) * 4 + 2] = image[i + 0];
imageData[(x + width * y) * 4 + 1] = image[i + 1];
imageData[(x + width * y) * 4 + 0] = image[i + 2];
}
}
return imageData;
};
function tgaGetImageData32bits(imageData, y_start, y_step, y_end, x_start, x_step, x_end, image) {
var i = 0, x, y;
var width = header.width;
for (y = y_start; y !== y_end; y += y_step) {
for (x = x_start; x !== x_end; x += x_step, i += 4) {
imageData[(x + width * y) * 4 + 2] = image[i + 0];
imageData[(x + width * y) * 4 + 1] = image[i + 1];
imageData[(x + width * y) * 4 + 0] = image[i + 2];
imageData[(x + width * y) * 4 + 3] = image[i + 3];
}
}
return imageData;
};
function tgaGetImageDataGrey8bits( imageData, y_start, y_step, y_end, x_start, x_step, x_end, image ) {
var color, i = 0, x, y;
var width = header.width;
for (y = y_start; y !== y_end; y += y_step) {
for (x = x_start; x !== x_end; x += x_step, i++) {
color = image[i];
imageData[(x + width * y) * 4 + 0] = color;
imageData[(x + width * y) * 4 + 1] = color;
imageData[(x + width * y) * 4 + 2] = color;
imageData[(x + width * y) * 4 + 3] = 255;
}
}
return imageData;
};
function tgaGetImageDataGrey16bits(imageData, y_start, y_step, y_end, x_start, x_step, x_end, image) {
var i = 0, x, y;
var width = header.width;
for (y = y_start; y !== y_end; y += y_step) {
for (x = x_start; x !== x_end; x += x_step, i += 2) {
imageData[(x + width * y) * 4 + 0] = image[i + 0];
imageData[(x + width * y) * 4 + 1] = image[i + 0];
imageData[(x + width * y) * 4 + 2] = image[i + 0];
imageData[(x + width * y) * 4 + 3] = image[i + 1];
}
}
return imageData;
};
function getTgaRGBA( width, height, image, palette ) {
var x_start,
y_start,
x_step,
y_step,
x_end,
y_end,
data = new Uint8Array(width * height * 4);
switch( (header.flags & TGA_ORIGIN_MASK) >> TGA_ORIGIN_SHIFT ) {
default:
case TGA_ORIGIN_UL:
x_start = 0;
x_step = 1;
x_end = width;
y_start = 0;
y_step = 1;
y_end = height;
break;
case TGA_ORIGIN_BL:
x_start = 0;
x_step = 1;
x_end = width;
y_start = height - 1;
y_step = -1;
y_end = -1;
break;
case TGA_ORIGIN_UR:
x_start = width - 1;
x_step = -1;
x_end = -1;
y_start = 0;
y_step = 1;
y_end = height;
break;
case TGA_ORIGIN_BR:
x_start = width - 1;
x_step = -1;
x_end = -1;
y_start = height - 1;
y_step = -1;
y_end = -1;
break;
}
if ( use_grey ) {
switch( header.pixel_size )
{
case 8:
tgaGetImageDataGrey8bits( data, y_start, y_step, y_end, x_start, x_step, x_end, image );
break;
case 16:
tgaGetImageDataGrey16bits( data, y_start, y_step, y_end, x_start, x_step, x_end, image );
break;
default:
console.error( 'ImageUtils::getTgaRGBA() - not support this format' );
break;
}
}
else {
switch( header.pixel_size )
{
case 8:
tgaGetImageData8bits( data, y_start, y_step, y_end, x_start, x_step, x_end, image, palette );
break;
case 16:
tgaGetImageData16bits( data, y_start, y_step, y_end, x_start, x_step, x_end, image );
break;
case 24:
tgaGetImageData24bits( data, y_start, y_step, y_end, x_start, x_step, x_end, image );
break;
case 32:
tgaGetImageData32bits( data, y_start, y_step, y_end, x_start, x_step, x_end, image );
break;
default:
console.error( 'ImageUtils::getTgaRGBA() - not support this format' );
break;
}
}
// Load image data according to specific method
// var func = 'tgaGetImageData' + (use_grey ? 'Grey' : '') + (header.pixel_size) + 'bits';
//func(data, y_start, y_step, y_end, x_start, x_step, x_end, width, image, palette );
return data;
}
var result = tgaParse( use_rle, use_pal, header, offset, content );
var rgbaData = getTgaRGBA( header.width, header.height, result.pixel_data, result.palettes );
return {
width: header.width,
height: header.height,
data: rgbaData
};
},
loadTGATexture: function ( url, mapping, onLoad, onError ) {
var texture = new THREE.TGATexture();
{
var request = new XMLHttpRequest();
request.open( 'GET', url, true );
request.responseType = "arraybuffer";
request.onload = function() {
if ( this.status === 200 ) {
var imageData = THREE.ImageUtils.decodeTGA( this.response );
if ( imageData ) {
texture.image = imageData;
texture.sourceFile = url;
texture.needsUpdate = true;
return texture;
}
}
};
request.addEventListener( 'load', function ( event ) {
if ( onLoad ) onLoad( texture );
}, false );
request.addEventListener( 'error', function ( event ) {
if ( onError ) onError( event );
}, false );
request.send(null);
}
texture.sourceFile = url;
return texture;
},
loadDDSTexture: function ( url, mapping, onLoad, onError ) {
var images = [];
...
...
build/three.min.js
浏览文件 @
98711f49
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
examples/textures/crate_color8.tga
0 → 100644
浏览文件 @
98711f49
文件已添加
examples/textures/crate_grey8.tga
0 → 100644
浏览文件 @
98711f49
文件已添加
src/extras/ImageUtils.js
浏览文件 @
98711f49
/**
* @author alteredq / http://alteredqualia.com/
* @author mrdoob / http://mrdoob.com/
* @author Daosheng Mu / https://github.com/DaoshengMu/
*/
THREE
.
ImageUtils
=
{
...
...
@@ -231,6 +232,453 @@ THREE.ImageUtils = {
},
// reference from vthibault, https://github.com/vthibault/roBrowser/blob/master/src/Loaders/Targa.js
decodeTGA
:
function
(
arrayBuffer
)
{
// TGA Constants
var
TGA_TYPE_NO_DATA
=
0
,
TGA_TYPE_INDEXED
=
1
,
TGA_TYPE_RGB
=
2
,
TGA_TYPE_GREY
=
3
,
TGA_TYPE_RLE_INDEXED
=
9
,
TGA_TYPE_RLE_RGB
=
10
,
TGA_TYPE_RLE_GREY
=
11
,
TGA_ORIGIN_MASK
=
0x30
,
TGA_ORIGIN_SHIFT
=
0x04
,
TGA_ORIGIN_BL
=
0x00
,
TGA_ORIGIN_BR
=
0x01
,
TGA_ORIGIN_UL
=
0x02
,
TGA_ORIGIN_UR
=
0x03
;
if
(
arrayBuffer
.
length
<
19
)
console
.
error
(
'
ImageUtils::decodeTGA()- Not enough data to contain header.
'
);
var
content
=
new
Uint8Array
(
arrayBuffer
),
offset
=
0
,
header
=
{
id_length
:
content
[
offset
++
],
colormap_type
:
content
[
offset
++
],
image_type
:
content
[
offset
++
],
colormap_index
:
content
[
offset
++
]
|
content
[
offset
++
]
<<
8
,
colormap_length
:
content
[
offset
++
]
|
content
[
offset
++
]
<<
8
,
colormap_size
:
content
[
offset
++
],
origin
:
[
content
[
offset
++
]
|
content
[
offset
++
]
<<
8
,
content
[
offset
++
]
|
content
[
offset
++
]
<<
8
],
width
:
content
[
offset
++
]
|
content
[
offset
++
]
<<
8
,
height
:
content
[
offset
++
]
|
content
[
offset
++
]
<<
8
,
pixel_size
:
content
[
offset
++
],
flags
:
content
[
offset
++
]
};
function
tgaCheckHeader
(
header
)
{
switch
(
header
.
image_type
)
{
// Check indexed type
case
TGA_TYPE_INDEXED
:
case
TGA_TYPE_RLE_INDEXED
:
if
(
header
.
colormap_length
>
256
||
header
.
colormap_size
!==
24
||
header
.
colormap_type
!==
1
)
{
console
.
error
(
'
Targa::tgaCheckHeader() - Invalid type colormap data for indexed type
'
);
}
break
;
// Check colormap type
case
TGA_TYPE_RGB
:
case
TGA_TYPE_GREY
:
case
TGA_TYPE_RLE_RGB
:
case
TGA_TYPE_RLE_GREY
:
if
(
header
.
colormap_type
)
{
console
.
error
(
'
ImageUtils::tgaCheckHeader() - Invalid type colormap data for colormap type
'
);
}
break
;
// What the need of a file without data ?
case
TGA_TYPE_NO_DATA
:
console
.
error
(
'
ImageUtils::tgaCheckHeader() - No data
'
);
// Invalid type ?
default
:
console
.
error
(
'
ImageUtils::tgaCheckHeader() - Invalid type "
'
+
header
.
image_type
+
'
"
'
);
}
// Check image width and height
if
(
header
.
width
<=
0
||
header
.
height
<=
0
)
{
console
.
error
(
'
ImageUtils::tgaCheckHeader() - Invalid image size
'
);
}
// Check image pixel size
if
(
header
.
pixel_size
!==
8
&&
header
.
pixel_size
!==
16
&&
header
.
pixel_size
!==
24
&&
header
.
pixel_size
!==
32
)
{
console
.
error
(
'
ImageUtils::tgaCheckHeader() - Invalid pixel size "
'
+
header
.
pixel_size
+
'
"
'
);
}
}
// Check tga if it is valid format
tgaCheckHeader
(
header
);
if
(
header
.
id_length
+
offset
>
arrayBuffer
.
length
)
{
console
.
error
(
'
ImageUtils::load() - No data
'
);
}
// Skip the needn't data
offset
+=
header
.
id_length
;
// Get targa information about RLE compression and palette
var
use_rle
=
false
,
use_pal
=
false
,
use_grey
=
false
;
switch
(
header
.
image_type
)
{
case
TGA_TYPE_RLE_INDEXED
:
use_rle
=
true
;
use_pal
=
true
;
break
;
case
TGA_TYPE_INDEXED
:
use_pal
=
true
;
break
;
case
TGA_TYPE_RLE_RGB
:
use_rle
=
true
;
break
;
case
TGA_TYPE_RGB
:
break
;
case
TGA_TYPE_RLE_GREY
:
use_rle
=
true
;
use_grey
=
true
;
break
;
case
TGA_TYPE_GREY
:
use_grey
=
true
;
break
;
}
// Parse tga image buffer
function
tgaParse
(
use_rle
,
use_pal
,
header
,
offset
,
data
)
{
var
pixel_data
,
pixel_size
,
pixel_total
,
palettes
;
pixel_size
=
header
.
pixel_size
>>
3
;
pixel_total
=
header
.
width
*
header
.
height
*
pixel_size
;
// Read palettes
if
(
use_pal
)
{
palettes
=
data
.
subarray
(
offset
,
offset
+=
header
.
colormap_length
*
3
);
}
// Read RLE
if
(
use_rle
)
{
pixel_data
=
new
Uint8Array
(
pixel_total
);
var
c
,
count
,
i
;
var
shift
=
0
;
var
pixels
=
new
Uint8Array
(
pixel_size
);
while
(
shift
<
pixel_total
)
{
c
=
data
[
offset
++
];
count
=
(
c
&
0x7f
)
+
1
;
// RLE pixels.
if
(
c
&
0x80
)
{
// Bind pixel tmp array
for
(
i
=
0
;
i
<
pixel_size
;
++
i
)
{
pixels
[
i
]
=
data
[
offset
++
];
}
// Copy pixel array
for
(
i
=
0
;
i
<
count
;
++
i
)
{
pixel_data
.
set
(
pixels
,
shift
+
i
*
pixel_size
);
}
shift
+=
pixel_size
*
count
;
}
// Raw pixels.
else
{
count
*=
pixel_size
;
for
(
i
=
0
;
i
<
count
;
++
i
)
{
pixel_data
[
shift
+
i
]
=
data
[
offset
++
];
}
shift
+=
count
;
}
}
}
// RAW Pixels
else
{
pixel_data
=
data
.
subarray
(
offset
,
offset
+=
(
use_pal
?
header
.
width
*
header
.
height
:
pixel_total
)
);
}
return
{
pixel_data
:
pixel_data
,
palettes
:
palettes
};
}
function
tgaGetImageData8bits
(
imageData
,
y_start
,
y_step
,
y_end
,
x_start
,
x_step
,
x_end
,
image
,
palettes
)
{
var
colormap
=
palettes
;
var
color
,
i
=
0
,
x
,
y
;
var
width
=
header
.
width
;
for
(
y
=
y_start
;
y
!==
y_end
;
y
+=
y_step
)
{
for
(
x
=
x_start
;
x
!==
x_end
;
x
+=
x_step
,
i
++
)
{
color
=
image
[
i
];
imageData
[(
x
+
width
*
y
)
*
4
+
3
]
=
255
;
imageData
[(
x
+
width
*
y
)
*
4
+
2
]
=
colormap
[(
color
*
3
)
+
0
];
imageData
[(
x
+
width
*
y
)
*
4
+
1
]
=
colormap
[(
color
*
3
)
+
1
];
imageData
[(
x
+
width
*
y
)
*
4
+
0
]
=
colormap
[(
color
*
3
)
+
2
];
}
}
return
imageData
;
};
function
tgaGetImageData16bits
(
imageData
,
y_start
,
y_step
,
y_end
,
x_start
,
x_step
,
x_end
,
image
)
{
var
color
,
i
=
0
,
x
,
y
;
var
width
=
header
.
width
;
for
(
y
=
y_start
;
y
!==
y_end
;
y
+=
y_step
)
{
for
(
x
=
x_start
;
x
!==
x_end
;
x
+=
x_step
,
i
+=
2
)
{
color
=
image
[
i
+
0
]
+
(
image
[
i
+
1
]
<<
8
);
// Inversed ?
imageData
[(
x
+
width
*
y
)
*
4
+
0
]
=
(
color
&
0x7C00
)
>>
7
;
imageData
[(
x
+
width
*
y
)
*
4
+
1
]
=
(
color
&
0x03E0
)
>>
2
;
imageData
[(
x
+
width
*
y
)
*
4
+
2
]
=
(
color
&
0x001F
)
>>
3
;
imageData
[(
x
+
width
*
y
)
*
4
+
3
]
=
(
color
&
0x8000
)
?
0
:
255
;
}
}
return
imageData
;
};
function
tgaGetImageData24bits
(
imageData
,
y_start
,
y_step
,
y_end
,
x_start
,
x_step
,
x_end
,
image
)
{
var
i
=
0
,
x
,
y
;
var
width
=
header
.
width
;
for
(
y
=
y_start
;
y
!==
y_end
;
y
+=
y_step
)
{
for
(
x
=
x_start
;
x
!==
x_end
;
x
+=
x_step
,
i
+=
3
)
{
imageData
[(
x
+
width
*
y
)
*
4
+
3
]
=
255
;
imageData
[(
x
+
width
*
y
)
*
4
+
2
]
=
image
[
i
+
0
];
imageData
[(
x
+
width
*
y
)
*
4
+
1
]
=
image
[
i
+
1
];
imageData
[(
x
+
width
*
y
)
*
4
+
0
]
=
image
[
i
+
2
];
}
}
return
imageData
;
};
function
tgaGetImageData32bits
(
imageData
,
y_start
,
y_step
,
y_end
,
x_start
,
x_step
,
x_end
,
image
)
{
var
i
=
0
,
x
,
y
;
var
width
=
header
.
width
;
for
(
y
=
y_start
;
y
!==
y_end
;
y
+=
y_step
)
{
for
(
x
=
x_start
;
x
!==
x_end
;
x
+=
x_step
,
i
+=
4
)
{
imageData
[(
x
+
width
*
y
)
*
4
+
2
]
=
image
[
i
+
0
];
imageData
[(
x
+
width
*
y
)
*
4
+
1
]
=
image
[
i
+
1
];
imageData
[(
x
+
width
*
y
)
*
4
+
0
]
=
image
[
i
+
2
];
imageData
[(
x
+
width
*
y
)
*
4
+
3
]
=
image
[
i
+
3
];
}
}
return
imageData
;
};
function
tgaGetImageDataGrey8bits
(
imageData
,
y_start
,
y_step
,
y_end
,
x_start
,
x_step
,
x_end
,
image
)
{
var
color
,
i
=
0
,
x
,
y
;
var
width
=
header
.
width
;
for
(
y
=
y_start
;
y
!==
y_end
;
y
+=
y_step
)
{
for
(
x
=
x_start
;
x
!==
x_end
;
x
+=
x_step
,
i
++
)
{
color
=
image
[
i
];
imageData
[(
x
+
width
*
y
)
*
4
+
0
]
=
color
;
imageData
[(
x
+
width
*
y
)
*
4
+
1
]
=
color
;
imageData
[(
x
+
width
*
y
)
*
4
+
2
]
=
color
;
imageData
[(
x
+
width
*
y
)
*
4
+
3
]
=
255
;
}
}
return
imageData
;
};
function
tgaGetImageDataGrey16bits
(
imageData
,
y_start
,
y_step
,
y_end
,
x_start
,
x_step
,
x_end
,
image
)
{
var
i
=
0
,
x
,
y
;
var
width
=
header
.
width
;
for
(
y
=
y_start
;
y
!==
y_end
;
y
+=
y_step
)
{
for
(
x
=
x_start
;
x
!==
x_end
;
x
+=
x_step
,
i
+=
2
)
{
imageData
[(
x
+
width
*
y
)
*
4
+
0
]
=
image
[
i
+
0
];
imageData
[(
x
+
width
*
y
)
*
4
+
1
]
=
image
[
i
+
0
];
imageData
[(
x
+
width
*
y
)
*
4
+
2
]
=
image
[
i
+
0
];
imageData
[(
x
+
width
*
y
)
*
4
+
3
]
=
image
[
i
+
1
];
}
}
return
imageData
;
};
function
getTgaRGBA
(
width
,
height
,
image
,
palette
)
{
var
x_start
,
y_start
,
x_step
,
y_step
,
x_end
,
y_end
,
data
=
new
Uint8Array
(
width
*
height
*
4
);
switch
(
(
header
.
flags
&
TGA_ORIGIN_MASK
)
>>
TGA_ORIGIN_SHIFT
)
{
default
:
case
TGA_ORIGIN_UL
:
x_start
=
0
;
x_step
=
1
;
x_end
=
width
;
y_start
=
0
;
y_step
=
1
;
y_end
=
height
;
break
;
case
TGA_ORIGIN_BL
:
x_start
=
0
;
x_step
=
1
;
x_end
=
width
;
y_start
=
height
-
1
;
y_step
=
-
1
;
y_end
=
-
1
;
break
;
case
TGA_ORIGIN_UR
:
x_start
=
width
-
1
;
x_step
=
-
1
;
x_end
=
-
1
;
y_start
=
0
;
y_step
=
1
;
y_end
=
height
;
break
;
case
TGA_ORIGIN_BR
:
x_start
=
width
-
1
;
x_step
=
-
1
;
x_end
=
-
1
;
y_start
=
height
-
1
;
y_step
=
-
1
;
y_end
=
-
1
;
break
;
}
if
(
use_grey
)
{
switch
(
header
.
pixel_size
)
{
case
8
:
tgaGetImageDataGrey8bits
(
data
,
y_start
,
y_step
,
y_end
,
x_start
,
x_step
,
x_end
,
image
);
break
;
case
16
:
tgaGetImageDataGrey16bits
(
data
,
y_start
,
y_step
,
y_end
,
x_start
,
x_step
,
x_end
,
image
);
break
;
default
:
console
.
error
(
'
ImageUtils::getTgaRGBA() - not support this format
'
);
break
;
}
}
else
{
switch
(
header
.
pixel_size
)
{
case
8
:
tgaGetImageData8bits
(
data
,
y_start
,
y_step
,
y_end
,
x_start
,
x_step
,
x_end
,
image
,
palette
);
break
;
case
16
:
tgaGetImageData16bits
(
data
,
y_start
,
y_step
,
y_end
,
x_start
,
x_step
,
x_end
,
image
);
break
;
case
24
:
tgaGetImageData24bits
(
data
,
y_start
,
y_step
,
y_end
,
x_start
,
x_step
,
x_end
,
image
);
break
;
case
32
:
tgaGetImageData32bits
(
data
,
y_start
,
y_step
,
y_end
,
x_start
,
x_step
,
x_end
,
image
);
break
;
default
:
console
.
error
(
'
ImageUtils::getTgaRGBA() - not support this format
'
);
break
;
}
}
// Load image data according to specific method
// var func = 'tgaGetImageData' + (use_grey ? 'Grey' : '') + (header.pixel_size) + 'bits';
//func(data, y_start, y_step, y_end, x_start, x_step, x_end, width, image, palette );
return
data
;
}
var
result
=
tgaParse
(
use_rle
,
use_pal
,
header
,
offset
,
content
);
var
rgbaData
=
getTgaRGBA
(
header
.
width
,
header
.
height
,
result
.
pixel_data
,
result
.
palettes
);
return
{
width
:
header
.
width
,
height
:
header
.
height
,
data
:
rgbaData
};
},
loadTGATexture
:
function
(
url
,
mapping
,
onLoad
,
onError
)
{
var
texture
=
new
THREE
.
TGATexture
();
{
var
request
=
new
XMLHttpRequest
();
request
.
open
(
'
GET
'
,
url
,
true
);
request
.
responseType
=
"
arraybuffer
"
;
request
.
onload
=
function
()
{
if
(
this
.
status
===
200
)
{
var
imageData
=
THREE
.
ImageUtils
.
decodeTGA
(
this
.
response
);
if
(
imageData
)
{
texture
.
image
=
imageData
;
texture
.
sourceFile
=
url
;
texture
.
needsUpdate
=
true
;
return
texture
;
}
}
};
request
.
addEventListener
(
'
load
'
,
function
(
event
)
{
if
(
onLoad
)
onLoad
(
texture
);
},
false
);
request
.
addEventListener
(
'
error
'
,
function
(
event
)
{
if
(
onError
)
onError
(
event
);
},
false
);
request
.
send
(
null
);
}
texture
.
sourceFile
=
url
;
return
texture
;
},
loadDDSTexture
:
function
(
url
,
mapping
,
onLoad
,
onError
)
{
var
images
=
[];
...
...
src/renderers/WebGLRenderer.js
浏览文件 @
98711f49
...
...
@@ -5546,6 +5546,10 @@ THREE.WebGLRenderer = function ( parameters ) {
}
}
else
if
(
texture
instanceof
THREE
.
TGATexture
)
{
var
tgaImg
=
texture
.
image
;
_gl
.
texImage2D
(
_gl
.
TEXTURE_2D
,
0
,
glFormat
,
tgaImg
.
width
,
tgaImg
.
height
,
0
,
glFormat
,
glType
,
tgaImg
.
data
);
}
else
{
// regular Texture (image, video, canvas)
// use manually created mipmaps if available
...
...
src/textures/TGATexture.js
0 → 100644
浏览文件 @
98711f49
/**
* @author Daosheng Mu / https://github.com/DaoshengMu/
*/
THREE
.
TGATexture
=
function
(
format
,
type
,
mapping
,
wrapS
,
wrapT
,
magFilter
,
minFilter
,
anisotropy
)
{
THREE
.
Texture
.
call
(
this
,
null
,
mapping
,
wrapS
,
wrapT
,
magFilter
,
minFilter
,
format
,
type
,
anisotropy
);
};
THREE
.
TGATexture
.
prototype
=
Object
.
create
(
THREE
.
Texture
.
prototype
);
THREE
.
TGATexture
.
prototype
.
clone
=
function
()
{
var
texture
=
new
THREE
.
TGATexture
();
THREE
.
Texture
.
prototype
.
clone
.
all
(
this
.
texture
);
return
texture
;
};
\ No newline at end of file
utils/build/includes/common.json
浏览文件 @
98711f49
...
...
@@ -64,6 +64,7 @@
"src/materials/SpriteCanvasMaterial.js"
,
"src/textures/Texture.js"
,
"src/textures/CompressedTexture.js"
,
"src/textures/TGATexture.js"
,
"src/textures/DataTexture.js"
,
"src/objects/PointCloud.js"
,
"src/objects/Line.js"
,
...
...
utils/build/includes/webgl.json
浏览文件 @
98711f49
...
...
@@ -55,6 +55,7 @@
"src/materials/SpriteMaterial.js"
,
"src/textures/Texture.js"
,
"src/textures/CompressedTexture.js"
,
"src/textures/TGATexture.js"
,
"src/textures/DataTexture.js"
,
"src/objects/PointCloud.js"
,
"src/objects/Line.js"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录