Skip to content

Instantly share code, notes, and snippets.

Q:如何显示2d的sprite?一种呈现在场景中(如粒子),一种固定在屏幕上不动(如GUI/HUD)
A:不同点在于是否需要设置useScreenCoordinates为true。
Q:如何按一定规则贴上纹理?
A:常用 texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set( 10, 10 );
var material = new THREE.MeshBasicMaterial( { map: texture, side: THREE.DoubleSide } );
// 后台进程(优先级最低)
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
});
// 更新界面(优先级最高)
dispatch_async(dispatch_get_main_queue(), ^{
});
@zhangwc
zhangwc / fog.js
Created November 27, 2013 10:34
ThreeJS fog effect
scene = new THREE.Scene();
scene.fog = new THREE.FogExp2( 0xcccccc, 0.002 );
@zhangwc
zhangwc / js_dispatchEvent.js
Created November 27, 2013 10:24
http://www.css88.com/archives/4998 (IE和其他浏览器自定义事件触发器)
document.addEventListener("onmyevent", function(event){
alert(event.eventType);
}, false);
var obj = document.getElementById("obj");
var event = document.createEvent('HTMLEvents');
event.initEvent("onmyevent", true, true);
event.eventType = 'message';
document.dispatchEvent(event);
@zhangwc
zhangwc / raycaster_insersectObjects.js
Created November 27, 2013 08:27
get object3Ds which are selected
renderer.domElement.addEventListener( 'mousedown', handleMouseDown, false );
function handleMouseDown(event) {
event.preventDefault();
var mouseX =((event.clientX - container.offsetLeft )/ container.clientWidth )*2-1;
var mouseY =-((event.clientY - container.offsetTop )/ container.clientHeight )*2+1;
@zhangwc
zhangwc / calCameraZ
Created November 27, 2013 05:56
the relation of camera depth and FOV(field of view)
D = d*W/w;
d = (w/2)/tan(fov/2);
===>
D = (W/2)/tan(fov/2);
(D: the distance between camera and 3d-objects
d: the distance between camera and screen
W: 3d-objects size
w: screen size)
@zhangwc
zhangwc / ThreeJS draw image.js
Created November 27, 2013 05:45
use THREE.SpriteMaterial and canvas to create text and image in 3D scene
{
var texture = new THREE.ImageUtils.loadTexture( 'images/img.jpg' );
texture.needsUpdate = true;
var material = new THREE.SpriteMaterial({
map: texture,
useScreenCoordinates: false,
alignment: THREE.SpriteAlignment.center,
transparent: true
});
UIColor *textDefaultColor = [UIColor blackColor];
CGColorRef textDefaultColorRef = textDefaultColor.CGColor;
NSString *textDefaultColorStr = [CIColor colorWithCGColor:textDefaultColorRef].stringRepresentation;
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:textDefaultColorStr forKey:@"textColorKey"];
@zhangwc
zhangwc / KVO
Created September 5, 2013 03:17
aBook = [[Book alloc] initWithBookNO:@"NO.21342413" bookName:@"清朝秘史" author:@"张家州" price:25.50];
[aBook addObserver:self forKeyPath:@"price" options:NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNew context:nil];
// 观察到变化(收到来自被观察者的消息通知)
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
if([keyPath isEqual:@"price"]) {
@zhangwc
zhangwc /
Created September 5, 2013 02:55
options (如NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNew)与infos的NSDictionary匹配使用 [infos objectForKey:@"old"], [infos objectForKey:@"new"]