# Javascript���� # ����ע��(comment) �����в��ᱻ�������������е�����, �����ڴ�����д�ʼ�, ��Ϊ���кͶ���ע�� ``` //������б��������ע�� /* ����ע�͵�1�� ����ע�͵�2�� ����ע�͵�3�� */ ``` # �ַ���, ����, ����ֵ Javascript�еĻ����������� ## �ַ���(string) ``` '������' //�����Ż�˫���Ű�Χ���ı����ַ���, ���������ʾ���� "������" //���ú�������ʵһ��, ��������', ��Ϊ�����"���� ``` ## ����(number) ``` 8 //���� 1.5 //������ ``` ## ����ֵ(boolean) ``` true //�� false //�� ``` # �����(operator) ## ���ּӼ��˳�ģ ``` 1.5 + 4 //1.5��4��5.5 1.5 - 4 //1.5��4��-3.5 1.5 * 4 //1.5��4��6 1.5 / 4 //1.5����4��0.375 7 % 4 //7��4ȡģ��3 ``` ## �ַ���ƴ�����ַ���ȡ(string concatenation/get char) ``` '��������' + 100 + '��Ǯ' //�ַ���ƴ�ӳ� '��������100��Ǯ' '������'[0] //0��λ���ַ���'��' '������'[2] //2��λ���ַ���'��' ``` ## ���Dz�������(and/or/negate) ``` true && true //true��true��true true && false //true��false��false false && false //false��false��false true || true //true��true��true true || false //true��false��true false || false //false��false��false !true //��true��false !false //��false��true ``` ## �Ƚ�����(comparison) ``` 2 > 3 //2����3��false 2 >= 3 //2���ڵ���3��false 2 < 3 //2С��3��true 2 <= 3 //2С�ڵ���3��true 2 == 3 //2����3��false 2 != 3 //2������3��true ``` # ����(variable) ���ڴ�ſɱ������ ``` let name = '������' // ������'������' let lv = 1 // �ȼ���1 let money = 10 // ��Ǯ��10 let hp = 100 // ����ֵ��100 let atk = 20 // ��������20 name = '�׵��' //���ִӼ���������׵�� atk += 10 //��������10, �����30������ hp -= 20 //����ֵ����20, ���80����ֵ lv++ //�ȼ���1, ���2�� money-- //��Ǯ��1, ���9 ``` ���еı���������� ``` my_var_name //��ʽ������ myVarName //�շ�ʽ������ MyVarName //������������ MY_VAR_NAME //���������� $my_var_name //��Ԫ����ʽ������ $myVarName //��Ԫ���շ�ʽ������ my_var_name99 //��ʽ+���ֻ�� myVarName88 //�շ�ʽ+���ֻ�� ``` ## ����(constant) �������ڴ�Ų��ᱻ�ı������ ``` const PI = 3.1415926535897932384626433832795 //Բ���� const DAYS_OF_A_WEEK = 7 //һ����7�� ``` # ʹ��console����̨���Դ��� ``` let a = 2 let b = 3 console.log(a + b) //�ڿ���̨���5 ``` ``` console.clear() //�������̨�������¼ ``` # ����������(object property) ���ն�����������: ``` let obj = {} //����һ����Ϊobj�ı����洢һ���ն��� obj.name = '������' //��obj����name����, ֵΪ'������' obj.money = 99 //��obj����money����, ֵΪ99 obj.atk = 10 //��obj����atk����, ֵΪ10 //����̨���:'��������99��Ǯ, 10������' console.log(`${obj.name}��${obj.money}��Ǯ, ${obj.atk}������`) ``` �ö�����г�ʼ����: ``` let obj = { name:'������', money: 99, atk: 10, } //����̨���:'��������99��Ǯ, 10������' console.log(`${obj.name}��${obj.money}��Ǯ, ${obj.atk}������`) ``` # ����(function) �������ڰѶಽ������̷�װ��1��, �����ڼ򻯴��� ``` //����һ����Ϊadd�ĺ���, ��3������, �ֱ��� a b c function add(a, b, c) { a += b a += c return a //�����ۼӺ�� a } add(2, 3, 4) //�ò���2,3,4����add, ���� 9 add('abc', 'def', 'ghi') //���� 'abcdefghi' //����ĺ������������Ҳ���Լ򻯳�1�� function add(a, b, c) { return a + b + c //ֱ�ӷ���abc�ĺ� } ``` ���������ڲ�����������: ``` let obj1 = { name:'������', money: 99, } let obj2 = { name:'�׵��', money: 10, } function addMoney(obj, n) {//�������Ǯ obj.money += n console.log(`${obj.name}�����${n}��Ǯ`) } function giveMoney(sender,receiver, n) {//��Ǯ��һ������ת����һ������ receiver.money += n sender.money -= n console.log(`${sender.name}����${receiver.name}${n}��Ǯ`) } function display(obj) { console.log(`${obj.name}��${obj.money}��Ǯ`) } display(obj1) display(obj2) addMoney(obj2, 10) display(obj2) giveMoney(obj1, obj2, 20) display(obj1) display(obj2) /* ����̨���: ��������99��Ǯ �׵����10��Ǯ �׵������10��Ǯ �׵����20��Ǯ �����������׵��20��Ǯ ��������79��Ǯ �׵����40��Ǯ */ ``` ## ������������̬ ### ��������(û�����ֵĺ���) ``` //����������ֵ������, ��������û������, �����õ��DZ��������� //ȱ����Ҫ������������ܵ��� let add = function(a, b, c) { return a + b + c } add(1,2,3) ``` ### ��ͷ���� ``` //��ͷ������ֵ������, ���������ļ�д, ����this�ؼ����ڼ�ͷ������Ч let add = (a, b, c) => { return a + b + c } let add2 = (a, b, c) => a + b + c //�ڱ���ʽֻ��1��ʱ, ���Խ�һ����д console.log(add(1,2,3), (1,2,3)) ``` ### �첽���� ``` //��async�ؼ������κ���, �����ú����첽ִ�� //await�ؼ����������첽����ͬ��ִ��, await������async������ʹ�� async function countDown() { console.log(3) await sleep(1000) //�ȴ�1000���� console.log(2) await sleep(1000) //�ȴ�1000���� console.log(1) await sleep(1000) //�ȴ�1000���� console.log(0) } console.log('start') countDown() console.log('end') ``` ``` // �������� �� ��ͷ���� ͬ������ʹ��async/await let a = async function () { await sleep(1000) } let b = async () => { await sleep(1000) } ``` # ����ķ���(object method) ���󷽷�, �Ƕ����Դ��ĺ���, ���ڲ�����������, �������this�ؼ��ʿ�������ָ��������� ��һ���������Ե�ֵ�Ǻ���, ������ԾͿ��Ե����������� ``` let obj1 = { name:'������', money: 99, giveMoney: function(receiver, n) {//giveMoney����, ��Ǯת����һ������ receiver.money += n this.money -= n console.log(`${this.name}����${receiver.name}${n}��Ǯ`)//this��ʾ�������� }, } let obj2 = { name:'�׵��', money: 10, giveMoney(receiver, n) {//giveMoney�����ļ�д receiver.money += n this.money -= n console.log(`${this.name}����${receiver.name}${n}��Ǯ`) }, } function display() { console.log(`${this.name}��${this.money}��Ǯ`) } //����ߵ�display�������ø�ֵ��show����, show�Ϳ��Ե����������� obj1.show = display obj2.show = display obj1.show() obj2.show() obj1.giveMoney(obj2, 20) obj1.show() obj2.show() obj2.giveMoney(obj1, 10) obj1.show() obj2.show() /* ��������99��Ǯ �׵����10��Ǯ �����������׵��20��Ǯ ��������79��Ǯ �׵����30��Ǯ �׵����˼�����10��Ǯ ��������89��Ǯ �׵����20��Ǯ */ ``` ���dz��õ�console.log��console.clear, ����ȫ�ֶ���console���log������clear���� # ����(array) ������������㽫���ݰ�˳��洢��һ�������� ``` let arr = ['������', 3, 100, 'a', 'b'] console.log(`${ arr[0] }��${ arr[2] }��Ǯ`) //��ȡ�����Ӧλ�õ�Ԫ�� console.log(arr.length) //��ȡ���鳤�� ``` # ������֧(conditional branching) ## if/else ``` let hp = 50 if (hp >= 80) { console.log('�㴦�ڽ���״̬') } else if (hp > 50) { console.log('�㴦������״̬') } else if (hp > 0) { console.log('�㴦������״̬') } else { console.log('��������') } ``` ## switch ``` let gunType = '���ǹ' let gunConfig switch (gunType) { case '���ǹ': gunConfig = { atk:3,//������ range:7,//��� fireRate:10,//���� } break case '�ѻ�ǹ': gunConfig = { atk:10,//������ range:12,//��� fireRate:2,//���� } break case 'ɢ��ǹ': gunConfig = { atk:6,//������ range:5,//��� fireRate:4,//���� } break default://���gunTypeû��ƥ������3��ǹе gunConfig = { atk:2,//������ range:5,//��� fireRate:6,//���� } break } ``` # ѭ�����(loops) ## for...of ��˳�����������ÿһ��Ԫ�� ``` let arr = ['������', 3, 100, 'a', 'b'] for (const e of arr) { //����arr�е�ÿһ��Ԫ�� console.log(e) } /* ������ 3 100 a b */ ``` ## while ����������ʱ��һֱ����ѭ�� ``` let i = 10 while (i-- > 0) { console.log(i) } ``` ## for...in ���������е�ÿһ�������� ``` let obj = {a: 1, b: 2, c: 3} for (const k in obj) { const v = obj[k] //kΪ������, vΪ����ֵ console.log(k, v) //��� k �� v } ``` ## for ���õ�ѭ����� ``` for (let i=0; i<10; i++) { console.log(i) } ``` # �������(class) ## ����һ���� ``` class Gamer {//����һ����ΪGamer���� constructor(name, money){//���췽��, ÿ�δ���ʵ������ִ�� this.name = name this.money = money } giveMoney(receiver, n) {//giveMoney����, ��Ǯת����һ������ receiver.money += n this.money -= n console.log(`${this.name}����${receiver.name}${n}��Ǯ`) } display() { console.log(`${this.name}��${this.money}��Ǯ`) } } let gamer1 = new Gamer('������', 99) //new ���Խ���ʵ����, �������������췽���� let gamer2 = new Gamer('�׵��', 20) gamer1.display() gamer2.display() gamer1.giveMoney(gamer2, 20) gamer1.display() gamer2.display() ``` ## ����(subclass) ������Լ̳и���ĵķ��������� ``` class Attacker extends Gamer {//Attacker��Gamer������, Gamer��Attacker�ĸ��� constructor(name, money, atk){ super(name, money)//super()�Ǹ���Ĺ��췽�� this.atk = atk } display() {//��д�����display���� super.display()//ͨ��super.xxx���ʸ���ķ��� console.log(`${this.name}��${this.atk}������`) } } let gamer1 = new Attacker('������', 99, 3) let gamer2 = new Attacker('�׵��', 20, 10) gamer1.display() gamer2.display() gamer1.giveMoney(gamer2, 20) gamer1.display() gamer2.display() ``` # �﷨С���� ## �⹹��ֵ(destructing assignment) ��ȡ��������ߵ����ݵ�д�� ``` let arr = [1,2,3] let obj = {a:88, b:99} let {a, b} = obj //���� let a = obj.a // let b = obj.b let [c, d, e] = arr //���� let c = arr[0] // let d = arr[1] // let e = arr[2] console.log(a,b,c,d,e) ``` # ���÷���(built-in methods) Javascript��ÿ���඼����һЩ���õ����Ժͷ��� ## ���� �������÷�������ϸ���ݿɲο� [���ҳ��](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array) ``` let arr = [1,2,3,4,5] arr.length arr.concat() arr.copyWithin() arr.fill() arr.find() arr.findIndex() arr.lastIndexOf() arr.pop() arr.push() arr.reverse() arr.shift() arr.unshift() arr.slice() arr.sort() arr.splice() arr.includes() arr.indexOf() arr.join() arr.keys() arr.entries() arr.values() arr.forEach() arr.filter() arr.flat() arr.flatMap() arr.map() arr.every() arr.some() arr.reduce() arr.reduceRight() arr.toLocaleString() arr.toString() ``` ## �ַ��� �ַ������÷�������ϸ���ݿɲο� [���ҳ��](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String) ``` let str = 'abcde' str.length str.anchor() str.big() str.blink() str.bold() str.charAt() str.charCodeAt() str.codePointAt() str.concat() str.endsWith() str.fontcolor() str.fontsize() str.fixed() str.includes() str.indexOf() str.italics() str.lastIndexOf() str.link() str.localeCompare() str.match() str.matchAll() str.normalize() str.padEnd() str.padStart() str.repeat() str.replace() str.search() str.slice() str.small() str.split() str.strike() str.sub() str.substr() str.substring() str.sup() str.startsWith() str.toString() str.trim() str.trimStart() str.trimLeft() str.trimEnd() str.trimRight() str.toLocaleLowerCase() str.toLocaleUpperCase() str.toLowerCase() str.toUpperCase() str.valueOf() str.replaceAll() ``` ## ���� �������÷�������ϸ���ݿɲο� [���ҳ��](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object) ``` Object.assign() Object.getOwnPropertyDescriptor() Object.getOwnPropertyDescriptors() Object.getOwnPropertyNames() Object.getOwnPropertySymbols() Object.is() Object.preventExtensions() Object.seal() Object.create() Object.defineProperties() Object.defineProperty() Object.freeze() Object.getPrototypeOf() Object.setPrototypeOf() Object.isExtensible() Object.isFrozen() Object.isSealed() Object.keys() Object.entries() Object.fromEntries() Object.values() ``` ## ��ѧ ��ѧ���÷�������ϸ���ݿɲο� [���ҳ��](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Math) ``` Math.abs() Math.acos() Math.acosh() Math.asin() Math.asinh() Math.atan() Math.atanh() Math.atan2() Math.ceil() Math.cbrt() Math.expm1() Math.clz32() Math.cos() Math.cosh() Math.exp() Math.floor() Math.fround() Math.hypot() Math.imul() Math.log() Math.log1p() Math.log2() Math.log10() Math.max() Math.min() Math.pow() Math.random() Math.round() Math.sign() Math.sin() Math.sinh() Math.sqrt() Math.tan() Math.tanh() Math.trunc() Math.E Math.LN10 Math.LN2 Math.LOG10E Math.LOG2E Math.PI Math.SQRT1_2 Math.SQRT2 ``` # �ⲿѧϰ���� - [https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference) - [https://www.runoob.com/js/js-tutorial.html](https://www.runoob.com/js/js-tutorial.html) - [http://c.biancheng.net/js/](http://c.biancheng.net/js/) # Class: Box3World **Box3World**��Box3 API����Ҫ�ӿڣ������ʹ��`world`������ƻ������������������������˾���ȫ�ֳ������ԣ��������������д���������ʵ�壬�����������ʵ�����ҵ���ײ���˺����������¼��� # Basics ���� ## world.projectName ###### `����` ??? ����ֵ���ͣ�`string` ??? Ĭ��ֵ��`��` ��ͼ���ƣ���Ӧ��Ŀ�����е����ơ�
��������ֻ���ģ������޸ĵ�ͼ���ƣ����ڱ༭���˵��ײ� **[��Ŀ-�༭����-��ͼ����]** �����޸ġ� ## world.onTick() ###### `�¼�` ��������ļ�ʱ�¼���ÿ64���봥��һ�Σ�Tick������1��
�������¼�������������64����Ϊ���ѭ��ִ�д��롣 ����������£�ÿTickΪ64���롣�����緢���ӳ٣����ܻ��б仯�� - **onTick**: *[Box3EventChannel](box3eventchannel.html)<[Box3TickEvent](box3tickevent.html)>* - **nextTick**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3TickEvent](box3tickevent.html)>* ### ����ֵ Box3TickEvent:{ tick, prevTick, elapsedTimeMS, skip } |����|����|˵�� |------ |tick|number|�¼�����ʱ��| |prevTick|number|��һ���Ѵ�����ʱ��| |elapsedTimeMS|number|����ʱ��֮���ʱ����(����)| |skip|boolean|�Ƿ���Ϊ�ӳٶ�������ijЩ Tick| ʾ������1 ʾ������2
// �������¼������ڿ���̨������� tick ����
world.onTick(({ tick }) => {
    console.log('tick ' + tick);
});

ʾ������1

// �������¼������ڿ���̨������� tick ����
world.onTick(({ tick }) => {
    console.log('tick ' + tick);
});

ʾ������2

// ����ҽ����ͼ
world.onPlayerJoin(({ entity }) => {

     // ÿTick�ļ�������̨�����ʾ
     const token = world.onTick(() => {
         console.log("tick !")
     });

     // 2��󣬽����¼�
     setTimeout(() => {
          console.log('cancel tick handler');
          token.cancel();  // ���ټ�¼tick�¼�
     }, 2000);
});
``` // �������¼������ڿ���̨������� tick ���� world.onTick(({ tick }) => { console.log('tick ' + tick); }); ``` ### ʾ������2 ## world.currentTick ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`0` ���統ǰ��Tick������ # Chat ����Ƶ�� ## world.say() ###### `����` ��������ҹ㲥һ����Ϣ�� ### ���� message |����|����|˵�� |------ |message|string|Ҫ�㲥����Ϣ| ��ʾ�� ѭ������ �߼���ʱ��
/* ��ҽ����ͼʱ����������ҷ�����Ϣ */
world.onPlayerJoin(({ entity }) => {
    world.say(`${entity.player.name}�����˵�ͼ`);
})

��ʾ��

/* ��ҽ����ͼʱ����������ҷ�����Ϣ */
world.onPlayerJoin(({ entity }) => {
    world.say(`${entity.player.name}�����˵�ͼ`);
})

ѭ������

/* ÿ�� 15 ��㲥һ����Ϣ����ѭ���л����� */
let seasonDuration = 1000 * 15  // ��λ�Ǻ��룺1�� = 1000 ����

async function seasonChange(){
    while(true){
        world.say('��������')
        await sleep(seasonDuration)
        world.say('�����')
        await sleep(seasonDuration)
        world.say('�^����')
        await sleep(seasonDuration)
        world.say('��������')
        await sleep(seasonDuration)
    }
}

seasonChange() // ���÷���

�߼���ʱ��

function startTimer(){
    const start = new Date().getTime()    // ��¼��ʼ��ʱǰ��ʱ�䡣
    const step = 1000 * 1                 // ÿ�������룬��һ�λ�����λ�Ǻ���(1�� = 1000����)
    const end = 1000 * 5                  // ��ʱ������������ʱ����λ�Ǻ���(1�� = 1000����)
    world.say('======��ʼ��ʱ======');
    const interval = setInterval(()=> {
        const current = new Date().getTime()   // ��ʱ�����е�ʱ��
        const duration = current - start       // ��ʱ�ۼ�ʱ������λ�Ǻ���(1�� = 1000����)
        if (duration > end) {                  // ���ʱ����������ʱ��
            world.say('======��ʱ����======');  // �㲥һ����Ϣ
            clearInterval(interval);           // ������ʱ��
            return;
        }
        world.say(`��ʱ ${Math.round(duration/1000)} ��`);  
    }, step);
}

startTimer()  // ���÷���
``` /* ��ҽ����ͼʱ����������ҷ�����Ϣ */ world.onPlayerJoin(({ entity }) => { world.say(`${entity.player.name}�����˵�ͼ`); }) ``` ### ѭ������ ``` function startTimer(){ const start = new Date().getTime() // ��¼��ʼ��ʱǰ��ʱ�䡣 const step = 1000 * 1 // ÿ�������룬��һ�λ�����λ�Ǻ���(1�� = 1000����) const end = 1000 * 5 // ��ʱ������������ʱ����λ�Ǻ���(1�� = 1000����) world.say('======��ʼ��ʱ======'); const interval = setInterval(()=> { const current = new Date().getTime() // ��ʱ�����е�ʱ�� const duration = current - start // ��ʱ�ۼ�ʱ������λ�Ǻ���(1�� = 1000����) if (duration > end) { // ���ʱ����������ʱ�� world.say('======��ʱ����======'); // �㲥һ����Ϣ clearInterval(interval); // ������ʱ�� return; } world.say(`��ʱ ${Math.round(duration/1000)} ��`); }, step); } startTimer() // ���÷��� ``` ## world.onChat() ###### `�¼�` ����������촰��˵��ʱ���� - **onChat**: *[Box3EventChannel](box3eventchannel.html)<[Box3ChatEvent](box3chatevent.html)>* - **nextChat**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3ChatEvent](box3chatevent.html)>* ### ����ֵ Box3ChatEvent:{ entity, message, tick } |����|����|˵�� |------ |entity|[Box3Entity](box3entity.html)|���������ʵ��| |message|string|�����¼���˵��������| |tick|number|�����¼�����ʱ��| ��������1 ��������2 ��ʵ��������к� �������������
// ����ҷ���'grow'���ֵ�ʱ��Ŵ�1.2��������ҷ���'shrink'���ֵ�ʱ����С1.2��
world.onChat(({ entity, message }) => {
    if (message === 'grow') {
        entity.player.scale *= 1.2;
    } else if (message === 'shrink') {
        entity.player.scale /= 1.2;
    }
})

��������1

// ����ҷ���'grow'���ֵ�ʱ��Ŵ�1.2��������ҷ���'shrink'���ֵ�ʱ����С1.2��
world.onChat(({ entity, message }) => {
    if (message === 'grow') {
        entity.player.scale *= 1.2;
    } else if (message === 'shrink') {
        entity.player.scale /= 1.2;
    }
})

��������2

// �����촰�ڻظ� '1', �������й��ܡ�
world.onChat(({ entity:user, message }) => {
    if(message === '1'){
        user.player.canFly = true;
        user.player.directMessage(`====���������====`)
    }else if (message === '2') {
        user.player.canFly = false;
        user.player.directMessage(`====�رշ��й���====`)
    }
});

��ʵ��������к�

// �����촰�ڻظ� '1', �����е�����ʵ���������к�
world.onChat(({ entity, message })=>{
    if(message==='1'){ //������������ 1
        //������ʵ���TA˵��ӭ
        let allEntities = world.querySelectorAll('*');
        for(let e of allEntities){
            if(e.isPlayer){continue} //���ʵ�������, ������
            e.say(`��ӭ ${entity.player.name}`)
        }
    }else if(message==='2'){ //������������ 2
        //��λ����(60,0,60)~(70,120,70)֮���ʵ�����˵��ӭ
        let foundEntities = world.searchBox(new Box3Bounds3(
            new Box3Vector3(60, 0, 60),
            new Box3Vector3(70, 120, 70),
        ))
        for(let e of foundEntities){
            if(e.isPlayer){continue} //���ʵ�������, ������
            e.say(`��� ${entity.player.name}`)
        }
    }
})

�������������

world.onPlayerJoin(({ entity })=>{
    entity.enableDamage = true
});

world.onChat(({ entity, message }) => {
    switch (message) {
        case 'die':
            if (entity.player.dead) { // �����˵��ʱ�Ѿ�����������
                entity.player.directMessage('��Ŀǰ�Ѿ������ˡ�');
                return;
            }
            entity.hurt(entity.maxHp)
            break;
        case 'revive':
            if (!entity.player.dead) { // ��˵��ʱ���Ƿ��Ѿ�����
                entity.player.directMessage('��Ŀǰ���ܽ���');
                return;
            }
            entity.hp = entity.maxHp
            entity.player.directMessage('ԭ����Ѫ���');
            break;
        default:
            break;
    }
})
``` // ����ҷ���'grow'���ֵ�ʱ��Ŵ�1.2��������ҷ���'shrink'���ֵ�ʱ����С1.2�� world.onChat(({ entity, message }) => { if (message === 'grow') { entity.player.scale *= 1.2; } else if (message === 'shrink') { entity.player.scale /= 1.2; } }) ``` ### ��������2 ``` // �����촰�ڻظ� '1', �����е�����ʵ���������к� world.onChat(({ entity, message })=>{ if(message==='1'){ //������������ 1 //������ʵ���TA˵��ӭ let allEntities = world.querySelectorAll('*'); for(let e of allEntities){ if(e.isPlayer){continue} //���ʵ�������, ������ e.say(`��ӭ ${entity.player.name}`) } }else if(message==='2'){ //������������ 2 //��λ����(60,0,60)~(70,120,70)֮���ʵ�����˵��ӭ let foundEntities = world.searchBox(new Box3Bounds3( new Box3Vector3(60, 0, 60), new Box3Vector3(70, 120, 70), )) for(let e of foundEntities){ if(e.isPlayer){continue} //���ʵ�������, ������ e.say(`��� ${entity.player.name}`) } } }) ``` ### ������������� # Player ��ң�����/�뿪 ## world.onPlayerJoin() ###### `�¼�` ����Ҽ����ͼʱ���� - **onPlayerJoin**: [Box3EventChannel](box3eventchannel.html)<[Box3EntityEvent](box3entityevent.html)> - **nextPlayerJoin**: [Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3EntityEvent](box3entityevent.html)> ### ����ֵ Box3EntityEvent:{ entity, tick } |����|����|˵�� |------ |entity|[Box3Entity](box3entity.html)|������ʵ��| |tick|number|�¼�����ʱ��| ��ʾ�� ������ҷ��� �ض���ҽ����ͼ����
// ��ҽ����ͼʱ����TA����һ��˽�š�
world.onPlayerJoin(({ entity }) => {
    entity.player.directMessage(`��ã�${entity.player.name}`);
});

��ʾ��

// ��ҽ����ͼʱ����TA����һ��˽�š�
world.onPlayerJoin(({ entity }) => {
    entity.player.directMessage(`��ã�${entity.player.name}`);
});

������ҷ���

// ��ҽ����ͼʱ���������й���
world.onPlayerJoin(({ entity }) => {
    entity.player.canFly = true;
});

�ض���ҽ����ͼ����

const TEST_PLAYER = ['������', '��ש��', '������', '�ĵ���']

world.onPlayerJoin(({ entity }) => {
    if (!TEST_PLAYER.includes(entity.player.name)) return; // ���������Ʋ����б�������������ű���
    world.say(`${entity.player.name} �����ˣ�`);
})
``` // ��ҽ����ͼʱ����TA����һ��˽�š� world.onPlayerJoin(({ entity }) => { entity.player.directMessage(`��ã�${entity.player.name}`); }); ``` ### ������ҷ��� ``` const TEST_PLAYER = ['������', '��ש��', '������', '�ĵ���'] world.onPlayerJoin(({ entity }) => { if (!TEST_PLAYER.includes(entity.player.name)) return; // ���������Ʋ����б�������������ű��� world.say(`${entity.player.name} �����ˣ�`); }) ``` ## world.onPlayerLeave() ###### `�¼�` ������뿪��ͼʱ���� ### ����ֵ Box3EntityEvent:{ entity, tick } |����|����|˵�� |------ |entity|[Box3Entity](box3entity.html)|�뿪��ͼ��ʵ��| |tick|number|�¼�����ʱ��| ``` // ����뿪��ͼʱ���ڿ���̨�����ҵ����֡� world.onPlayerLeave(({ entity }) => { console.log(`��� ${entity.player.name} �˳��˵�ͼ��`); }); ``` # Input ���/���� ## world.onInteract() ###### `�¼�` ��ʵ�忪���˻�������[`enableInteract = true`](box3entity.html#enableinteract)���������ʵ�����**����**ʱ������ ������߽�ʵ��Ļ�����Χ��ʵ�����Ͼͻ���ְ�����ʾ����Ұ��»�����ť(Ĭ��Ϊ���� E ����)���ʵ����л����� ����`onInteract`�¼�ͬʱ���ᴥ��ʵ��Ĭ�ϵ�[������Ч](box3entity.html#interactsound) ### ����ֵ Box3InteractEvent{ entity, targetEntity, tick } |����|����|˵�� |------ |entity|[Box3Entity](box3entity.html)|���𻥶���ʵ��| |targetEntity|[Box3Entity](box3entity.html)|�յ����������ʵ��| |tick|number|�¼�����ʱ��| > [!TIP|style:flat] ��Ҫ��ʵ����л�������Ҫ���ڱ༭���з���һ��ģ�ͣ�������ȡһ�����֡�
�����ʾ���������ָ�Ϊ��'NPC'�� ``` /* �ڳ�������������Ϊ NPC ��ģ�ͣ������������л��� */ const npc = world.querySelector('#NPC'); npc.enableInteract = true; // ����ʵ�廥������ npc.interactHint = 'NPC'; // ���뻥����Χʱ��ʾ������ npc.interactRadius = 32; // ������Χ��С // ���������п��Ի�����ʵ�壬����ʱ���ᴥ�����¼� world.onInteract( ({entity, targetEntity}) => { targetEntity.say('���! ' + entity.player.name); }); ``` > [!TIP|style:flat] ͨ��ͨ������onInteract ## world.onClick() ###### `�¼�` ������������ʵ��ʱ���� ### ����ֵ Box3InputEvent:{ entity, clicker, button, distance, clickerPosition, raycast, tick} |����|����|˵�� |------ |entity|[Box3Entity](box3entity.html)|�������ʵ��| |clicker|[Box3Entity](box3entity.html) & { [isPlayer:true](box3entity.html#isplayer), player:[Box3Player](box3player.html) }|�������¼������| |button|[Box3ButtonType](box3buttontype.html)|����İ�ť��ACTION0 = �����ACTION1 = �Ҽ�| |distance|number|��ҵ������ʵ��ľ���| |clickerPosition|[Box3Vector3](box3vector3.html)|�������˲���������λ��| |raycast|[Box3RaycastResult](box3raycastresult.html)|���°�ť˲�䣬������ӽ�Ͷ������߼����| |tick|number|�¼�����ʱ��| ``` // ���������ʵ��y�����ٶ����� world.onClick(({ entity }) => { console.log('clicked'); entity.velocity.y += 1; }) ``` ## world.onPress() ###### `�¼�` ����Ұ��°�ťʱ���� ### ����ֵ Box3InputEvent:{ button, entity, position, pressed, raycast, tick } |����|����|˵�� |------ |button|[Box3ButtonType](box3buttontype.html)|�������İ�ť| |entity|[Box3Entity](box3entity.html) & { [isPlayer:true](box3entity.html#isplayer), player:[Box3Player](box3player.html) }|���°�ť�����| |position|[Box3Vector3](box3vector3.html)|���°�ť˲�䣬��ҵ�λ��| |pressed|boolean|�Ƿ����˰�ť����Ϊ true����Ϊ�����˰�ť��| |raycast|[Box3RaycastResult](box3raycastresult.html)|���°�ť˲�䣬������ӽ�Ͷ������߼����| |tick|number|�¼�����ʱ��| ��ʾ�� ���������ʾ�Ի��� ���°�ť�滻����
/* �������ʱ���ڿ���̨�����¼ */
world.onPress(({ button, entity }) => {
    if(button === 'action0'){
       console.log(` ${entity.player.name} ���������`);
    }
})

��ʾ��

/* �������ʱ���ڿ���̨�����¼ */
world.onPress(({ button, entity }) => {
    if(button === 'action0'){
       console.log(` ${entity.player.name} ���������`);
    }
})

���������ʾ�Ի���

/* �������ʱ������һ���򵥶Ի��� */
world.onPress(({ button, entity }) => {
    if(button != 'action0' || !entity.isPlayer || entity.player.dead) return;
    entity.player.dialog({
        type: 'text',
        content: `��ã�${entity.player.name}���ܸ�����ʶ�㡣`,
    })
})

���°�ť�滻����

/* �������������ָ��λ�õķ����滻Ϊʯͷ������Ҽ������ٷ��顣 */
world.onPress(({ button, raycast }) => {
    const pos = raycast.voxelIndex  // ���߻��еķ�����������
    if(button === 'action0'){       // ������
        voxels.setVoxel(pos.x,pos.y,pos.z,'stone')  // �������滻Ϊʯͷ
    }else if(button === 'action1'){ // ����Ҽ�
        voxels.setVoxel(pos.x,pos.y,pos.z,'air')    // �������滻Ϊ����
    }
})
``` /* �������ʱ���ڿ���̨�����¼ */ world.onPress(({ button, entity }) => { if(button === 'action0'){ console.log(` ${entity.player.name} ���������`); } }) ``` ### ���������ʾ�Ի��� ``` /* �������������ָ��λ�õķ����滻Ϊʯͷ������Ҽ������ٷ��顣 */ world.onPress(({ button, raycast }) => { const pos = raycast.voxelIndex // ���߻��еķ����������� if(button === 'action0'){ // ������ voxels.setVoxel(pos.x,pos.y,pos.z,'stone') // �������滻Ϊʯͷ }else if(button === 'action1'){ // ����Ҽ� voxels.setVoxel(pos.x,pos.y,pos.z,'air') // �������滻Ϊ���� } }) ``` ## world.onRelease() ###### `�¼�` ������ɿ���ťʱ���� ### ����ֵ Box3InputEvent:{ button, entity, position, pressed, raycast, tick } |����|����|˵�� |------ |button|[Box3ButtonType](box3buttontype.html)|�������İ�ť| |entity|[Box3Entity](box3entity.html) & { [isPlayer:true](box3entity.html#isplayer), player:[Box3Player](box3player.html) }|���°�ť�����| |position|[Box3Vector3](box3vector3.html)|���°�ť˲�䣬��ҵ�λ��| |pressed|boolean|�Ƿ����˰�ť����Ϊ false����Ϊ�ɿ���ť��| |raycast|[Box3RaycastResult](box3raycastresult.html)|���°�ť˲�䣬������ӽ���ǰͶ������߼����| |tick|number|�¼�����ʱ��| ``` world.onRelease(({ button, position }) => { console.log(`press: ${button} ${position}`) }) ``` > [!TIP|style:flat] ��ʾ��Box3World �� Box3Player ���д������/���°�ť���¼������ǵ�������ǣ� # Entity ʵ�壺����/���� ## world.createEntity() ###### `����` ����һ����ʵ�� *[Box3Entity](box3entity.html)* ����һ�����е�ʵ�壬��ʵ������([entityQuota](#worldentityquota))�ﵽ���ޣ��򷵻� null�� ### ���� Box3EntityConfig |����|����|˵�� |------ |`config`|Partial<[Box3EntityConfig](box3entityconfig.html)>|ָ��ʵ���һ���ʼֵ| ### ����ֵ Box3Entity |����|����|˵�� |------ |Entity|[Box3Entity](box3entity.html)|����ָ������������һ����ʵ��| > [!TIP|style:flat] ��Ҫ��ǰ�ڱ༭��������'��'��ģ�͡�
���Ӻ�����ڵ�ͼ��ɾ�� (ֻ��ȷ�� ����-�ļ� ``` /* �ڵ�ͼ�������λ�ô���50�仨��*/ for(let i=0;i<50;i++){ world.createEntity({ mesh:'mesh/��.vb', position:new Box3Vector3(64+ 10*Math.random(), 9, 64 + 10*Math.random()), meshScale:new Box3Vector3(0.1, 0.1, 0.1), collides:false, fixed:true, gravity:false, }) } ``` ## world.entityQuota() ###### `����` ���ؽű���ǰ�Կɴ�����ʵ������ ### ����ֵ number |����|˵�� |------ |number|��ǰ�Կɴ�����ʵ������| ``` // �ڿ���̨���Ŀǰ�����Դ�����ʵ������ console.log(`�����Դ��� ${world.entityQuota()} ��ʵ��`) ``` ## world.onEntityCreate() ###### `�¼�` ��ʵ�屻����ʱ���� - **onEntityCreate**: *[Box3EventChannel](box3eventchannel.html)<[Box3EntityEvent](box3entityevent.html)>* - **nextEntityCreate**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3EntityEvent](box3entityevent.html)>* ### ����ֵ Box3EntityEvent:{ entity, tick } |����|����|˵�� |------ |entity|[Box3Entity](box3entity.html)|��������ʵ��| |tick|number|�¼�����ʱ��| ``` // ����ҵ�ʵ�屻����ʱ���㲥һ����Ϣ world.onEntityCreate(({ entity }) => { if (entity.isPlayer) { return } // ���ʵ����������������� entity.say(`���� ${entity.id}���������λ�ã�${JSON.stringify(entity.position)}`) }) ``` ## world.onEntityDestroy() ###### `�¼�` ��ʵ�屻����ʱ���� - **onEntityDestroy**: *[Box3EventChannel](box3eventchannel.html)<[Box3EntityEvent](box3entityevent.html)>* - **nextEntityDestroy**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3EntityEvent](box3entityevent.html)>* ### ����ֵ Box3EntityEvent:{ entity, tick } |����|����|˵�� |------ |entity|[Box3Entity](box3entity.html)|���ٵ�ʵ��| |tick|number|�¼�����ʱ��| ``` // ӵ�� 'box' ��ǩ��ʵ�屻����ʱ���㲥һ����Ϣ world.onEntityDestroy(({ entity }) => { if (entity.isPlayer || !entity.hasTag('box')) return; // ���ʵ����������ͣ����Ҳ�����'box'��ǩ������ world.say(`${entity.id} �ѱ����١�`) }) ``` # Battle & Health ս��������ֵ ��ʵ�忪���������˺�������[`(enableDamage = true)`](box3entity.html#enableDamage)������ͨ��[`hurt()`](box3entity.html#hurt)�����Ը�ʵ���������ֵ�˺��� **�˺�**: ʵ���ܵ��˺����ᴥ��[`onTakeDamage()`](box3entity.html#onTakeDamage)�¼���
**����**: ʵ������ֵ[`HP`](box3entity#hp)��Ϊ0����ʱ��ʵ�彫���������¼� [`onDie()`](box3entity.html#onDie), ���ز���
**����**: ʵ�������󣬿�ͨ����������ֵ[`HP`](box3entity.html#hp)����ʵ����и��ͬʱ����[`onRespawn()`](box3entity.html#onRespawn)�¼���
**ǿ������**: ���ʵ������Ϊ��ң�������ͨ��[`forceRespawn()`](box3player.html#forceRespawn)������ʹ���ǿ������������[������](box3player.html#spawnPoint)�� ## world.onTakeDamage() ###### `�¼�` ��ʵ���ܵ��˺�ʱ������ - **onTakeDamage**: *[Box3EventChannel](box3eventchannel.html)<[Box3DamageEvent](box3damageevent.html)>* - **nextTakeDamage**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3DamageEvent](box3damageevent.html)>* ### ����ֵ Box3DamageEvent:{ entity, attacker, damage, damageType, tick } |����|����|˵�� |------ |attacker|[Box3Entity](box3entity.html) | null|������| |damage|number|�˺�ֵ| |damageType|string|�˺�����| |entity|[Box3Entity](box3entity.html)|�ܵ��˺���ʵ��| |tick|number|�¼�����ʱ��| ``` /* �ܵ��˺�ʱ������ҷ���˽�ţ���ʾս����Ϣ */ world.onTakeDamage(({ entity, attacker, damage}) => { if (!entity.isPlayer) return; const attackerName = attacker.isPlayer ? attacker.player.name : attacker.id; entity.player.directMessage(`[ʣ��HP: ${entity.hp}]: ���ܵ��� ${damage} ������ ${attackerName} ���˺�`); }); ``` ## world.onDie() ###### `�¼�` ��ʵ������ʱ������ - **onDie**: *[Box3EventChannel](box3eventchannel.html)<[Box3DieEvent](box3dieevent.html)>* - **nextDie**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3DieEvent](box3dieevent.html)>* ### ����ֵ Box3DieEvent:{ entity, attacker, damageType, tick } |����|����|˵�� |------ |attacker|[Box3Entity](box3entity.html) | null|��ɱ��| |damageType|string|�˺�����| |entity|[Box3Entity](box3entity.html)|������ʵ��| |tick|number|�¼�����ʱ��| ��ʾ�� ����5�������
// һ����ұ�������һ�ɱʱ���㲥һ����Ϣ
world.onDie(({ entity, attacker }) => {
    if (!attacker || !entity.isPlayer) return;
    world.say(`${attacker.player.name}��ɱ��${entity.player.name}`);

});

��ʾ��

// һ����ұ�������һ�ɱʱ���㲥һ����Ϣ
world.onDie(({ entity, attacker }) => {
    if (!attacker || !entity.isPlayer) return;
    world.say(`${attacker.player.name}��ɱ��${entity.player.name}`);

});

����5�������

// �������ʱ���ȴ�5��󸴻 
world.onDie(async({ entity }) => { // �ȴ��¼���Ҫ�� async
    if (!entity.isPlayer) return;  // ����������ҵ������¼�

    for (let t = 1; t <= 5; t++) {
        entity.player.directMessage(`����ʱ ${String(5 - t)} ��󸴻�`);
        await sleep(1000);
    }

    entity.player.forceRespawn();  // ���������
});
``` // һ����ұ�������һ�ɱʱ���㲥һ����Ϣ world.onDie(({ entity, attacker }) => { if (!attacker || !entity.isPlayer) return; world.say(`${attacker.player.name}��ɱ��${entity.player.name}`); }); ``` ### ����5������� ## world.onRespawn() ###### `�¼�` ��ʵ�帴��ʱ������ - **onRespawn**: *[Box3EventChannel](box3eventchannel.html)<[Box3RespawnEvent](box3respawnevent.md)>* - **nextRespawn**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3RespawnEvent](box3respawnevent.md)>* ### ����ֵ Box3RespawnEvent:{ entity, tick } |����|����|˵�� |------ |entity|[Box3Entity](box3entity.html)|������ʵ��| |tick|number|�¼�����ʱ��| ``` // ��Ҹ���ʱ���㲥һ����Ϣ world.onRespawn(({ entity }) => { if (!entity.isPlayer) return; world.say(`${entity.player.name} ������`); }); ``` > [!TIP|style:flat] Box3World �� Box3Entity ӵ����ͬ�Ĵ����¼��� ���ǵ������� # Zones ���� ## world.addZone() ###### `����` ����һ���������ڼ��ʵ�������뿪ij������ Ҳ�����������û����������������ꡢ�졢ѩ���硢�����ȶ��������ڵĻ��������� ### ���� Box3ZoneConfig |����|����|˵�� |------ |`config`|Partial?[Box3ZoneConfig](box3zoneconfig.html)?|ָ�������һ���ʼ����ֵ| ### ����ֵ Box3Zone |����|����|˵�� |------ |Box3Zone|[Box3Zone](box3zone.html)|����| ``` // ���Ӽ����ҽ�����뿪 x:48-64, y:8-20, z: 50-72 ������ const area = world.addZone({ selector: 'player', bounds: { lo: [48, 8, 50], hi: [64, 20, 72], }, }) // ����ҽ������� area.onEnter(({ entity }) => { }); // ������뿪���� area.onLeave(({ entity }) => { }); ``` ## world.removeZone() ###### `����` ɾ������ ### ���� zone |����|����|˵�� |------ |`zone`|[Box3Zone](box3zone.html)|Ҫɾ��������| ``` // ���Ӽ����ҽ�����뿪 x:0-64, y:0-20, z: 0-64 ������ const area = world.addZone({ selector: 'player', bounds: { lo: [40, 8, 40], hi: [72, 20, 72], }, }) // ɾ������'area' world.removeZone(area); ``` ## world.zones() ###### `����` �������е������б� ### ����ֵ Box3Zone[] |����|����|˵�� |------ |Box3Zone[]|[Box3Zone](box3zone.html)|���е�����| ``` // ɾ���������������� const allZones = world.zones(); allZones.forEach((zone) => { world.removeZone(zone); }) ``` # Search ���� Box3����������jQueryѡ�������﷨������ijЩʵ�塣 - ����ȫ��: `'*'` - ��������: `'#id'` - ������ǩ: `'.tag'` - ����ͬʱ���������ǩ: `'.tag1 .tag2'` - �������: `'player'` ## world.querySelector() ###### `����` �������������ĵ�һ��ʵ�塣 ### ���� selector |����|����|˵�� |------ |`selector`|[Box3SelectorString](box3selectorstring.html)|һ��ѡ��������ģʽ��| ### ����ֵ Box3Entity | null |����|����|˵�� |------ |Entity|[Box3Entity](box3entity.html)|����ѡ�������׸�ʵ��| ��ʾ�� ʾ������2
const thePoint = world.querySelector('#������-1'); // ����ģ������Ϊ"������-1"���׸�ʵ��

��ʾ��

const thePoint = world.querySelector('#������-1'); // ����ģ������Ϊ"������-1"���׸�ʵ��

ʾ������2

const thePoint = world.querySelector('#������-1');

// ����ҳ�����������ģ�͵�λ��
world.onPlayerJoin(({ entity }) => {  
    entity.player.spawnPoint.copy(thePoint.position)
});
``` const thePoint = world.querySelector('#������-1'); // ����ģ������Ϊ"������-1"���׸�ʵ�� ``` ### ʾ������2 ## world.querySelectorAll() ###### `����` ������������������ʵ�壬����һ���б��� ### ���� selector |����|����|˵�� |------ |`selector`|[Box3SelectorString](box3selectorstring.html)|һ��ѡ��������ģʽ| ### ����ֵ Box3Entity[] |����|����|˵�� |------ |Entity[]|[Box3Entity](box3entity.html)|����ѡ������ȫ��ʵ��| ��ʾ�� �����������
const entities = world.querySelectorAll('*');  // ���������е�ȫ��ʵ��
const players = world.querySelectorAll('player'); // ������ͼ�е�ȫ�����
const boxes = world.querySelectorAll('.����'); // ��������"����"��ǩ��ȫ��ʵ��
const redBoxes = world.querySelectorAll('.���� .��ɫ'); // ����ͬʱ����"����"��"��ɫ"��ǩ��ȫ��ʵ��

��ʾ��

const entities = world.querySelectorAll('*');  // ���������е�ȫ��ʵ��
const players = world.querySelectorAll('player'); // ������ͼ�е�ȫ�����
const boxes = world.querySelectorAll('.����'); // ��������"����"��ǩ��ȫ��ʵ��
const redBoxes = world.querySelectorAll('.���� .��ɫ'); // ����ͬʱ����"����"��"��ɫ"��ǩ��ȫ��ʵ��

�����������

// ����������ڿ���̨�����ǰ������ҵ�����״̬
world.onRelease(({ button }) => {
    if (button === 'action0'){
        world.querySelectorAll('player').forEach((user)=>{
            console.log(`${user.player.name} : ${user.hp}`)
        })
        console.log('---------------------------')
    }
})
``` const entities = world.querySelectorAll('*'); // ���������е�ȫ��ʵ�� const players = world.querySelectorAll('player'); // ������ͼ�е�ȫ����� const boxes = world.querySelectorAll('.����'); // ��������"����"��ǩ��ȫ��ʵ�� const redBoxes = world.querySelectorAll('.���� .��ɫ'); // ����ͬʱ����"����"��"��ɫ"��ǩ��ȫ��ʵ�� ``` ### ����������� > [!TIP|style:flat] querySelector �� querySelectorAll ����������
querySelector ## world.searchBox() ###### `����` ����ָ����Χ�е�ȫ��ʵ�� ### ���� bounds |����|����|˵�� |------ |`bounds`|[Box3Bounds3](box3bounds3.html)|Ҫ�����ķ�Χ�߽�| ### ����ֵ Box3Entity[] |����|����|˵�� |------ |Entity[]|[Box3Entity](box3entity.html)|��Χ�ڵ�ȫ��ʵ��| ``` // ������Χ { x: 48-72, y:8-20, z: 48-72 } const bounds = new Box3Bounds3(new Box3Vector3(48, 8, 48), new Box3Vector3(72, 20, 72)); // ʹ�� forEach ����ʵ���б��������ҵ����ơ� world.searchBox(bounds).forEach( (entityInBounds) => { // ���������� if (entityInBounds.isPlayer) { console.log(`�������ڵ���ң�${entityInBounds.player.name}`) } }); ``` ## world.raycast() ###### `����` ���߼�⣬�� **origin**ԭ��λ���� **direction** ����Ͷ��һ�����ε����ߣ�����������ʵ��򷽿顣 ### ���� origin, direction, options |����|����|˵�� |------ |`origin`|[Box3Vector3](box3vector3.html)|**����**�����ߵ����| |`direction`|[Box3Vector3](box3vector3.html)|**����**�����ߵķ���| |`options`|[Box3RaycastOptions](box3raycastoptions.html)|��ѡ��ѡ�����ò���| ### ����ֵ Box3RaycastResult |����|����|˵�� |------ |origin|[Box3Vector3](box3vector3.html)|���ߵ����| |direction|[Box3Vector3](box3vector3.html)|���ߵķ���| |distance|number|���ߴ�Խ�ľ���| |hit|boolean|���Ϊ�棬�����߻�����Ŀ��| |hitEntity|[Box3Entity](box3entity.html) | null|���������е�ʵ��| |hitPosition|[Box3Vector3](box3vector3.html)|���߻��е�λ��| |hitVoxel|number|���������еķ��� id (��δ���з��飬��Ϊ 0)| |voxelIndex|[Box3Vector3](box3vector3.html)|������߻��е��Ƿ��飬�򷵻������з�����������ꡣ| |normal|[Box3Vector3](box3vector3.html)|����������ƽ��ķ�����| ``` /* ��������������λ������·���һ�����ߣ��ڿ���̨�������� */ world.onPress(({ button, entity }) => { if(button === 'action0'){ const res = world.raycast( entity.position, new Box3Vector3(0,-1,0)) console.log(JSON.stringify(res)) } }) ``` # Physics ������� ?? ## world.gravity ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`-0.1` ������������Ӧ�༭���˵� **[����-����-��������]** �ؼ����ԡ�
��ֵԽС���ж�Խ���ء�������Ӱ�������Ե���������Ծ�߶ȼ������ٶȡ����������ֵ����0������ʵ�ַ������� ``` /* Example��������������л���������*/ // ʹ�ñ�������¼������ת��״̬�� let toggleGravity = false // ����������¼� world.onPress(({ button }) => { // ��������� if (button === Box3ButtonType.ACTION0) { // �л�����״̬ // true���false, false���true. toggleGravity = !toggleGravity // �޸�������ֵ // ���true, �������������false���ָ�Ĭ�������� world.gravity = toggleGravity ? -0.5 * world.gravity : -0.1 // ������ṩ���� world.say(`����״̬: ${toggleGravity ? '����' : '����'}`) } }); ``` ## world.airFriction ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`0.001` ������������Ӧ�༭���˵� **[����-�ٶ�����]** �ؼ����ԡ�
��ֵ��0-1֮�䡣��ֵԽ�����߼��ٶ�ԽС����������ģ����Ļ����� ## world.onEntityContact() ###### `�¼�` ��ʵ����ʵ�巢����ײʱ������ - **onEntityContact**: *[Box3EventChannel](box3eventchannel.html)<[Box3EntityContactEvent](box3entitycontactevent.html)>* - **nextEntityContact**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3EntityContactEvent](box3entitycontactevent.html)>* ### ����ֵ Box3EntityContactEvent:{ entity, other, force, axis, tick } |����|����|˵�� |------ |entity|[Box3Entity](box3entity.html)|��ײ�еĵ�һ��ʵ��| |other|[Box3Entity](box3entity.html)|��ײ�еĵڶ���ʵ��| |force|[Box3Vector3](box3vector3.html)|��ײ����������| |axis|[Box3Vector3](box3vector3.html)|��ײ�����嵯�ɵķ���| |tick|number|�¼�����ʱ��| ��ʾ�� ����ָ��ʵ���Ѫ ����ʵ�����
/* ����ʵ�������ײʱ���㲥һ����Ϣ */
world.onEntityContact(({ entity, other }) => {
    const entityA = entity.isPlayer ? entity.player.name : entity.id;
    const entityB = other.isPlayer ? other.player.name : other.id;
    world.say(`${entityA}��${entityB}�����˼��ҵ���ײ`)
});

��ʾ��

/* ����ʵ�������ײʱ���㲥һ����Ϣ */
world.onEntityContact(({ entity, other }) => {
    const entityA = entity.isPlayer ? entity.player.name : entity.id;
    const entityB = other.isPlayer ? other.player.name : other.id;
    world.say(`${entityA}��${entityB}�����˼��ҵ���ײ`)
});

����ָ��ʵ���Ѫ

/* ����������� 'healpoint' ��ǩ��ʵ�壬�ظ�ȫ��HP */
world.onEntityContact(({ entity, other }) => {
    if (!entity.isPlayer || !other.hasTag('healpoint')) return;
    if (entity.hp < entity.maxHp) { // �ָ�ȫ��HP
        entity.hp = entity.maxHp;
        entity.player.directMessage('��ظ���ȫ����HP');
    }
});

����ʵ�����

/* �������ʵ��ʱ�����������ʵ������� */
world.onEntityContact(({ entity, other }) => {
    if (entity.isPlayer && !other.isPlayer) {
        fakeObject(entity, other);
    }
});

function fakeObject(player, object) {
    player.mesh = object.mesh;
    player.meshOrientation = object.meshOrientation;
    player.meshScale = object.meshScale;
    player.player.showName = false;
}
``` /* ����ʵ�������ײʱ���㲥һ����Ϣ */ world.onEntityContact(({ entity, other }) => { const entityA = entity.isPlayer ? entity.player.name : entity.id; const entityB = other.isPlayer ? other.player.name : other.id; world.say(`${entityA}��${entityB}�����˼��ҵ���ײ`) }); ``` ### ����ָ��ʵ���Ѫ ``` /* �������ʵ��ʱ�����������ʵ������� */ world.onEntityContact(({ entity, other }) => { if (entity.isPlayer && !other.isPlayer) { fakeObject(entity, other); } }); function fakeObject(player, object) { player.mesh = object.mesh; player.meshOrientation = object.meshOrientation; player.meshScale = object.meshScale; player.player.showName = false; } ``` > [!TIP] ����ʵ��սӴ��ĵ�һ�£�����onEntityContact ## world.onEntitySeparate() ###### `�¼�` ʵ����ʵ�������ײʱ������ - **onEntitySeparate**: *[Box3EventChannel](box3eventchannel.html)<[Box3EntityContactEvent](box3entitycontactevent.html)>* - **nextEntitySeparate**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3EntityContactEvent](box3entitycontactevent.html)>* #### ����ֵ Box3EntityContactEvent:{entity, other, force, axis, tick} |����|����|˵�� |------ |entity|[Box3Entity](box3entity.html)|��ײ�еĵ�һ��ʵ��| |other|[Box3Entity](box3entity.html)|��ײ�еĵڶ���ʵ��| |force|[Box3Vector3](box3vector3.html)|��ײ����������| |axis|[Box3Vector3](box3vector3.html)|��ײ�����嵯�ɵķ���| |tick|number|�¼�����ʱ��| ``` // ʵ�忪ʼ��ײ world.onEntityContact(({ entity, other }) => { console.log('��ʼ��ײ') }) // ʵ��ֹͣ��ײ world.onEntitySeparate(({ entity, other }) => { console.log('ֹͣ��ײ') }) ``` ## world.onVoxelContact() ###### `�¼�` ��ʵ���뷽�鷢����ײʱ������ - **onVoxelContact**: *[Box3EventChannel](box3eventchannel.html)<[Box3VoxelContactEvent](box3voxelcontactevent.html)>* - **nextVoxelContact**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3VoxelContactEvent](box3voxelcontactevent.html)>* ### ����ֵ Box3VoxelContactEvent:{ entity, voxel, x, y, z, force, axis, tick } |����|����|˵�� |------ |entity|[Box3Entity](box3entity.html)|���������ʵ��| |voxel|number|�������ķ��� id| |x|number|����������� x ����| |y|number|����������� y ����| |z|number|����������� z ����| |force|[Box3Vector3](box3vector3.html)|��ײ����������| |axis|[Box3Vector3](box3vector3.html)|��ײ�����嵯�ɵķ���| |tick|number|�¼�����ʱ��| �ƻ������ı��� �����µķ���
/* ���ʵ���������飬����ᱻ���� */
world.onVoxelContact(({ x, y, z, voxel }) => {
    const voxelName = voxels.name(voxel);  // ������idת������
    if (voxelName === 'ice'){              // ������������DZ���
        voxels.setVoxel(x, y, z, 0);       // �������ɿ���
    }
});

�ƻ������ı���

/* ���ʵ���������飬����ᱻ���� */
world.onVoxelContact(({ x, y, z, voxel }) => {
    const voxelName = voxels.name(voxel);  // ������idת������
    if (voxelName === 'ice'){              // ������������DZ���
        voxels.setVoxel(x, y, z, 0);       // �������ɿ���
    }
});

�����µķ���

// �����ҽ��µķ����Ƿ�Ϊʯͷ
world.onVoxelContact(({ entity, voxel, axis }) => {
    if (!entity.isPlayer) return;                 // �����������IJ�����ң�������
    const voxelName = voxels.name(voxel);         // ������idת������
    if (voxelName === 'stone' && axis.y === 1){   // �������������ʯͷ������������·�
        console.log(`${entity.player.name} ���²��� ${voxelName} ����`)
    }
});
``` /* ���ʵ���������飬����ᱻ���� */ world.onVoxelContact(({ x, y, z, voxel }) => { const voxelName = voxels.name(voxel); // ������idת������ if (voxelName === 'ice'){ // ������������DZ��� voxels.setVoxel(x, y, z, 0); // �������ɿ��� } }); ``` ### �����µķ��� ## world.onVoxelSeparate() ###### `�¼�` ��ʵ���뷽�������ײʱ������ - **onVoxelSeparate**: *[Box3EventChannel](box3eventchannel.html)<[Box3VoxelContactEvent](box3voxelcontactevent.html)>* - **nextVoxelSeparate**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3VoxelContactEvent](box3voxelcontactevent.html)>* ### ����ֵ Box3VoxelContactEvent:{ entity, voxel, x, y, z, force, axis, tick } |����|����|˵�� |------ |entity|[Box3Entity](box3entity.html)|���������ʵ��| |voxel|number|�������ķ��� id| |x|number|����������� x ����| |y|number|����������� y ����| |z|number|����������� z ����| |force|[Box3Vector3](box3vector3.html)|��ײ����������| |axis|[Box3Vector3](box3vector3.html)|��ײ�����嵯�ɵķ���| |tick|number|�¼�����ʱ��| ``` // ʵ��Ӵ������� world.onVoxelContact(({ entity, voxel }) => { console.log('��ײ������') }) // ʵ��ֹͣ�Ӵ����� world.onVoxelSeparate(({ entity, voxel }) => { console.log('ֹͣ��ײ') }) ``` ## world.onFluidEnter() ###### `�¼�` ��ʵ�����ˮ��/Һ��ʱ������ - **onFluidEnter**: *[Box3EventChannel](box3eventchannel.html)<[Box3FluidContactEvent](box3voxelcontactevent.html)>* - **nextFluidEnter**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3FluidContactEvent](box3voxelcontactevent.html)>* ### ����ֵ Box3FluidContactEvent:{ entity, voxel, tick } |����|����|˵�� |------ |entity|[Box3Entity](box3entity.html)|����Һ���ʵ��| |voxel|number|������Һ�巽��| |tick|number|�¼�����ʱ��| ``` // ����ҽӴ���Һ��ʱ���ڿ���̨��ʾ��ҵ����� world.onFluidEnter(({ entity, voxel})=>{ if (!entity.isPlayer) return; const voxelName = voxels.name(voxel); console.log(`${entity.player.name} ������ ${voxelName}`) }) ``` ## world.onFluidLeave() ###### `�¼�` ��ʵ���뿪ˮ��/Һ��ʱ������ - **onFluidLeave**: *[Box3EventChannel](box3eventchannel.html)<[Box3FluidContactEvent](box3voxelcontactevent.html)>* - **nextFluidLeave**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3FluidContactEvent](box3voxelcontactevent.html)>* ### ����ֵ Box3FluidContactEvent:{ entity, voxel, tick } |����|����|˵�� |------ |entity|[Box3Entity](box3entity.html)|����Һ���ʵ��| |voxel|number|������Һ�巽��| |tick|number|�¼�����ʱ��| ``` // ʵ��Ӵ���Һ��ʱ world.onFluidEnter(({ entity, voxel}) => { console.log('�Ӵ���Һ��') }) // ʵ���뿪Һ��ʱ world.onFluidLeave(({ entity, voxel}) => { console.log('ֹͣ�Ӵ�Һ��') }) ``` ## world.addCollisionFilter() ###### `����` ������ײ���������ر�����ʵ����֮�����ײ����������ʵ����ֱ���[ѡ����](box3selectorstring.html)`aSelector`��`bSelector`�����壬�ɰ�ʵ�����ơ���ǩ���Լ��Ƿ���ҵ�������ɸѡ�� ### ���� |����|����|˵�� |------ |`aSelector`|[Box3SelectorString](box3selectorstring.html)|���ڶ����һ��ʵ���ѡ����| |`bSelector`|[Box3SelectorString](box3selectorstring.html)|���ڶ���ڶ���ʵ���ѡ����| ### ����ֵ void ``` // �ر���Һ����֮�����ײ world.addCollisionFilter('player','player'); // �ر���Һʹ�'groupA'��ǩ��ʵ��֮�����ײ world.addCollisionFilter('.groupA','player'); // �ر���Һ���Ϊ'entity1'��ʵ��֮�����ײ world.addCollisionFilter('#entity1','player'); // �ر�ȫ��ʵ��֮�����ײ world.addCollisionFilter('*','*'); ``` ## world.removeCollisionFilter() ###### `����` �Ƴ���ײ�����������ٹر�����ʵ����`aSelector`��`bSelector`֮�����ײ�� ### ���� |����|����|˵�� |------ |`aSelector`|[Box3SelectorString](box3selectorstring.html)|���ڶ����һ��ʵ���ѡ����| |`bSelector`|[Box3SelectorString](box3selectorstring.html)|���ڶ���ڶ���ʵ���ѡ����| ### ����ֵ void ``` // �Ƴ���Һ����֮�����ײ������ remove collision filter for player & player world.removeCollisionFilter('player','player'); // �Ƴ���Һʹ�'groupA'��ǩ��ʵ��֮�����ײ������ remove collision filter for player & entity with tag named groupA world.removeCollisionFilter('.groupA','player'); // �Ƴ���Һ���Ϊ'entity1'��ʵ��֮�����ײ������ remove collision filter for player & specific entity with id named entity1 world.removeCollisionFilter('#entity1','player'); ``` ## world.clearCollisionFilters() ###### `����` ���ȫ����ײ�������� ### ����ֵ void ``` // �����ǰ��ȫ����ײ������ remove all current collision filters world.clearCollisionFilters() ``` ## world.collisionFilters() ###### `����` ���ص�ǰ��Ч��ȫ����ײ�������� Returns a list of all currently active collision filters ### ����ֵ string[][] |����|˵�� |------ |string[][]|��ǰ��Ч��ȫ����ײ������| ``` // ��ӡȫ����ײ������ print all collision filters world.collisionFilters().forEach(([ a, b ]) => console.log(a, b)); ``` ## world.testSelector() ###### `����` ����ʵ���Ƿ����ij��[ѡ����(Selector)](box3selectorstring.html)�������� Test a selector on an entity. ### ���� |����|����|˵�� |------ |`selector`|[Box3SelectorString](box3selectorstring.html)|Ҫ���Ե�ѡ����| |`entity`|[Box3Entity](box3entity.html)|Ҫ���Ե�ʵ��| ### ����ֵ boolean |����|˵�� |------ |boolean|`true`: ʵ�����ѡ����������; `false`: ʵ�岻����ѡ����������| ��ʾ�� ʾ������2
const e1 = world.createEntity({
    mesh:'mesh/��.vb',
    position:new Box3Vector3(64, 9, 64),
    meshScale:new Box3Vector3(0.1, 0.1, 0.1),
    collides:true,
    fixed:true,
});
e1.addTag('groupA');

// can use to test entity selectable with a tag
if (world.testSelector('.groupA', e1)) { 
    // ���������ij��ִ�д���
    }

��ʾ��

const e1 = world.createEntity({
    mesh:'mesh/��.vb',
    position:new Box3Vector3(64, 9, 64),
    meshScale:new Box3Vector3(0.1, 0.1, 0.1),
    collides:true,
    fixed:true,
});
e1.addTag('groupA');

// can use to test entity selectable with a tag
if (world.testSelector('.groupA', e1)) { 
    // ���������ij��ִ�д���
    }

ʾ������2

const e1 = world.createEntity({
    id: '����',
    mesh:'mesh/��.vb',
    position:new Box3Vector3(64, 9, 64),
    meshScale:new Box3Vector3(0.1, 0.1, 0.1),
    collides:true,
    fixed:true,
});
e1.addTag('groupA');

// can use to test whether entity selectable with entity id 
if (world.testSelector('#����', e1)) {  
    // do something 
}
``` const e1 = world.createEntity({ mesh:'mesh/��.vb', position:new Box3Vector3(64, 9, 64), meshScale:new Box3Vector3(0.1, 0.1, 0.1), collides:true, fixed:true, }); e1.addTag('groupA'); // can use to test entity selectable with a tag if (world.testSelector('.groupA', e1)) { // ���������ij��ִ�д��� } ``` ### ʾ������2 # Sound ������Ч ## world.sound() ###### `����` ����һ��������������Ҷ�����������[�ļ�����]�������½�[�ϴ���Ƶ]��ͨ�� `.sound()`�������������ļ���·���� ### ���� spec | string |����|����|˵�� |------ |sample|string|**����**�������ļ�·���������ļ����������ϴ��Զ����������� `'audio/chat.mp3'`| |gain|number|��ѡ���������档����Ϊ 1����ֵԽ������Խ�졣| |position|[Box3Vector3](box3vector3.html)|��ѡ���������ŵ�λ�á�����ָ����ij��ʵ�����Ϸ���������| |radius|number|��ѡ��������Χ��Ĭ��Ϊ 32���� 2 �񷽿���롣������Χ�������������������| |pitch|number|��ѡ���������档����Ϊ 1������ 1����������Խ�죬С�� 1����������Խ����| ��ʾ�� ʾ������2
// ����һ��������������Ҷ�������
world.sound('audio/drama.mp3');

��ʾ��

// ����һ��������������Ҷ�������
world.sound('audio/drama.mp3');

ʾ������2

// ��ָ����λ�ò��� 'airhorn' ����
world.sound({
    sample: 'audio/airhorn.mp3',
    position: new Box3Vector3(64, 10, 64),
    radius: 64  // ֻ�о���λ��64�뾶�������������(1������ľ�����16)
})
``` // ����һ��������������Ҷ������� world.sound('audio/drama.mp3'); ``` ### ʾ������2 > [!TIP|style:flat] ���� world.sound() Box3����Ԥ����һЩ�������ԣ��ڶ�Ӧ���¼�����ʱ������Ч�� ����ͼ��ʼ����ʱѭ�����ŵ�[��������](#worldambientsound)��
������[��ҽ���/�뿪��ͼʱ](#worldplayerjoinsound)ʱ���ŵ���Ч��
������[���鱻����/�ƻ�](#worldplacevoxelsound)ʱ���ŵ���Ч�� ## world.ambientSound ###### `����` ??? ����ֵ���ͣ�`new Box3SoundEffect()` ??? Ĭ��ֵ��`''` �ı��ͼ�������֣��ӵ�ͼ���п�ʼѭ�����š�
�������ֵ�����������û���[����-����]���ġ� ``` // ��������������Ϊ������ world.ambientSound.sample = 'audio/rain.mp3'; ``` ## world.playerJoinSound ###### `����` ??? ����ֵ���ͣ�`new Box3SoundEffect()` ??? Ĭ��ֵ��`''` ����ҽ����ͼʱ�����ŵ���Ч��ͨ��[world.onPlayerJoin()](#worldonplayerjoin)������ ## world.playerLeaveSound ###### `����` ??? ����ֵ���ͣ�`new Box3SoundEffect()` ??? Ĭ��ֵ��`''` ������뿪��ͼʱ�����ŵ���Ч��ͨ��[world.onPlayerLeave()](#worldonplayerleave)������ ## world.placeVoxelSound ###### `����` ??? ����ֵ���ͣ�`new Box3SoundEffect()` ??? Ĭ��ֵ��`'audio/place_block.mp3'` ���鱻����ʱ�����ŵ���Ч��ͨ��[Box3Voxels.setVoxel()](box3voxels.html#setvoxel)������Ĭ����ЧΪ `'audio/place_block.mp3'` ## world.breakVoxelSound ###### `����` ??? ����ֵ���ͣ�`new Box3SoundEffect()` ??? Ĭ��ֵ��`'audio/break_block.mp3'` ���鱻����ʱ�����ŵ���Ч��ͨ��[Box3Voxels.setVoxel()](box3voxels.html#setvoxel)������Ĭ����ЧΪ `'audio/break_block.mp3'` # Weather �������� ## world.maxFog ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`1` �����������Ӧ�༭���˵� **[����-ȫ����Ч-����-�������]** �ؼ����ԡ� ## world.fogColor ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`new Box3RGBColor(1, 1, 1)` ������ɫ����Ӧ�༭���˵� **[����-ȫ����Ч-����-��ɫ]** �ؼ����ԡ� ## world.fogStartDistance ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`0` - **fogStartDistance**: number = 0 ����ʼ���롣��Ӧ�༭���˵� **[����-ȫ����Ч-����-��ʼ����]** �ؼ����ԡ� ## world.fogHeightOffset ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`0` ����ʼ�߶ȡ���Ӧ�༭���˵� **[����-ȫ����Ч-����-�߶�]** �ؼ����ԡ� ## world.fogUniformDensity ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`0` �������ܶȣ���Ӧ�༭���˵� **[����-ȫ����Ч-����-��������]** �ؼ����ԡ�
��ֵ����0��Խ�ѿ�����ա� ## world.fogHeightFalloff ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`0.8` ��˥�������ʡ���Ӧ�༭���˵� **[����-ȫ����Ч-����-�߶�˥��ϵ��]** �ؼ����ԡ�
��ֵ��0-1֮�䡣ֵԽС����ԽŨ�� ``` // ����һƬ��ɫ��Ũ�� world.maxFog = 1; // ������� world.fogColor = new Box3RGBColor(1, 1, 1); // ��ɫ world.fogHeightOffset = -0.5; // �߶� world.fogStartDistance = 6; // ��ʼ���� world.fogUniformDensity = 1; // �����ܶ� world.fogHeightFalloff = 1; // ˥������ ``` # Weather �������� ## world.rainSpeed ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`1` ����ٶȡ���Ӧ�༭���˵� **[����-ȫ����Ч-��-�ٶ�]** �ؼ����ԡ� ## world.rainColor ###### `����` ??? ����ֵ���ͣ�`Box3RGBAColor` ??? Ĭ��ֵ��`new Box3RGBAColor(1, 1, 1, 1)` �����ɫ����Ӧ�༭���˵� **[����-ȫ����Ч-��-��ɫ]** �ؼ����ԡ� ## world.rainDirection ###### `����` ??? ����ֵ���ͣ�`Box3Vector3` ??? Ĭ��ֵ��`new Box3Vector3(0, 1, 0)` ��ķ��򡣶�Ӧ�༭���˵� **[����-ȫ����Ч-��-����]** �ؼ����ԡ� ## world.rainDensity ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`0` ����ܶȡ���Ӧ�༭���˵� **[����-ȫ����Ч-��-�ܶ�]** �ؼ����ԡ�
�ܶ�Խ�����Խ�ࡣ ## world.rainInterference ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`0` ����Ŷ����ȡ���Ӧ�༭���˵� **[����-ȫ����Ч-��-��������]** �ؼ����ԡ� ## world.rainSizeLo ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`0` ��ε���Сֱ���� ## world.rainSizeHi ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`1` ��ε����ֱ���� ``` /* ������㣬ģ��ө������ij��� */ world.rainDensity = 0.25; // ����ܶ� world.rainDirection = new Box3Vector3(0, -1, 0); // ���� world.rainColor = new Box3RGBAColor(0.98, 0.89, 0.12, 0.4); // ��ɫ world.rainSpeed = 0.15; // �ٶ� world.rainSizeLo = 0.01; // �����Сֱ�� world.rainSizeHi = 0.03; // ������ֱ�� world.rainInterference = 0.2; // �Ŷ����� ``` # Weather ������ѩ ## world.snowColor ###### `����` ??? ����ֵ���ͣ�`Box3RGBAColor` ??? Ĭ��ֵ��`new Box3RGBAColor(1, 1, 1, 1)` ѩ����ɫ�� ## world.snowTexture ###### `����` ??? ����ֵ���ͣ�`string` ??? Ĭ��ֵ��`''` ѩ���������˴���д�ļ��������е�������Դ���ơ��� `'snow/heart.part'` ``` /* ��ѩ���������ɰ��ġ�(����ǰ�ڱ༭������ѩ����) */ world.snowTexture = 'snow/heart.part' ``` ## world.snowDensity ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`0` ѩ���ܶȡ��ܶ�Խ��ѩ��Խ�ࡣ ## world.snowFallSpeed ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`1` ѩ�������ٶȡ����С��0�������˶��� ## world.snowSpinSpeed ###### `����` ??? ����ֵ���ͣ�`Box3Vector3` ??? Ĭ��ֵ��`new Box3Vector3(0, 0, 0)` ѩ�������ٶȡ� ## world.snowSizeLo ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`0` ѩ����Сֱ���� ## world.snowSizeHi ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`1` ѩ�����뾶�� ``` /* ӣ��ѩ */ world.snowDensity = 0.4; // ѩ���ܶ� world.snowFallSpeed = 0.2; // �����ٶ� world.snowSizeLo = 0.2; // ��Сֱ�� world.snowSizeHi = 0.35; // ���ֱ�� world.snowColor = new Box3RGBAColor(0.91, 0.3, 0.53, 1); // ��ɫ world.snowTexture = 'snow/sakura.part'; // ���� ``` # Weather ����: ���� ## world.lightMode ###### `����` ??? ����ֵ���ͣ�`string` ??? Ĭ��ֵ��`'natural'` ��������պͻ�������������͡���Ӧ�༭������ **[����-�չ�-�չ����]** �ؼ����ԡ�
Ŀǰ���ṩ2�ֹ���ģʽ��'manual'(�Զ���)��'natural'(��̬)��Ĭ��Ϊ 'natural'�� ``` world.lightMod = 'natural' // ��������ģʽΪ��Ȼ world.sunFrequency = 0 // ��̫���˶�Ƶ������Ϊ0��ʹ�չⲻ����ʱ����仯�� world.sunPhase = 0.25 // ��̫��λ�õ����ڴ�Լ����12:00�� ``` ## world.sunFrequency ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`0` ̫���˶���Ƶ�ʣ���ֵԽ����ҹ����Խ�졣
��ҹʱ����㹫ʽ: `timeOfDay = (sunPhase + sunFrequency * tick) % 1` ## world.sunPhase ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`0` ??? ��Χ��`0-1` ̫�������������£�����յ�λ�á���Ӧ�༭���˵� **[����-�չ�]** �ؼ����ԡ�
��ֵ��0-1֮�䡣����0.5ʱ����������ҹ�� �����չ����Ϊ `natural` ״̬ʱ��Ч�� > [!TIP] ����̫��λ�ú�����ʱ��Ĺ�ϵ��
̫��λ�� sunPhase = 0 ## world.lunarPhase ###### `����` ??? ����ֵ���ͣ�`number` ??? Ĭ��ֵ��`0` ??? ��Χ��`0-1` ��������λ����ֵ��0��1֮�䡣������0.5ʱ��Ϊ�����¡� ## world.sunDirection ###### `����` ??? ����ֵ���ͣ�`Box3Vector3` ??? Ĭ��ֵ��`new Box3Vector3(0, -1, 0)` ̫�����������򡣽��ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч�� ## world.sunLight ###### `����` ??? ����ֵ���ͣ�`Box3RGBColor` ??? Ĭ��ֵ��`new Box3RGBColor(1000, 1000, 1000)` ̫������ɫ���ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч��
��ɫֵ����0ʱ����ɫԽ���� ``` // �Զ���̫���������Ƕȡ���ɫ���ȡ� world.lightMode = 'manual'; world.sunDirection = new Box3Vector3(0.1, -0.25, 0.05) world.sunLight = new Box3RGBColor(0.02, 1.02, 2.13); ``` ## world.skyLeftLight ###### `����` ??? ����ֵ���ͣ�`Box3RGBColor` ??? Ĭ��ֵ��`new Box3RGBColor(0, 0, 0)` ��������-X�᷽������ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч��
��ɫֵ����0ʱ����ɫԽ���� ## world.skyRightLight ###### `����` ??? ����ֵ���ͣ�`Box3RGBColor` ??? Ĭ��ֵ��`new Box3RGBColor(0, 0, 0)` ��������+X�᷽�����ɫ���ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч��
��ɫֵ����0ʱ����ɫԽ���� ## world.skyBottomLight ###### `����` ??? ����ֵ���ͣ�`Box3RGBColor` ??? Ĭ��ֵ��`new Box3RGBColor(0, 0, 0)` ��������-Y�᷽�����ɫ���ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч��
��ɫֵ����0ʱ����ɫԽ���� ## world.skyTopLight ###### `����` ??? ����ֵ���ͣ�`Box3RGBColor` ??? Ĭ��ֵ��`new Box3RGBColor(0, 0, 0)` ��������+Y�᷽�����ɫ���ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч��
��ɫֵ����0ʱ����ɫԽ���� ## world.skyFrontLight ###### `����` ??? ����ֵ���ͣ�`Box3RGBColor` ??? Ĭ��ֵ��`new Box3RGBColor(0, 0, 0)` ��������-Z�᷽�����ɫ���ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч��
��ɫֵ����0ʱ����ɫԽ���� ## world.skyBackLight ###### `����` ??? ����ֵ���ͣ�`Box3RGBColor` ??? Ĭ��ֵ��`new Box3RGBColor(0, 0, 0)` ��������+Z�᷽�����ɫ���ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч��
��ɫֵ����0ʱ����ɫԽ���� ``` /* ��������Ⱦ�ɷ�ɫ */ // �Զ���̫���������Ƕȡ���ɫ���� world.lightMode = 'manual'; world.sunLight = new Box3RGBColor(0.5, 0.5, 0.5); world.sunDirection = new Box3Vector3(0.15, -0.1, 0.25); // Y�᷽�� world.skyTopLight = new Box3RGBColor(10, 0.2, 1.5); world.skyBottomLight = new Box3RGBColor(1.5, 0.2, 10); // X�᷽�� world.skyRightLight = new Box3RGBColor(1, 0.5, 30); world.skyLeftLight = new Box3RGBColor(1, 0.5, 30); // Z�᷽�� world.skyTopLight = new Box3RGBColor(20, 0.5, 1); world.skyBottomLight = new Box3RGBColor(20, 0.5, 1); ``` # ���� ## world.animate() ###### `����` ����һ���ؼ�֡���� *[Box3Animation](box3animation.html)* �� ### ���� |����|����|˵�� |------ |`keyframes`|[Box3WorldKeyframe](box3worldkeyframe.html)[]|�ؼ�֡������| |`playbackInfo`|[Box3AnimationPlaybackConfig](box3animationplaybackconfig.html)|�������Ų���| ### ����ֵ |����|����|˵�� |------ |Animation|[Box3Animation](box3animation.html)|���������Ķ�������| ``` const ani = world.animate([ { rainDensity: 0.0 }, { rainDensity: 1.0 }, ], { iterations: Infinity,//����ѭ�� direction: Box3AnimationDirection.REVERSE,//������������С duration: 16 * 5,//5��1������(ÿ��16֡) }) world.onPress(({ button }) => { if (button === Box3ButtonType.ACTION0) {//���ͣ�� ani.cancel() world.rainDensity = 0 } }) ``` # Web��� ## world.url ###### `����` ??? ����ֵ���ͣ�[URL](url.html) ??? ��ȡ��ǰ��ͼ���ڵ�URL���ӵ�ַ�� ``` console.log(world.url) ``` # Class: Box3Zone ��������ڼ��ʵ�����ij��������뿪�� Ҳ�����������û����������������ꡢ�졢ѩ���硢�����ȶ��������ڵĻ��������� ### ���� - [bounds](box3zone.html#bounds) - [entities](box3zone.html#entities)
  • [selector](box3zone.html#selector)
  • [nextEnter](box3zone.html#nextenter)
  • - [nextLeave](box3zone.html#nextleave) - [onEnter](box3zone.html#onenter) - [onLeave](box3zone.html#onleave)
  • [remove](box3zone.html#remove)
  • [force](box3zone.html#force)
  • [massScale](box3zone.html#massscale)
  • [fogColor](box3zone.html#fogcolor)
  • - [fogDensity](box3zone.html#fogdensity) - [fogEnabled](box3zone.html#fogenabled) - [fogHeightFalloff](box3zone.html#fogheightfalloff) - [fogHeightOffset](box3zone.html#fogheightoffset) - [fogMax](box3zone.html#fogmax)
  • [fogStartDistance](box3zone.html#fogstartdistance)
  • [rainColor](box3zone.html#raincolor)
  • - [rainDensity](box3zone.html#raindensity) - [rainDirection](box3zone.html#raindirection) - [rainEnabled](box3zone.html#rainenabled) - [rainInterference](box3zone.html#raininterference) - [rainSizeHi](box3zone.html#rainsizehi) - [rainSizeLo](box3zone.html#rainsizelo)
  • [rainSpeed](box3zone.html#rainspeed)
  • [skyBackLight](box3zone.html#skybacklight)
  • - [skyBottomLight](box3zone.html#skybottomlight) - [skyEnabled](box3zone.html#skyenabled) - [skyFrontLight](box3zone.html#skyfrontlight) - [skyLeftLight](box3zone.html#skyleftlight) - [skyLunarPhase](box3zone.html#skylunarphase) - [skyMode](box3zone.html#skymode) - [skyRightLight](box3zone.html#skyrightlight) - [skySunDirection](box3zone.html#skysundirection) - [skySunFrequency](box3zone.html#skysunfrequency) - [skySunLight](box3zone.html#skysunlight) - [skySunPhase](box3zone.html#skysunphase)
  • [skyTopLight](box3zone.html#skytoplight)
  • [snowColor](box3zone.html#snowcolor)
  • - [snowDensity](box3zone.html#snowdensity) - [snowEnabled](box3zone.html#snowenabled) - [snowFallSpeed](box3zone.html#snowfallspeed) - [snowSizeHi](box3zone.html#snowsizehi) - [snowSizeLo](box3zone.html#snowsizelo) - [snowSpinSpeed](box3zone.html#snowspinspeed) - [snowTexture](box3zone.html#snowtexture) --- ### bounds ? **bounds**: *[Box3Bounds3](box3bounds3.html)??* = new Box3Bounds3( new Box3Vector3(0, 0, 0), new Box3Vector3(0, 0, 0)) ���������ָ���ļ������ --- ### entities ? **entities**: *function* �������ڵ�ȫ��ʵ��[Box3Entity](box3entity.html) #### ��������: ? (): *[Box3Entity](box3entity.html)[]* --- ### fogColor ? **fogColor**: *[Box3RGBColor](box3rgbcolor.html)??* = new Box3RGBColor(1, 1, 1) ������������ɫ --- ### fogDensity ? **fogDensity**: *number* = 0 �������������ܶ� --- ### fogEnabled ? **fogEnabled**: *boolean* = false ���������Ƿ��� **ʾ������** ``` // վ�ڵ������һƬ����, �������򲻻� world.addZone({ selector: 'player', bounds: { lo: [0, 0, 0], hi: [128, 10, 128], }, fogEnabled: true, fogColor: new Box3RGBColor(1, 0, 0), fogDensity: 0.05, }) ``` --- ### fogHeightFalloff ? **fogHeightFalloff**: *number* = 0.8 ��������˥�������� --- ### fogHeightOffset ? **fogHeightOffset**: *number* = -8 ����������ʼ�߶� --- ### fogMax ? **fogMax**: *number* = 1 ������������� --- ### fogStartDistance ? **fogStartDistance**: *number* = 0 ����������ʼ���� --- ### force ? **force**: *[Box3Vector3](box3vector3.html)??* = new Box3Vector3(0, 0, 0) ������ʩ�ӵ����Ĵ�С **ʾ������** ``` // �ѵ����ɱĴ� world.addZone({ selector: 'player', bounds: { lo: [0, 0, 0], hi: [128, 10, 128], }, force: [0, 2, 0], }) ``` --- ### massScale ? **massScale**: *number* = 0 �������������������Ӱ��̶ȡ� 0 = ������һ�� 1 = ���һ�� --- ### onEnter ### nextEnter ? **onEnter**: *[Box3EventChannel](box3eventchannel)?[box3TriggerEvent](box3triggerevent.html)?*
    ? **nextEnter**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)?[box3TriggerEvent](box3triggerevent.html)?* ��ʵ�����ָ������ʱ�������¼� --- ### onLeave ### NextLeave ? **onLeave**: *[Box3EventChannel](box3eventchannel)?[box3TriggerEvent](box3triggerevent.html)?*
    ? **nextLeave**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)?[box3TriggerEvent](box3triggerevent.html)?* ��ʵ���뿪����ʱ�����¼� **ʾ������** ``` // ���Ӽ����ҽ�����뿪 x:0-64, y:0-20, z: 0-64 ������ const area = world.addTrigger({ selector: 'player', bounds: { lo: [0, 0, 0], hi: [64, 20, 64], }, }) // ����ҽ������� area.onEnter(({ entity }) => { world.say(`${entity.player.name}����������`) }) // ������뿪���� area.onLeave(({ entity }) => { world.say(`${entity.player.name}�뿪������`) }) ``` --- ### rainColor ? **rainColor**: *[Box3RGBAColor](box3rgbacolor.html)??* = new Box3RGBAColor(1, 1, 1, 1) �����������ɫ --- ### rainDensity ? **rainDensity**: *number* = 0 ����������ܶ� �ܶ�Խ�����Խ�ࡣ --- ### rainDirection ? **rainDirection**: *[Box3Vector3](box3vector3.html)??* = new Box3Vector3(0, 1, 0) ��������ķ��� --- ### rainEnabled ? **rainEnabled**: *boolean* = false ���������Ƿ��� **ʾ������** ``` // վ�ڵ��������, �������򲻻� world.addZone({ selector: 'player', bounds: { lo: [0, 0, 0], hi: [128, 10, 128], }, rainEnabled: true, rainDensity: 0.5, rainSpeed: 0.5, }) ``` --- ### rainInterference ? **rainInterference**: *number* = 0 ����������Ŷ����� --- ### rainSizeHi ? **rainSizeHi**: *number* = 1 ��������ε����ֱ�� --- ### rainSizeLo ? **rainSizeLo**: *number* = 0 ��������ε���Сֱ�� --- ### rainSpeed ? **rainSpeed**: *number* = 1 ����������ٶ� --- ### remove ? **remove**: *function* �Ѹ�����ɾ�� #### ��������: ? (): *void* --- ### selector ? **selector**: *[Box3SelectorString](box3selectorstring.html)* = "" ���������¼��������������� --- ### skyBackLight ? **skyBackLight**: *[Box3RGBColor](box3rgbcolor.html)??* = new Box3RGBColor(0, 0, 0) �����ڻ�������+Z�᷽�����ɫ���ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч����ɫֵ����0ʱ����ɫԽ���� --- ### skyBottomLight ? **skyBottomLight**: *[Box3RGBColor](box3rgbcolor.html)??* = new Box3RGBColor(0, 0, 0) �����ھ�����-Y�᷽�����ɫ���ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч����ɫֵ����0ʱ����ɫԽ���� --- ### skyEnabled ? **skyEnabled**: *boolean* = false �����ڻ��������Ƿ���Ч **ʾ������** ``` // վ�ڵ��������ҹ�л�, �������򲻻� world.addZone({ selector: 'player', bounds: { lo: [0, 0, 0], hi: [128, 10, 128], }, skyEnabled: true, skySunFrequency: 0.03, }) ``` --- ### skyFrontLight ? **skyFrontLight**: *[Box3RGBColor](box3rgbcolor.html)??* = new Box3RGBColor(0, 0, 0) �����ڻ�������-Z�᷽�����ɫ���ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч����ɫֵ����0ʱ����ɫԽ���� --- ### skyLeftLight ? **skyLeftLight**: *[Box3RGBColor](box3rgbcolor.html)??* = new Box3RGBColor(0, 0, 0) �����ڻ�������-X�᷽������ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч����ɫֵ����0ʱ����ɫԽ���� --- ### skyLunarPhase ? **skyLunarPhase**: *number* = 0 ��������������λ����ֵ��0��1֮�䡣������0.5ʱ��Ϊ�����¡� --- ### skyMode ? **skyMode**: *"natural" | "manual"* = "natural" ��������������պͻ�������������͡�Ŀǰ���ṩ2�ֹ���ģʽ��'manual'(�Զ���)��'natural'(��̬)��Ĭ��Ϊ 'natural'�� **ʾ������** ``` // վ�ڵ�����зۺ��ȫ�ֹ���, �������򲻻� world.addZone({ selector: 'player', bounds: { lo: [0, 0, 0], hi: [128, 10, 128], }, skyEnabled: true, skyMode: 'manual', sunDirection: new Box3Vector3(0.15, -0.1, 0.25), skySunLight: new Box3RGBColor(0.5, 0.5, 0.5), skyTopLight: new Box3RGBColor(10, 0.2, 1.5), skyBottomLight: new Box3RGBColor(1.5, 0.2, 10), skyRightLight: new Box3RGBColor(1, 0.5, 30), skyLeftLight: new Box3RGBColor(1, 0.5, 30), skyTopLight: new Box3RGBColor(20, 0.5, 1), skyBottomLight: new Box3RGBColor(20, 0.5, 1), }) ``` --- ### skyRightLight ? **skyRightLight**: *[Box3RGBColor](box3rgbcolor.html)??* = new Box3RGBColor(0, 0, 0) �����ڻ�������+X�᷽�����ɫ���ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч����ɫֵ����0ʱ����ɫԽ���� --- ### skySunDirection ? **skySunDirection**: *[Box3Vector3](box3vector3.html)??* = new Box3Vector3(0, -1, 0) ������̫�����������򡣽��ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч�� --- ### skySunFrequency ? **skySunFrequency**: *number* = 0 ������̫���˶���Ƶ�ʣ���ֵԽ����ҹ����Խ�졣 --- ### skySunLight ? **skySunLight**: *[Box3RGBColor](box3rgbcolor.html)??* = new Box3RGBColor(1000, 1000, 1000) ������̫������ɫ���ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч����ɫֵ����0ʱ����ɫԽ���� --- ### skySunPhase ? **skySunPhase**: *number* = 0 ������̫�������������£�����յ�λ�á� --- ### skyTopLight ? **skyTopLight**: *[Box3RGBColor](box3rgbcolor.html)??* = new Box3RGBColor(0, 0, 0) �����ڻ�������+Y�᷽�����ɫ���ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч����ɫֵ����0ʱ����ɫԽ���� --- ### snowColor ? **snowColor**: *[Box3RGBAColor](box3rgbacolor.html)??* = new Box3RGBAColor(1, 1, 1, 1) ������ѩ����ɫ --- ### snowDensity ? **snowDensity**: *number* = 0 ������ѩ���ܶȡ��ܶ�Խ��ѩ��Խ�ࡣ --- ### snowEnabled ? **snowEnabled**: *boolean* = false ������ѩ�Ƿ��� **ʾ������** ``` // վ�ڵ����������, �������򲻻� world.addZone({ selector: 'player', bounds: { lo: [0, 0, 0], hi: [128, 10, 128], }, snowEnabled: true, snowDensity: 0.5, snowTexture: 'snow/bubble.part', snowFallSpeed: 0.1, }) ``` --- ### snowFallSpeed ? **snowFallSpeed**: *number* = 1 ������ѩ�������ٶȡ����С��0�������˶��� --- ### snowSizeHi ? **snowSizeHi**: *number* = 1 ������ѩ�����뾶 --- ### snowSizeLo ? **snowSizeLo**: *number* = 0 ������ѩ����Сֱ�� --- ### snowSpinSpeed ? **snowSpinSpeed**: *number* = 0 ������ѩ�������ٶ� --- ### snowTexture ? **snowTexture**: *string* = "" ������ѩ������ --- **�������ʾ��** ``` // һ������, һ��ӣ��Ʈ��ij���Ч��, ����������Ч����ʧ world.addZone({ selector: 'player', bounds: { lo: [0, 0, 64], hi: [128, 10, 128], }, rainEnabled: true, rainDensity: 0.5, rainSpeed: 0.5, snowEnabled: true, snowDensity: 0.5, snowTexture: 'snow/bubble.part', snowFallSpeed: -0.1, fogEnabled: true, fogColor: new Box3RGBColor(0.5, 1, 0), fogDensity: 0.02, }) world.addZone({ selector: 'player', bounds: { lo: [0, 0, 0], hi: [128, 10, 64], }, rainEnabled: true, rainDensity: 0.5, rainSpeed: -0.5, snowEnabled: true, snowDensity: 0.5, snowTexture: 'snow/sakura.part', snowFallSpeed: 0.1, fogEnabled: true, fogColor: new Box3RGBColor(1, 0, 0.5), fogDensity: 0.02, }) ``` # Interface: Box3ZoneConfig ��������IJ��� |����|����|˵�� |------ |bounds|[Box3Bounds3](box3bounds3.html)|�������ָ���ļ������| |selector|[Box3SelectorString](box3selectorstring)|���������¼���������������| |force|[Box3Vector3](box3vector3.html)|������ʩ�ӵ����Ĵ�С| |massScale|number|�������������������Ӱ��̶ȡ� 0 = ������һ��; 1 = ���һ��| |fogColor|[Box3RGBColor](box3rgbcolor.html)|������ɫ| |fogDensity|number|�������ܶ�| |fogEnabled|boolean|���Ƿ���| |fogHeightFalloff|number|����ʼ�߶�| |fogHeightOffset|number|��˥��������| |fogMax|number|�������| |fogStartDistance|number|����ʼ����| |rainColor|[Box3RGBAColor](box3rgbacolor.html)|�����ɫ| |rainDensity|number|����ܶȡ��ܶ�Խ�����Խ�ࡣ| |rainDirection|[Box3Vector3](box3vector3.html)|��ķ���| |rainEnabled|boolean|���Ƿ���| |rainInterference|number|����Ŷ�����| |rainSizeHi|number|��ε����ֱ��| |rainSizeLo|number|��ε���Сֱ��| |rainSpeed|number|����ٶ�| |skyBackLight|[Box3RGBColor](box3rgbcolor.html)|��������+Z�᷽�����ɫ���ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч����ɫֵ����0ʱ����ɫԽ����| |skyBottomLight|[Box3RGBColor](box3rgbcolor.html)|��������-Y�᷽�����ɫ���ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч����ɫֵ����0ʱ����ɫԽ����| |skyEnabled|boolean|���������Ƿ���Ч| |skyFrontLight|[Box3RGBColor](box3rgbcolor.html)|��������-Z�᷽�����ɫ���ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч����ɫֵ����0ʱ����ɫԽ����| |skyLeftLight|[Box3RGBColor](box3rgbcolor.html)|��������-X�᷽������ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч����ɫֵ����0ʱ����ɫԽ����| |skyLunarPhase|number|��������λ����ֵ��0��1֮�䡣������0.5ʱ��Ϊ�����¡�| |skyMode|"natural" or "manual"|��������պͻ�������������͡�Ŀǰ���ṩ2�ֹ���ģʽ��'manual'(�Զ���)��'natural'(��̬)��Ĭ��Ϊ 'natural'��| |skyRightLight|[Box3RGBColor](box3rgbcolor.html)|��������+X�᷽�����ɫ���ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч����ɫֵ����0ʱ����ɫԽ����| |skySunDirection|[Box3Vector3](box3vector3.html)|̫�����������򡣽��ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч��| |skySunFrequency|number|̫���˶���Ƶ�ʣ���ֵԽ����ҹ����Խ�졣| |skySunLight|[Box3RGBColor](box3rgbcolor.html)|̫������ɫ���ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч����ɫֵ����0ʱ����ɫԽ����| |skySunPhase|number|̫�������������£�����յ�λ�á�| |skyTopLight|[Box3RGBColor](box3rgbcolor.html)|��������+Y�᷽�����ɫ���ȡ����ڹ���ģʽΪ`manual`�Զ���ģʽʱ��Ч����ɫֵ����0ʱ����ɫԽ����| |snowColor|[Box3RGBAColor](box3rgbacolor.html)|ѩ����ɫ| |snowDensity|number|ѩ���ܶȡ��ܶ�Խ��ѩ��Խ�ࡣ| |snowEnabled|boolean|ѩ�Ƿ���| |snowFallSpeed|number|ѩ�������ٶȡ����С��0�������˶���| |snowSizeHi|number|ѩ�����뾶| |snowSizeLo|number|ѩ����Сֱ��| |snowSpinSpeed|number|ѩ�������ٶ�| |snowTexture|string|ѩ������| Ĭ��ֵ�ο� [Box3Zone](box3zone.html) ``` { selector: '', bounds: { lo: [0, 0, 0], hi: [0, 0, 0], }, force: [0, 0, 0], massScale: 0, fogEnabled: false, fogColor: new Box3RGBColor(1, 1, 1), fogDensity: 0, fogHeightFalloff: 0.8, fogHeightOffset: -8, fogMax: 1, fogStartDistance: 0, rainEnabled: false, rainColor: new Box3RGBAColor(1, 1, 1, 1), rainDensity: 0, rainSpeed: 1, rainDirection: new Box3Vector3(0, 1, 0), rainInterference: 0, rainSizeHi: 1, rainSizeLo: 0, rainSpeed: 1, skyEnabled: false, skyMode: 'natural', skyBottomLight: new Box3RGBColor(0, 0, 0), skyTopLight: new Box3RGBColor(0, 0, 0), skyBackLight: new Box3RGBColor(0, 0, 0), skyFrontLight: new Box3RGBColor(0, 0, 0), skyLeftLight: new Box3RGBColor(0, 0, 0), skyRightLight: new Box3RGBColor(0, 0, 0), skySunDirection: new Box3Vector3(0, -1, 0), skyLunarPhase: 0, skySunFrequency: 0, skySunPhase: 0, skySunLight: new Box3RGBColor(1000, 1000, 1000), snowEnabled: false, snowColor: new Box3RGBAColor(1, 1, 1, 1), snowDensity: 0, snowTexture: '', snowFallSpeed: 1, snowSizeHi: 1, snowSizeLo: 0, snowSpinSpeed: 0, } ``` # Class: Box3Voxels **Box3Voxels**�ǿ���Box3���з���Ľӿڣ������ʹ�� `voxels` ������Ƶ��α仯������ѭ���﷨��������/���ٷ��飬��ȡij����������͡����ơ���ת�Ƕȵȡ� # Basic ���� ## voxels.shape ###### `����` ??? ����ֵ���ͣ�`Box3Vector3` ??? Ĭ��ֵ��`{x: 128, y: 128, z: 128}` ����������ߴ硣
    Ŀǰ��Box3��������֧��128x128x128��δ�������Ÿ���ĵ��Σ������ڴ��� # Voxel Name �������� ## voxels.id() ###### `����` ����������ת��Ϊ����id ### ���� name |����|����|˵�� |------ |name|string|��������| ### ����ֵ id |����|����|˵�� |------ |id|number|���� id| ``` voxels.id('air') // 0 voxels.id('dirt') // 125 voxels.id('stone') // 129 ``` ## voxels.name() ###### `����` ������idת��Ϊ�������� ### ���� id |����|����|˵�� |------ |id|number|����id| ### ����ֵ name |����|����|˵�� |------ |name|string|��������| ``` voxels.name(0) // 'air' voxels.name(125) // 'dirt' voxels.name(129) // 'stone' ``` # setVoxel ���÷��� �������Ҫ��ͼ**�ڷ�����״̬**��ͨ���ű��ڳ�����**���ٽ���**�����Գ������²����� 1. �����༭�����Ͻǵĵ���ģʽ(С����ͼ��) 1. ʹ�ô��ڵײ��Ŀ���̨�������Ӧ�Ĵ��롣 ��ʹ��Ϸû�����У�Ҳ��ʹ���ִ���ֱ����Ч�� > [!TIP|style:flat] ʹ�ÿ���ִ̨�нű�ǰ�������ҪС�ģ���ǰ������Ŀ���ݹ�����һ��������Ч���п�������޷��ָ��������
    Ҫ��������ʱ��������ʹ�ÿհ׵�ͼ�Դ�����г�ֲ��ԣ�Ч��������ٲ�����ʽ�ĵ�ͼ�� ## voxels.setVoxel() ###### `����` ��ָ��������λ�÷���һ�����顣 ### ���� x, y, z, voxel, rotation |����|����|˵�� |------ |x|number|**����**������λ�õ�x����| |y|number|**����**������λ�õ�y����| |z|number|**����**������λ�õ�z����| |voxel|number | string|**����**���������ƻ�id| |rotation|number | string|ѡ��������ת��(0,1,2,3)| ### ����ֵ id |����|����|˵�� |------ |id|number|�µķ���id| > [!TIP|style:flat] ����������Ϊ'air' ��ʾ�� �����µķ���ȫ�����ѩ�� ɾ���������Ͽյ����з��� �����Զ��������� ���÷�����ʾ��ĸ ���÷�����ʾ���� ����һ������
    voxels.setVoxel(64, 9 ,64, 'H')
    voxels.setVoxel(65, 9 ,64, 'E')
    voxels.setVoxel(66, 9 ,64, 'L')
    voxels.setVoxel(67, 9 ,64, 'L')
    voxels.setVoxel(68, 9 ,64, 'O')
    

    ��ʾ��

    voxels.setVoxel(64, 9 ,64, 'H')
    voxels.setVoxel(65, 9 ,64, 'E')
    voxels.setVoxel(66, 9 ,64, 'L')
    voxels.setVoxel(67, 9 ,64, 'L')
    voxels.setVoxel(68, 9 ,64, 'O')
    

    �����µķ���ȫ�����ѩ��

    // ����ѭ���������÷���
    for(let x=0; x<127; x++){
    for(let z=0; z<127; z++){
        voxels.setVoxel(x, 8, z, 'snow')
    }}
    

    ɾ���������Ͽյ����з���

    // ����ѭ���������÷���
    for(let x=0; x<127; x++){
    for(let z=0; z<127; z++){
    for(let y=9; y<127; y++){
        voxels.setVoxel(x, y, z, 'air')
    }}}
    

    �����Զ���������

    // ���ݵ���ķ������裬��������������5��߶ȵ�ǽ��
    for(let x=0; x<127; x++){ 
    for(let z=0; z<127; z++){ 
      let vox = voxels.getVoxelId(x,9,z);
      if (!vox) continue // ���û�з���������
      for(let y = 10; y < 10+5; y++){ // ��y=10��λ�ÿ�ʼ����5��
        voxels.setVoxel(x, y, z, vox);
      }
    }}
    

    ���÷�����ʾ��ĸ

    // ��ָ��λ�÷�����ĸ����
    function voxelAlhpabet(str, x, y, z) {
        str = str.toUpperCase()  // ����ĸת��Ϊ��д
        for(var i = 0; i < str.length; i++){
            var char = str[i]
            voxels.setVoxel(x+i, y, z, char);
        }
    }
    
    // ���÷���
    voxelAlhpabet('hello world', 63, 20, 63)
    

    ���÷�����ʾ����

    // ���ַ����뷽�����ƶ�Ӧ
    const char_table = {
      0:'zero',
      1:'one',
      2:'two',
      3:'three',
      4:'four',
      5:'five',
      6:'six',
      7:'seven',
      8:'eight',
      9:'nine',
      '+':'add',
      '-':'subtract',
      '?':'question_mark',
      '!':'exclamation_mark',
      '=':'equal',
      ' ':'black',
      '&':'ampersand',
      '*':'asterisk',
      '@':'at',
      '\\':'backslash',
      ']':'bracket_close',
      '[':'bracket_open',
      '^':'caret',
      ':':'colon',
      ',':'comma',
      '$':'dollar',
      '>':'greater_than',
      '<':'less_than',
      '(':'paren_open',
      ')':'paren_close',
      '%':'percent',
      '.':'period',
      '#':'pound',
      '"':'quotation_mark',
      ';':'semicolon',
      '/':'slash',
      '~':'tilde',
    }
    
    // ����������б��ڣ�������б���Ӧ���Ƶķ��顣����ֱ�ӷ�����ĸ���顣
    function voxelText(str, x, y, z) {
      for (var i=0; i<str.length; i++) {
        var char = str[i].toUpperCase()
        var name = char_table[char]
        if (name) {
          voxels.setVoxel(x+i, y, z, name)
        } else {
          voxels.setVoxel(x+i, y, z, char)
        }
      }
    }
    
    // ��ָ����λ�ã����������ַ�������
    function voxelTextWall(words, x, y, z) {
      for (var i=0; i<words.length; i++) {
        voxelText(words[i], x, y-i, z)
      }
    }
    
    // ���÷���
    voxelTextWall(['HELLO BOX3.0','2333'], 64, 13, 64)
    

    ����һ������

    // ���̷���
    const B = {
        '+': voxels.id('board1'),
        'T': voxels.id('board4'),
        'L': voxels.id('board3'),
        '.': voxels.id('board2'),
    }
    
    // ������ת��
    const R = {
        N: 0x8000,
        S: 0,
        E: 0xc000,
        W: 0x4000,
    };
    
    // ��������
    function createBoard(originX, originY, originZ, size) {
        // ����size * size������
        for (let x = 0; x < size; ++x) {
            for (let z = 0; z < size; ++z) {
                // ͨ�������ǽ���
                let p = B['+'];
                // �����ĸ��ж������ж��Ƿ��DZ߽�
                if (x === 0 && z === 0) { 
                    p = B['L'] | R['S'];
                } else if (x === 0 && z === size - 1) {
                    p = B['L'] | R['E'];
                } else if (x === size -1 && z === 0) {
                    p = B['L'] | R['W'];
                } else if (x === size -1 && z === size - 1) {
                    p = B['L'] | R['N'];
                // �����ĸ��ж������ж��Ƿ��DZ�Ե
                } else if (x === 0) {
                    p = B['T'] | R['E'];
                } else if (x === size -1) {
                    p = B['T'] | R['W'];
                } else if (z === 0) {
                    p = B['T'] | R['S'];
                } else if (z === size -1) {
                    p = B['T'] | R['N'];
                }
                // ���÷���
                voxels.setVoxelId(x + originX, originY, z + originZ, p);
            }
        }
    }
    
    
    // ���÷���: ��{x:32, y:9, z:32} λ�ã�����19*19������
    createBoard(32, 9, 32, 19)
    
    ``` voxels.setVoxel(64, 9 ,64, 'H') voxels.setVoxel(65, 9 ,64, 'E') voxels.setVoxel(66, 9 ,64, 'L') voxels.setVoxel(67, 9 ,64, 'L') voxels.setVoxel(68, 9 ,64, 'O') ``` ### �����µķ���ȫ�����ѩ�� ``` // ����ѭ���������÷��� for(let x=0; x<127; x++){ for(let z=0; z<127; z++){ for(let y=9; y<127; y++){ voxels.setVoxel(x, y, z, 'air') }}} ``` ### �����Զ��������� ``` // ��ָ��λ�÷�����ĸ���� function voxelAlhpabet(str, x, y, z) { str = str.toUpperCase() // ����ĸת��Ϊ��д for(var i = 0; i < str.length; i++){ var char = str[i] voxels.setVoxel(x+i, y, z, char); } } // ���÷��� voxelAlhpabet('hello world', 63, 20, 63) ``` ### ���÷�����ʾ���� ``` // ���̷��� const B = { '+': voxels.id('board1'), 'T': voxels.id('board4'), 'L': voxels.id('board3'), '.': voxels.id('board2'), } // ������ת�� const R = { N: 0x8000, S: 0, E: 0xc000, W: 0x4000, }; // �������� function createBoard(originX, originY, originZ, size) { // ����size * size������ for (let x = 0; x < size; ++x) { for (let z = 0; z < size; ++z) { // ͨ�������ǽ��� let p = B['+']; // �����ĸ��ж������ж��Ƿ��DZ߽� if (x === 0 && z === 0) { p = B['L'] | R['S']; } else if (x === 0 && z === size - 1) { p = B['L'] | R['E']; } else if (x === size -1 && z === 0) { p = B['L'] | R['W']; } else if (x === size -1 && z === size - 1) { p = B['L'] | R['N']; // �����ĸ��ж������ж��Ƿ��DZ�Ե } else if (x === 0) { p = B['T'] | R['E']; } else if (x === size -1) { p = B['T'] | R['W']; } else if (z === 0) { p = B['T'] | R['S']; } else if (z === size -1) { p = B['T'] | R['N']; } // ���÷��� voxels.setVoxelId(x + originX, originY, z + originZ, p); } } } // ���÷���: ��{x:32, y:9, z:32} λ�ã�����19*19������ createBoard(32, 9, 32, 19) ``` ## voxels.setVoxelId() ###### `����` ʹ�÷���ID��ֱ����ָ��������λ�÷��÷��顣ִ��Ч�ʱ� [`voxels.setVoxel()`](#voxelssetvoxel) ���졣 ### ���� x, y, z, voxel |����|����|˵�� |------ |x|number|**����**�����õķ��� x ����| |y|number|**����**�����õķ��� y ����| |z|number|**����**�����õķ��� z ����| |voxel|number|**����**�����õķ��� id| ### ����ֵ id |����|����|˵�� |------ |id|number|����ָ��λ�õķ���id| ``` // ��ָ��λ�������ӡ 0-9, A-Z ���� for( let i = 0; i <= 35; i++) { voxels.setVoxelId(32+i, 9 ,30, 18+(i*2-1)) } ``` # getVoxel ��ȡ���� ## voxels.getVoxel() ###### `����` ��ȡij������λ�õķ���id ### ���� x, y, z |����|����|˵�� |------ |x|number|**����**����ȡ�ķ��� x ����| |y|number|**����**����ȡ�ķ��� y ����| |z|number|**����**����ȡ�ķ��� z ����| ### ����ֵ id |����|����|˵�� |------ |id|number|����ָ��λ�õķ���id| ``` voxels.setVoxel(64, 11 ,64, 'ice') voxels.getVoxel(64, 11, 64) // 398 ``` ## voxels.getVoxelId() ###### `����` ֱ�ӻ�ȡָ��λ�õķ���ID��ִ��Ч�ʱ� [`voxels.getVoxel()`](#voxelsgetvoxel) ���졣 ### ���� x, y, z |����|����|˵�� |------ |x|number|**����**����ȡ�ķ��� x ����| |y|number|**����**����ȡ�ķ��� y ����| |z|number|**����**����ȡ�ķ��� z ����| ### ����ֵ id |����|����|˵�� |------ |id|number|����ָ��λ�õķ���id| ``` voxels.getVoxelId(64, 8 ,64) // 127 ``` ## voxels.getVoxelRotation() ###### `����` ��ȡij������λ�õķ�����ת�� ### ���� x, y, z |����|����|˵�� |------ |x|number|**����**����ȡ�ķ��� x ����| |y|number|**����**����ȡ�ķ��� y ����| |z|number|**����**����ȡ�ķ��� z ����| ### ����ֵ id |����|����|˵�� |------ |id|number|����ָ��λ�õķ���id| ``` // ʹ�����̷��� ` �a ` �����������ڵ�ͼ�������һ���򵥵����� voxels.setVoxel(63, 9 ,60, 'board3', 0) voxels.setVoxel(64, 9 ,60, 'board3', 1) voxels.setVoxel(64, 9 ,61, 'board3', 2) voxels.setVoxel(63, 9 ,61, 'board3', 3) // ��ȡ������ת�� voxels.getVoxelRotation(63, 9, 60) // 0 voxels.getVoxelRotation(64, 9 ,60) // 1 voxels.getVoxelRotation(64, 9 ,61) // 2 voxels.getVoxelRotation(63, 9 ,61) // 3 ``` # Voxels Type �������� ## voxels.VoxelTypes ###### `����` ??? ����ֵ���ͣ�`Array` ??? Ĭ��ֵ��`String[]` ���ذ������з������Ƶ����顣 # Build ���ٽ��� �˴��ṩһЩ���ٽ����ض��������͵Ĵ���Ƭ�Σ��ɹ��ο��� ʵ�ľ��� ���ľ��� ʵ������ Բ���� ����¥��(+x) ����¥��(-x)
    /* ��ָ��λ�ÿ��ٽ���һ��ʵ�ĵľ��� */
    function cubefill(vox, sx, sy, sz, xsize, ysize, zsize){
        var xend = sx+xsize
        var yend = sy+ysize
        var zend = sz+zsize
        for(var x=sx;x<xend;x++){
        for(var y=sy;y<yend;y++){
        for(var z=sz;z<zend;z++){
            voxels.setVoxel(x,y,z,vox)
        }}}
    }
    
    cubefill('stone',64,9,64,10,5,10)   // ���÷�������{x:64, y:9, z:64} λ�ã�����һ����10�񣬿�5�񣬸�10���ʵ�ľ���
    

    ʵ�ľ���

    /* ��ָ��λ�ÿ��ٽ���һ��ʵ�ĵľ��� */
    function cubefill(vox, sx, sy, sz, xsize, ysize, zsize){
        var xend = sx+xsize
        var yend = sy+ysize
        var zend = sz+zsize
        for(var x=sx;x<xend;x++){
        for(var y=sy;y<yend;y++){
        for(var z=sz;z<zend;z++){
            voxels.setVoxel(x,y,z,vox)
        }}}
    }
    
    cubefill('stone',64,9,64,10,5,10)   // ���÷�������{x:64, y:9, z:64} λ�ã�����һ����10�񣬿�5�񣬸�10���ʵ�ľ���
    

    ���ľ���

    /* ��ָ��λ�ÿ��ٽ���һ�����ĵľ��� */
    function cube(vox, sx, sy, sz, xsize, ysize, zsize){
        var xend = sx+xsize
        var yend = sy+ysize
        var zend = sz+zsize
        for(var x=sx;x<xend;x++){
        for(var y=sy;y<yend;y++){
        for(var z=sz;z<zend;z++){
            if(x===sx || z===sx || x===xend-1 || z===zend-1 ){ //��������λ���ڱ�Ե
                voxels.setVoxel(x,y,z,vox)
            }
        }}}
    }
    
    cube('stone',64,9,64,10,5,10)  // ���÷�������{x:64, y:9, z:64} λ�ã�����һ����10�񣬿�5�񣬸�10��Ŀ��ľ���
    

    ʵ������

    /* ��ָ��λ�ÿ��ٽ���һ��ʵ�ĵ����� */
    function sphere(vox, cx, cy, cz, radius){
        let xend = cx+radius
        let yend = cy+radius
        let zend = cz+radius
        for(let x=cx-radius;x<=xend;x++){
        for(let y=cy-radius;y<=yend;y++){
        for(let z=cz-radius;z<=zend;z++){
            let dx = x-cx;
            let dy = y-cy;
            let dz = z-cz;
            if(Math.round(Math.sqrt(dx*dx+dy*dy+dz*dz)) <= radius){
                voxels.setVoxel(x,y,z,vox)
            }
        }}}
    }
    
    sphere('stone',63,24,63,12) // ���÷�������{x:63, y:24, z:63} λ�ã�����һ���뾶Ϊ12���ʵ������
    

    Բ����

    /* ��ָ��λ�ÿ��ٽ���һ��Բ���� */
    function cylinder(vox, cx, cy, cz, radius, height){
        let xend = cx+radius
        let yend = cy+height
        let zend = cz+radius
        for(let x=cx-radius; x<=xend; x++){
        for(let z=cz-radius; z<=zend; z++){
            let dx = x-cx;
            let dz = z-cz;
            if(Math.round(Math.sqrt(dx*dx+dz*dz)) <= radius){
                for(let y=cy; y<yend; y++){
                    voxels.setVoxel(x,y,z,vox)
                }
            }
        }}
    }
    
    cylinder('stone',63,12,63,10,4)  // ���÷�������{x:63, y:12, z:63} λ�ã�����һ���뾶10�񣬸߶�4���Բ����
    

    ����¥��(+x)

    /* ��ָ��λ�ÿ��ٽ���һ������¥��(+x�᷽��) */
    function stairs(sx, sy, sz, length, thickness){
        let xend = sx + length;
        let zend = sz + thickness;
        let i = 0;
        for(let x=sx; x < xend; x++){
            let yend = sy+i;
            i++;
            for(let y=sy; y<=yend; y++){
            for(let z=sz; z<zend; z++){
                voxels.setVoxel(x,y,z,'stone');
            }}
        }
    }
    
    stairs(63,9,63,6,4)  // ���÷�������{x:63, y:9, z:63} λ�ã�����һ���߶�6�񣬿���4���¥��
    

    ����¥��(-x)

    /* ��ָ��λ�ÿ��ٽ���һ������¥��(-x�᷽��) */
    function stairs(sx, sy, sz, length, thickness){
        let xend = sx + length;
        let zend = sz + thickness;
        let i = 0;
        for(let x=xend; x > sx; x--){ // ��ǰ��+x�᷽��ķ�����ȣ��˴������෴
            let yend = sy+i;
            i++;
            for(let y=sy; y<=yend; y++){
            for(let z=sz; z<zend; z++){
                voxels.setVoxel(x,y,z,'stone');
            }}
        }
    }
    
    stairs(63,9,63,6,4)  // ���÷�������{x:63, y:9, z:63} λ�ã�����һ���߶�6�񣬿���4���¥��
    
    ``` /* ��ָ��λ�ÿ��ٽ���һ��ʵ�ĵľ��� */ function cubefill(vox, sx, sy, sz, xsize, ysize, zsize){ var xend = sx+xsize var yend = sy+ysize var zend = sz+zsize for(var x=sx;x<xend;x++){ for(var y=sy;y<yend;y++){ for(var z=sz;z<zend;z++){ voxels.setVoxel(x,y,z,vox) }}} } cubefill('stone',64,9,64,10,5,10) // ���÷�������{x:64, y:9, z:64} λ�ã�����һ����10�񣬿�5�񣬸�10���ʵ�ľ��� ``` ### ���ľ��� ``` /* ��ָ��λ�ÿ��ٽ���һ��ʵ�ĵ����� */ function sphere(vox, cx, cy, cz, radius){ let xend = cx+radius let yend = cy+radius let zend = cz+radius for(let x=cx-radius;x<=xend;x++){ for(let y=cy-radius;y<=yend;y++){ for(let z=cz-radius;z<=zend;z++){ let dx = x-cx; let dy = y-cy; let dz = z-cz; if(Math.round(Math.sqrt(dx*dx+dy*dy+dz*dz)) <= radius){ voxels.setVoxel(x,y,z,vox) } }}} } sphere('stone',63,24,63,12) // ���÷�������{x:63, y:24, z:63} λ�ã�����һ���뾶Ϊ12���ʵ������ ``` ### Բ���� ``` /* ��ָ��λ�ÿ��ٽ���һ������¥��(+x�᷽��) */ function stairs(sx, sy, sz, length, thickness){ let xend = sx + length; let zend = sz + thickness; let i = 0; for(let x=sx; x < xend; x++){ let yend = sy+i; i++; for(let y=sy; y<=yend; y++){ for(let z=sz; z<zend; z++){ voxels.setVoxel(x,y,z,'stone'); }} } } stairs(63,9,63,6,4) // ���÷�������{x:63, y:9, z:63} λ�ã�����һ���߶�6�񣬿���4���¥�� ``` ### ����¥��(-x) > [!TIP|style:flat] ����id�����ƶ��ձ� |����id|���� |------ |0|air| |3|add| |5|subtract| |7|multiply| |9|divide| |11|equal| |13|exclamation_mark| |15|question_mark| |17|zero| |19|one| |21|two| |23|three| |25|four| |27|five| |29|six| |31|seven| |33|eight| |35|nine| |37|A| |39|B| |41|C| |43|D| |45|E| |47|F| |49|G| |51|H| |53|I| |55|J| |57|K| |59|L| |61|M| |63|N| |65|O| |67|P| |69|Q| |71|R| |73|S| |75|T| |77|U| |79|V| |81|W| |83|X| |85|Y| |87|Z| |89|cadet_blue| |91|sky_blue| |93|powder_blue| |95|dark_gray| |97|light_gray| |99|olive_green| |101|yellow_green| |103|pale_green| |105|red| |107|dark_red| |109|brick_red| |111|medium_gray| |113|dark_slate_blue| |115|pink| |117|sakura_pink| |119|orange| |121|lemon| |123|stained_glass| |125|dirt| |127|grass| |129|stone| |131|green_leaf| |133|acacia| |135|sand| |137|plank_01| |139|plank_02| |141|plank_03| |143|plank_04| |145|ice_brick| |147|light_grey_stone_brick| |149|grey_stone_brick| |151|gold_trim_brick| |153|red_brick| |155|quartz_brick| |157|lantern_01| |159|lantern_02| |160|window| |162|cross_window| |164|geometric_window_01| |166|geometric_window_02| |169|snow| |170|glass| |172|color_glass| |175|black| |177|white| |179|wooden_box| |181|board_01| |183|board_02| |185|stripe_01| |187|stripe_02| |189|stripe_03| |191|stripe_04| |193|stripe_05| |195|carpet_01| |197|carpet_02| |199|carpet_03| |201|carpet_04| |203|carpet_05| |205|carpet_06| |207|carpet_07| |209|palace_eaves_01| |211|palace_eaves_02| |213|palace_eaves_03| |215|palace_eaves_04| |217|palace_eaves_05| |219|palace_eaves_06| |221|palace_eaves_07| |223|palace_eaves_08| |225|roof_red| |227|roof_purple| |229|roof_green| |231|roof_blue_04| |233|roof_yellow| |235|carpet_08| |237|carpet_09| |239|carpet_10| |241|carpet_11| |243|carpet_12| |245|carpet_13| |247|stainless_steel| |249|ice_wall| |251|leaf_01| |253|leaf_02| |255|palace_roof| |257|wood| |259|red_brick_floor| |261|red_brick_wall| |263|palace_floor| |264|palace_carving| |267|stone_pillar_03| |269|stone_pillar_04| |271|stone_pillar_05| |273|stone_pillar_06| |275|stone_wall| |276|blue_glass| |278|green_glass| |281|red_light| |283|orange_light| |285|yellow_light| |287|green_light| |289|indigo_light| |291|blue_light| |293|purple| |295|pink_light| |297|mint_green_light| |299|white_light| |301|warm_yellow_light| |302|black_glass| |304|red_glass| |307|palace_lamp| |309|board_03| |311|board_04| |313|board_05| |315|board_06| |317|dark_grass| |319|greenbelt_L| |321|greenbelt_L1| |323|stone_brick_01| |325|stone_brick_02| |327|dark_stone| |329|dark_brick_00| |331|dark_brick_01| |333|dark_brick_02| |335|stone_wall_01| |337|pink_cake| |339|macaroon| |341|biscuit| |343|snowland| |345|polar_region| |347|polar_ice| |349|blue_surface_01| |351|blue_surface_02| |353|purple_surface_01| |355|purple_surface_02| |357|dark_surface| |359|rock| |361|palace_cloud| |363|blue| |364|water| |367|turquoise| |369|dark_orchid| |371|medium_orchid| |373|medium_purple| |375|medium_violet_red| |377|maroon| |379|coffee_gray| |381|peru| |383|dark_salmon| |385|navajo_white| |387|orange_red| |389|medium_yellow| |391|medium_green| |393|sienna| |395|mint_green| |397|medium_spring_green| |398|ice| |401|crane_roof_01| |403|crane_roof_02| |405|crane_lantern| |407|roof_grey| |408|palace_window| |411|woodstone_12| |412|strawberry_juice| |414|lime_juice| |416|blueberry_juice| |418|lemon_juice| |420|grape_juice| |422|orange_juice| |424|milk| |426|soy_sauce| |428|coffee| |430|peach_juice| |433|board0| |435|board1| |437|board2| |439|board3| |441|board4| |443|board5| |445|board6| |447|board7| |449|board8| |451|board9| |453|board10| |455|board11| |457|board12| |459|board13| |461|board14| |463|board15| |465|lava01| |467|lava02| |469|windygrass| |471|conveyor| |473|ledfloor01| |475|ledfloor02| |477|yellow_grass| |479|express_box| |481|television| |483|bookshelf| |485|ampersand| |487|asterisk| |489|at| |491|backslash| |493|bracket_close| |495|bracket_open| |497|caret| |499|colon| |501|comma| |503|dollar| |505|greater_than| |507|less_than| |509|paren_open| |511|paren_close| |513|percent| |515|period| |517|pound| |519|quotation_mark| |521|semicolon| |523|slash| |525|tilde| |527|winter_leaf| |529|leaf_03| |531|leaf_04| |533|leaf_05| |535|honeycomb_01| |537|honeycomb_02| |539|white_grass| |541|palm| # Class: Box3VoxelContact ��ʵ�崥���ķ������� --- ### x ? **x**: *number* �����������x���� --- ### y ? **y**: *number* �����������y���� --- ### z ? **z**: *number* �����������z���� --- ### voxel ? **voxel**: *number* �������ķ���id --- ### force ? **force**: *[Box3Vector3](box3vector3.html)* �������� --- ### axis ? **axis**: *[Box3Vector3](box3vector3.html)* �����ķ����ᣬҲ���Ǵ��������嵯�ɵķ��� # Class: Box3FluidContact ��ʵ��/��Ҵ�����Һ�巽�顣 --- ### voxel ? **voxel**: *number* Һ�巽��id --- ### volume ? **volume**: *number* Һ�巽���У�����һ�ʵ�����������������СΪ(0,1] # Class: Box3Entity Entityʵ����Box3�е���Ϸ�������ڶ����塢��ҵȵĿ��ơ� ## ����ʵ������ ### entity.mesh ? **mesh**: *string* = "" *��[Box3EntityConfig](box3entityconfig.html).[mesh](box3entityconfig.html#mesh)ʵ��* ʵ����״����(mesh)��hash�������Ϊ���ַ���/''����ʵ����mesh�� ����ʵ��Ϊ��ң������趨ʵ���mesh֮��mesh�ͻ���������ʵ��ı߽硣 ֻ����ǰ�ڳ����з���ģ�ͣ����ܻ��ģ�͵�Mesh���ԡ�
    ģ�ͱ����ú󣬻��Զ��������ļ��б��С�ģ���ļ���Ӧ�� **'mesh/*.vb*'* ���Ʊ��� mesh���ԡ� **ʾ������** ``` /* ��ҽ�����Ϸʱ�����һ�����ǡ�5���ָ��� */ world.onPlayerJoin(async({ entity }) => { const originPlayerMesh = entity.mesh; // ��Ҫ���ڳ����ڷ�һ������Ϊ ���� ��ģ�� entity.mesh = world.querySelector('#����').mesh entity.meshScale = new Box3Vector3(1/24, 1/24, 1/24); entity.meshOrientation = new Box3Quaternion(0, 1, 0, 0) entity.player.invisible = true; await sleep(5000) entity.mesh = originPlayerMesh entity.player.invisible = false; }); ``` --- ### entity.position ? **position**: *[Box3Vector3](box3vector3.html)<>* = new Box3Vector3(0, 0, 0) *��[Box3EntityConfig](box3entityconfig.html).[position](box3entityconfig.html#position)ʵ��* ʵ���λ�á� **ʾ������** ``` //����ڷ����ж�����λ�� world.querySelectorAll('*').forEach((e) => { e.position = new Box3Vector3( Math.random()*10, 10+Math.random()*10, Math.random()*10); }); ``` --- ### entity.meshOrientation ? **meshOrientation**: *[Box3Quaternion](box3quaternion.html)<>* = new Box3Quaternion(0, 0, 0, 1) *��[Box3EntityConfig](box3entityconfig.html).[meshOrientation](box3entityconfig.html#meshorientation)ʵ��* ʵ�����ת�Ƕ� --- ### entity.meshScale ? **meshScale**: *[Box3Vector3](box3vector3.html)<>* = new Box3Vector3(1 / 64, 1 / 64, 1 / 64) *��[Box3EntityConfig](box3entityconfig.html).[meshScale](box3entityconfig.html#meshscale)ʵ��* ʵ������ű��� --- ### entity.meshColor ? **meshColor**: *[Box3RGBAColor](box3rgbacolor.html)<>* = new Box3RGBAColor(1, 1, 1, 1) *��[Box3EntityConfig](box3entityconfig.html).[meshColor](box3entityconfig.html#meshcolor)ʵ��* ʵ�����ɫ --- ### entity.meshInvisible ? **meshInvisible**: *boolean* = false �ɿ���ʵ�����Σ���ֵ��Ϊtrueʱ����ʵ�����Ρ� --- ### entity.meshEmissive ? **meshEmissive**: *number* = 0 *��[Box3EntityConfig](box3entityconfig.html).[meshEmissive](box3entityconfig.html#meshemissive)ʵ��* ʵ��ķ���� --- ### entity.meshMetalness ? **meshMetalness**: *number* = 0 *��[Box3EntityConfig](box3entityconfig.html).[meshMetalness](box3entityconfig.html#meshmetalness)ʵ��* ʵ��Ľ����� --- ### entity.meshShininess ? **meshShininess**: *number* = 0 *��[Box3EntityConfig](box3entityconfig.html).[meshShininess](box3entityconfig.html#meshshininess)ʵ��* ʵ��ķ���ȣ���Ϊ1��Ϊ�dz��⻬ --- ### entity.meshOffset ? **meshOffset**: *[Box3Vector3](box3vector3.html)<>* = new Box3Vector3(0, 0, 0) ʵ���λ�� --- ## ����ʵ����������� ### entity.bounds ? **bounds**: *[Box3Vector3](box3vector3.html)<>* = new Box3Vector3(1, 1, 1) ʵ��߽��Ĵ�С������x/y/z���� --- ### entity.collides ? **collides**: *boolean* = true *��[Box3EntityConfig](box3entityconfig.html).[collides](box3entityconfig.html#collides)ʵ��* ���Ϊ��(false)����ʵ�岻����ײ --- ### entity.fixed ? **fixed**: *boolean* = false *��[Box3EntityConfig](box3entityconfig.html).[fixed](box3entityconfig.html#fixed)ʵ��* ���Ϊ��(true)����ʵ�岻���ƶ� --- ### entity.friction ? **friction**: *number* = 0 *��[Box3EntityConfig](box3entityconfig.html).[friction](box3entityconfig.html#friction)ʵ��* ����ʵ���ճ��(0 = ����1 = ճ) --- ### entity.gravity ? **gravity**: *boolean* = true *��[Box3EntityConfig](box3entityconfig.html).[gravity](box3entityconfig.html#gravity)ʵ��* ���Ϊ��(false)����ʵ�岻������ **ʾ������** ``` //��������ڷ��ڿ����������� world.querySelectorAll('*').forEach((e) => { e.position = new Box3Vector3( Math.random()*10,15,Math.random()*10 ); e.gravity = true; e.fixed = false; }); ``` ``` /* Example��������������л���������*/ let toggleWorldGravityState = false world.onPress(({ button }) => { if (button === Box3ButtonType.ACTION0) { toggleWorldGravityState = !toggleWorldGravityState world.gravity = toggleWorldGravityState ? -0.5 * world.gravity : -0.1 world.say(`����: ${toggleWorldGravityState ? '����' : '����'}`) } }); ``` --- ### entity.mass ? **mass**: *number* = 1 *��[Box3EntityConfig](box3entityconfig.html).[mass](box3entityconfig.html#mass)ʵ��* ʵ���������� --- ### entity.restitution ? **restitution**: *number* = 0 *��[Box3EntityConfig](box3entityconfig.html).[restitution](box3entityconfig.html#restitution)ʵ��* ����ʵ��ĵ���(0 = ��, 1 = ��) --- ### entity.velocity ? **velocity**: *[Box3Vector3](box3vector3.html)<>* = new Box3Vector3(0, 0, 0) *��[Box3EntityConfig](box3entityconfig.html).[velocity](box3entityconfig.html#velocity)ʵ��* ʵ����ٶ� **ʾ������** ``` // ���������ÿ������һ�� setInterval(() => { console.log('jump around!') world.querySelectorAll('player').forEach((e) => { e.velocity.y += 1; }); }, 5000); ``` --- ### entity.contactForce ? **contactForce**: *[Box3Vector3](box3vector3.html)<>* = new Box3Vector3(0, 0, 0) ʵ���ܵ�����ײ�� --- ### entity.entityContacts ? **entityContacts**: *[Box3EntityContact](box3entitycontact.html)*[] = [] �������ں����/ʵ�巢����ײ��ȫ��ʵ���б� --- ### entity.voxelContacts ? **voxelContacts**: *[Box3VoxelContact](box3voxelcontact.html)*[] = [] �������ں����/ʵ�巢����ײ��ȫ�������б� --- ### entity.fluidContacts ? **fluidContacts**: *[Box3FluidContact](box3fluidcontact.html)*[] = [] �������ڱ����/ʵ�崥����ȫ��Һ�巽���б� --- ## ���� ### entity.say ? **say**(`message`: string): *void* ��ʵ��˵���� **ʾ������** ``` // ����һ��ʵ�岢����ÿ��˵һ�仰 const e = world.createEntity({ position: [64, 9, 64], }) setInterval(() => { e.say('hey, im a box. my position is ' + e.position.toString()); }, 1000); ``` --- ## ���� ### ����ʵ����л��� ### entity.enableInteract ? **enableInteract**: *boolean* = false �Ƿ�����ʵ����л�������������������߽�������Χ֮�ڣ�ʵ�����Ͻ�����ֻ�����ʾ�� --- ### ʵ�廥����Χ ### entity.interactRadius ? **interactRadius**: *number* = 16 ʵ�廥����Χ����ֵԽС������Ҫ����ʵ��Ż���ֻ�����ʾ��
    ��Χ�ж���ɻ���ʵ�壬���¼��� `[` �� `]` �����л�����Ŀ�ꡣ --- ### ������ʾ�ı� ### entity.interactHint ? **interactHint**: *string* = "" ����ʵ�廥����Χʱ��ʵ�����ϳ��ֵ���ʾ�ı��� --- ### ������ʾ�ı���ɫ ### entity.interactColor ? **interactColor**: *[Box3RGBColor](box3rgbcolor.html)??* = new Box3RGBColor(1, 1, 1) ����ʵ�廥����Χʱ����ʾ�ı�����ɫ�� **ʾ������**
    ��ʵ�廥��֮ǰ���ڳ����б�������һ��ʵ�塣
    ��ģ���б��У���ѡһ����ϲ����ģ�ͣ����������ڳ����У�����סģ�͵����֡� ``` // ���ڳ����з���һ������Ϊ NPC ��ʵ�塣 const npc = world.querySelector('#NPC'); npc.enableInteract = true; // �������л��� npc.interactRadius = 16; // ʵ��Ļ�����Χ npc.interactHint = npc.id; // ������ʾ����ʾʵ������� npc.interactColor = new Box3RGBColor(1,0,1); // ������ʾ��������ɫ // �����ʵ����н���ʱ���� npc.onInteract(async({entity}) => { const result = await entity.player.dialog({ type: Box3DialogType.TEXT, // �Ի�������ͣ�TEXT���ı��� title: npc.id, // �Ի������ΪNPC���֣���ʾ����˵������NPC lookEye: entity, // ������������λ�� lookTarget: npc, // �����ͷ��׼NPC content: `��ã�${entity.player.name}���ܸ�����ʶ�㡣`, }); }); ``` --- ## ��ʵ���йص��¼� ### entity.onClick ? **onClick**: *[Box3EventChannel](box3eventchannel.html)<[Box3ClickEvent](box3clickevent.html)>* ? **nextClick**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3ClickEvent](box3clickevent.html)>* ������������ʵ��ʱ�������¼� --- ### entity.onEntityContact ? **onEntityContact**: *[Box3EventChannel](box3eventchannel.html)<[Box3EntityContactEvent](box3entitycontactevent.html)>* ? **nextEntityContact**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3EntityContactEvent](box3entitycontactevent.html)>* ��ʵ�崥����һ��ʵ��ʱ���� --- ### entity.onEntitySeparate ? **onEntitySeparate**: *[Box3EventChannel](box3eventchannel.html)<[Box3EntityContactEvent](box3entitycontactevent.html)>* ? **nextEntitySeparate**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3EntityContactEvent](box3entitycontactevent.html)>* ��ʵ��ֹͣ������һ��ʵ��ʱ���� --- ### entity.onFluidEnter ? **onFluidEnter**: *[Box3EventChannel](box3eventchannel.html)<[Box3FluidContactEvent](box3fluidcontactevent.html)>* ? **nextFluidEnter**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3FluidContactEvent](box3fluidcontactevent.html)>* ��ʵ�����Һ��ʱ���� --- ### entity.onFluidLeave ? **onFluidLeave**: *[Box3EventChannel](box3eventchannel.html)<[Box3FluidContactEvent](box3fluidcontactevent.html)>* ? **nextFluidLeave**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3FluidContactEvent](box3fluidcontactevent.html)>* ��ʵ���뿪Һ��ʱ���� --- ### entity.onInteract ? **onInteract**: *[Box3EventChannel](box3eventchannel)?[Box3InteractEvent](box3interactevent.html)?* ? **nextInteract**: *[Box3EventFuture](box3eventfuture)?[Box3InteractEvent](box3interactevent.html)?* ��ʵ����л���ʱ���� **ʾ������** ``` const npc = world.querySelector('#NPC'); npc.enableInteract = true; npc.interactHint = 'NPC'; npc.interactRadius = 10; npc.onInteract( ({entity}) => { npc.say('���! ' + entity.player.name); }); ``` --- ### entity.onVoxelContact ? **onVoxelContact**: *[Box3EventChannel](box3eventchannel.html)<[Box3VoxelContactEvent](box3voxelcontactevent.html)>* ? **nextVoxelContact**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3VoxelContactEvent](box3voxelcontactevent.html)>* ��ʵ�崥������ʱ���� --- ### entity.onVoxelSeparate ? **onVoxelSeparate**: *[Box3EventChannel](box3eventchannel.html)<[Box3VoxelContactEvent](box3voxelcontactevent.html)>* ? **nextVoxelSeparate**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3VoxelContactEvent](box3voxelcontactevent.html)>* ��ʵ��ֹͣ��������ʱ���� --- ## ������� ### entity.isPlayer ? **isPlayer**: *boolean* = false ���Ϊ�棬��ʵ��Ϊ��� --- ### `Optional` player ? **player**? : *[Box3Player](box3player.html)* �����������ص�ȫ��״̬�ͷ��� --- ## ���ٲ���ʵ�� ### entity.addTag Ϊʵ������һ���±�ǩ #### ��������: ? **addTag**(`tag`: string): *void* **����** |����|����|˵�� |------ |`tag`|string|Ҫ���ӵı�ǩ��| --- ### entity.hasTag �ж�ʵ���Ƿ����ij����ǩ #### ��������: ? **hasTag**(`tag`: string): *boolean* **����** |����|����|˵�� |------ |`tag`|string|��ǩ��| **ʾ������** ``` if (entity.hasTag('��ɫ')) { console.log(`ʵ��${entity.id}���б�ǩ [��ɫ]`);//����Ļ��ʾ���С���ɫ����ǩ��ʵ��id } ``` --- ### entity.id ? **id**: *string* = "" ���ڱ༭�������ӵ�ʵ������ --- ### entity.removeTag ��ʵ���Ƴ���ǩ #### ��������: ? **removeTag**(`tag`: string): *void* **����** |����|����|˵�� |------ |`tag`|string|Ҫ�Ƴ��ı�ǩ��| --- ### entity.tags �ڱ༭���и�ʵ�����ӵ�ȫ����ǩ #### ��������: ? **tags**(): *string[]* --- ## ʵ������� ### entity.destroy ? **destroy**: *function* ����ʵ�� #### ��������: ? **destroy**(): *void* --- ### entity.destroyed ? **destroyed**: *boolean* = false ���Ϊ��(true)��ʵ��ͱ����١� --- ### entity.onDestroy ? **onDestroy**: *[Box3EventChannel](box3eventchannel.html)<[Box3EntityEvent](box3entityevent.html)>* ? **nextDestroy**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3EntityEvent](box3entityevent.html)>* ��ʵ�屻����ʱ���� --- ## ����ʵ�������ֵ ### entity.enableDamage ? **enableDamage**: *boolean* = false ���Ϊ��true����ɶ�ʵ������˺� --- ### entity.showHealthBar ? **showHealthBar**: *boolean* = true ���Ϊ��true������ʾʵ�������ֵHP --- ### entity.hp ? **hp**: *number* = 100 ʵ��ĵ�ǰ����ֵhp --- ### entity.maxHp ? **maxHp**: *number* = 100 ʵ����������ֵhp --- ### entity.onTakeDamage ʵ���յ��˺�ʱ�������¼� ? **onTakeDamage**: *[Box3EventChannel](box3eventchannel.html)<[Box3DamageEvent](box3damageevent.html)>* ? **nextTakeDamage**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3DamageEvent](box3damageevent.html)>* --- ### entity.onDie ʵ������ʱ�������¼� ? **onDie**: *[Box3EventChannel](box3eventchannel.html)<[Box3DieEvent](box3dieevent.html)>* ? **nextDie**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3DieEvent](box3dieevent.html)>* --- ### entity.hurt ������������������ʵ����˺��������ʵ����˺�ֵ�� #### ��������: ? **hurt**(`amount`: number, `options?`:Partial< [Box3HurtOptions](box3hurtoptions.html) >): *void* **����** |����|����|˵�� |------ |`amount`|number|�˺�ֵ| |`options?`|Partial< [Box3HurtOptions](box3hurtoptions.html) >|�˺���������ã�ѡ��| **����ʾ��** ``` //һ���򵥵����PvP world.onPlayerJoin(({ entity }) => { entity.enableDamage = true; entity.player.onPress(({ button, raycast:{ hitEntity, direction } }) => { if (button !== 'action0' || !hitEntity) { return; } hitEntity.velocity.x += direction.x; hitEntity.velocity.y += 0.5; hitEntity.velocity.z += direction.z; hitEntity.hurt(20 * Math.random() + 5, { attacker: entity, }); }); }); world.onDie(({ entity, attacker }) => { if (attacker) { world.say(attacker.player.name + ' killed ' + entity.player.name) } entity.player.forceRespawn(); }); ``` --- ## ����ʵ��������ӵ����� ### entity.particleRate ? **particleRate**: *number* = 0 ʵ��ƽ��ÿ��������ӵ����������ϣ��ʵ��ֹͣ�ͷ����ӣ����Խ������Ը�Ϊ0 **ʾ������** ``` // �������ÿ�����5������ world.onPlayerJoin(({ entity }) => { Object.assign(entity, { particleRate: 5, }); }); ``` --- ### entity.particleRateSpread ? **particleRateSpread**: *number* = 0 ����趨�˸����Ե�ֵ��ʵ��ÿһ��������ӵ������������Ǹ��̶�ֵ�����Ǵ����� [`particleRate`, `particleRate` + `particleRateSpread`) �����ѡȡ��һ�����������磬���� `particleRate`=0��`particleRateSpread`=3��ÿ�����������������[0, 0+3) ����[0, 3)�������һ�����������Ҳ���ǿ���Ϊ0��1����2 **ʾ������** ``` // �������ÿ�����5��14������ world.onPlayerJoin(({ entity }) => { Object.assign(entity, { particleRate: 5, particleRateSpread: 10, }); }); ``` --- ### entity.particleLimit ? **particleLimit**: *number* = 100 ʵ��ɲ������������������� --- ### entity.particleLifetime ? **particleLifetime**: *number* = 10 ���ӵĴ��ʱ�䣬����Ϊ��λ **ʾ������** ``` // ���Ӵ��1�� world.onPlayerJoin(({ entity }) => { Object.assign(entity, { particleRate: 30, particleLifetime: 1, particleVelocity: new Box3Vector3(0, 0.5, 0), }); }); ``` --- ### entity.particleLifetimeSpread ? **particleLifetimeSpread**: *number* = 0 ����趨�˸����Ե�ֵ�����ӵĴ��ʱ�佫�����ǹ̶�ֵ���������� [`particleLifetime`, `particleLifetime` + `particleLifetimeSpread`) ���һ�������������ΪС�� **ʾ������** ``` // ���Ӵ��1��6�� world.onPlayerJoin(({ entity }) => { Object.assign(entity, { particleRate: 30, particleLifetime: 1, particleLifetimeSpread: 5, particleVelocity: new Box3Vector3(0, 0.5, 0), }); }); ``` --- ### entity.particleSize ? **particleSize**: *number[]* = [1, 1, 1, 1, 1] �����Ե�ֵ������һ������Ϊ0��5�����顣ÿ�����ӵĴ��ʱ�䱻ƽ����Ϊ����׶Σ����ڳ���Ϊ5�����飬�������ÿ��ֵ�ֱ�ָ�������ڸ����׶εĴ�С�����У���һ��ֵΪ���Ӹղ����ǵĴ�С�������ֵΪ������ʧʱ�Ĵ�С���ټ������ӣ�*�������ӵĴ��ʱ�䱻�趨Ϊ5��*����� `particleSize` ��ֵΪ - [25, 25, 25, 25, 25]�������Ӵ���5���ڴ�С���ᷢ���仯������ʱ��25����ʧʱҲ��25 - [0, 25, 0, 25, 15]�����Ӳ���ʱ��СΪ0��Ȼ���𽥱�Ϊ25��֮�����𽥱�Ϊ0�����𽥱�Ϊ25������Ϊ15�������ø�ʵ�������������Ӿ����𽥷Ŵ���С��Ч�� - [15�� 25], ���Ӳ���ʱ��СΪ15��1����𽥱����25��֮��������С����Сֵ **ʾ������** ``` // ���ӷŴ���С���������ʧ world.onPlayerJoin(({ entity }) => { Object.assign(entity, { particleRate: 30, particleSize: [2, 4, 8, 4, 10], particleLifetime: 1, particleVelocity: new Box3Vector3(0, 0.5, 0), }); }); ``` --- ### entity.particleSizeSpread ? **particleSizeSpread**: *number* = 0 - ����趨�˸����ԣ���û�趨 `particleSize` ��ֵ��ÿ����һ�����ӣ��������[0�� `particleSizeSpread`)��ѡȡ��һ���������Ϊ���Ĵ�С - ���ͬʱ�趨�� `particleSize` �� `particleSizeSpread` �������ԣ�ÿ����һ�����ӣ�������[0�� `particleSizeSpread`)��ѡȡһ�������x��������ӵ�i���׶εĴ�С��Ϊ `particleSize[i]+x` --- ### entity.particleColor ? **particleColor**: *[Box3RGBColor](box3rgbcolor.html)[]* = [ new Box3RGBColor(1,1,1), new Box3RGBColor(1,1,1), new Box3RGBColor(1,1,1), new Box3RGBColor(1,1,1), new Box3RGBColor(1,1,1) ] ���� `particleSize`�������Ե�ֵ������һ������Ϊ0��5�����飬�������ÿ��ֵ�ֱ�ָ���������ڸ����׶ε���ɫ�����Ƶأ�����ͨ��������ʹ���Ӿ�����ɫ�����Ч�� **ʾ������** ``` // ��������Ż��� world.onPlayerJoin(({ entity }) => { Object.assign(entity, { particleRate: 30, particleSize: [2, 4, 8, 4, 10], particleColor: [ new Box3RGBColor(10, 9, 2), new Box3RGBColor(5, 0.25, 0.1), new Box3RGBColor(3, 0.05, 0.05), new Box3RGBColor(0, 0, 0), new Box3RGBColor(0, 0, 0), ], particleLifetime: 1, particleVelocitySpread: new Box3Vector3(2, 2, 2), }); }); ``` --- ### entity.particleVelocity ? **particleVelocity**: *[Box3Vector3](box3vector3.html)* = new Box3Vector3(0, 0, 0) ��ʵ��������������ӵij�ʼ�ٶȣ��������������Ϊnew Box3Vector3(x, y, z)��x��y��z����ֵ�ֱ�ָ�������ڶ�Ӧ���������ϵ����� **ʾ������** ``` // ����ҵ�λ����һ���㷢������ world.onPlayerJoin(({ entity }) => { Object.assign(entity, { particleRate: 30, particleSize: [2, 2, 2, 2, 10], particleLifetime: 2, particleVelocity: new Box3Vector3(0, 0, 50), }); }); ``` --- ### entity.particleVelocitySpread ? **particleVelocitySpread**: *[Box3Vector3](box3vector3.html)* = new Box3Vector3(0, 0, 0) ���Ӹ�ʵ��������������ӳ�ʼ�ٶȵIJ�ȷ���ԣ��������������Ϊnew Box3Vector3(sx, sy, sz)��ÿ����һ�����ӣ������������ֵ�ֱ����һ�����ֵ�ӵ� x/y/z ������������Ӧ�������ϡ�ͨ���趨������ԣ�����ʹ���Ӿ�������������˶���Ч�� **ʾ������** ``` // ����ҵ�λ�����η������� world.onPlayerJoin(({ entity }) => { Object.assign(entity, { particleRate: 100, particleSize: [2, 2, 2, 2, 10], particleLifetime: 2, particleVelocity: new Box3Vector3(0, 0, 50), particleVelocitySpread: new Box3Vector3(30, 2, 2), }); }); ``` --- ### entity.particleDamping ? **particleDamping**: *number* = 0 - ��������Ե�ֵΪ����������ݼ��ٸ�ʵ�����������ӵij�ʼ�ٶȣ���ֵԽ�󣬼��ٳ�ʼ�ٶȵ�Ч��������Խ�� - ���Ϊ��ֵ��������������ӵij�ʼ�ٶȣ���ֵԽС�����ӳ�ʼ�ٶȵ�Ч��Խ���� **ʾ������** ``` // �������� world.onPlayerJoin(({ entity }) => { Object.assign(entity, { particleRate: 100, particleSize: [2, 2, 2, 2, 10], particleLifetime: 2, particleVelocity: new Box3Vector3(0, 0, 50), particleVelocitySpread: new Box3Vector3(30, 2, 2), particleDamping: 3, }); }); ``` --- ### entity.particleAcceleration ? **particleAcceleration**: *[Box3Vector3](box3vector3.html)* = new Box3Vector3(0, 0, 0) ��ʵ�����������ӵļ��ٶ� --- ### entity.particleNoise ? **particleNoise**: *number* = 0 ָ�����������֮ǰ�˶���������ƫ��ֵ����ֵԽ�󣬸������ӵ��˶����ԭ�з����ƫ��Խ���� --- ### entity.particleNoiseFrequency ? **particleNoiseFrequency**: *number* = 1 ָ�����Ӹı��˶������Ƶ�ʣ���ֵԽ�󣬸������ӵ��˶�����Խû�й��� **ʾ������** ``` // ��Ʈѩ world.onPlayerJoin(({ entity }) => { Object.assign(entity, { particleRate: 30, particleSize: [2, 2, 2, 2, 10], particleLifetime: 2, particleVelocity: new Box3Vector3(0, 0, 50), particleNoise: 20, particleNoiseFrequency: 10, }); }); ``` --- ## ������Ч ### �ϴ���Ч �༭��Ŀǰ������34����Ч�������ڲ˵�- **[�ļ�����]** ������ `.mp3` �鿴������ļ��󣬻ᵯ�������ļ����������ԡ���� **λ��** ���ɸ����ļ�·�����ڽű���ʹ�ö�Ӧ�ķ������š� �����ϴ��Զ��������������� **[�ļ�����]** ���ڣ�������½Ǹ����ļӺŰ�ť- **[�ϴ���Ƶ]** �� ### ���� ### entity.chatSound ? **chatSound**: *[Box3SoundEffect](box3soundeffect.html)??* = new Box3SoundEffect() ��ʵ��˵��ʱ������������Ч��Ĭ��Ϊ `'audio/chat.mp3'`��ͨ�� `entity.say()`������ --- ### entity.hurtSound ? **hurtSound**: *[Box3SoundEffect](box3soundeffect.html)??* = new Box3SoundEffect() ��ʵ�崥�������¼�ʱ������������Ч��Ĭ��Ϊ `'audio/hurt.mp3'`��ͨ��`entity.onTakeDamage()`���� --- ### entity.dieSound ? **dieSound**: *[Box3SoundEffect](box3soundeffect.html)??* = new Box3SoundEffect() ��ʵ�崥�������¼�ʱ������������Ч��Ĭ��Ϊ `'audio/die.mp3'`��ͨ��`entity.onDie()`���� --- ### entity.interactSound ? **interactSound**: *[Box3SoundEffect](box3soundeffect.html)??* = new Box3SoundEffect() ��ʵ����л���ʱ�����Ż�����Ч������Ч����������ҿ�������ͨ�� `entity.onInteract()`������ --- ### ���� ### entity.sound ? **sound**: *function* ��ʵ���λ�ò��������� **����** spec:{sample, radius, gain, pitch} | string
  • **sample** :string ��������ļ�·���������ļ����������ϴ��Զ����������� `'audio/chat.mp3'`

  • **radius** ?:number ��ѡ��������Χ��Ĭ��Ϊ32������ʵ��Խ������������Խ������������Χ�������������������

  • **gain** ?:number ��ѡ���������档����Ϊ1����ֵԽ������Խ�졣

  • **pitch** ?:number ��ѡ���������档����Ϊ1������1����������Խ�죬С��1����������Խ����

  • **ʾ��1** ``` entity.sound('audio/chat.mp3') ``` **ʾ��2** ``` // ���岥�ŵ��������� const bounceSound = { 'sample': 'audio/chat.mp3', // �����ļ� 'radius': 32, // ������Χ 'gain': 1, // �������� 'pitch': 1, // ���ߵ��� 'gainRange': 0, // �������淽�� 'pitchRange': 0, // �������淽�� } // ÿ3�룬������������𡣲����������� const bounceEvent = setInterval(() => { world.querySelectorAll('player').forEach((e) => { e.sound(bounceSound); // �������� e.velocity.y += 1; // ��ʵ��ʩ�����Ϸ����˶������� }); console.log('Jump'); }, 3000); // 9���ֹͣ������ setTimeout(() => { clearInterval(bounceEvent) console.log('Cancel Jump Event'); }, 9000); ``` **ʾ��3** ``` // ������/����ʱ�����ſ��Ż���ŵ������� function toggleDoor(entity) { if (entity.isOpen) { entity.sound('audio/door_close.mp3'); } else { entity.sound('audio/door_open.mp3'); } entity.isOpen = !entity.isOpen; } ``` --- ## ���� ### entity.animate ��������������趨ʵ��Ķ����켣 #### ��������: ? **animate**(`keyframes`: [Box3EntityKeyframe](box3entitykeyframe.html)[], `playbackInfo`:Partial< [Box3AnimationPlaybackConfig](box3animationplaybackconfig.html) >): [Box3Animation](box3animation.html) **����ʾ��** ``` //��Ҫ��ǰ�ڱ༭��������'��Ԫ����'��ģ�͡� const vox = world.querySelector('#��Ԫ����-1') //��ȡʵ�� vox.meshScale = vox.meshScale.scale(4) //��ʵ����4�� const ani = vox.animate([ { position: [0, 12, 0], meshColor: [1, 1, 0, 1] }, { position: [0, 12, 127], meshColor: [1, 0, 0, 1] }, { position: [127, 12, 127], meshColor: [0, 1, 0, 1] }, { position: [127, 12, 0], meshColor: [0, 0, 1, 1] }, ], { iterations: 3,//��3Ȧ direction: Box3AnimationDirection.WRAP,//���յ�ص���� duration: 16 * 5, //��һȦ5��(ÿ��16֡) }) ani.onReady(() => {//��������ʼ����ʱ world.say('��ʼ��Ȧ') }) ani.onFinish(() => {//��������������ʱ world.say('��Ȧ����') }) ``` --- # Interface: Box3EntityConfig ���ڿ���ʵ��IJ����� |����|����|˵�� |------ |position|[Box3Vector3](box3vector3.html)|ʵ���λ��| |velocity|[Box3Vector3](box3vector3.html)|ʵ�峯��ij�������˶���������| |collides|boolean|ʵ���Ƿ����ײ| |mesh|string|mesh������ʵ������Ρ�`'mesh/*.vb'`| |meshColor|[Box3RGBAColor](box3rgbacolor.html)|ʵ�����ɫ| |meshScale|[Box3Vector3](box3vector3.html)|ʵ������ű���| |meshOrientation|Box3Quaternion|ʵ�����ת�Ƕ�| |meshMetalness|number|ʵ��Ľ�����| |meshEmissive|number|ʵ��ķ����| |meshShininess|number|ʵ��ķ����| |gravity|boolean|ʵ���Ƿ������| |fixed|boolean|ʵ���λ���Ƿ�̶�����| |mass|number|ʵ������| |friction|number|ʵ���ճ��(0 = ����1 = ճ)| |restitution|number|ʵ��ĵ���(0 = ��, 1 = ��)| |enableInteract|boolean|����ʵ����л���| |interactRadius|number|����ʵ�廥���ķ�Χ����ΧԽС�����������| |interactHint|string|����ʵ�廥����Χʱ��ʵ�����ϳ��ֵ���ʾ�ı�| |interactColor|[Box3RGBAColor](box3rgbacolor.html)|����ʵ�廥����Χʱ����ʾ�ı���������ɫ| |particleRate|number|ʵ��ÿ��������ӵ�����| |particleRateSpread|number|����ʵ��ÿ��������������������| |particleLimit|number|ʵ��ɲ�����������������| |particleLifetime|number|ʵ�������������ܴ�������| |particleLifetimeSpread|number|����ʵ�����������Ӵ��ʱ��������| |particleSize|number[]|ʵ�����������ӵĴ�С�仯| |particleSizeSpread|number|����ʵ�����������Ӵ�С�������| |particleColor|Box3RGBColor[]|ʵ�����������ӵ���ɫ�仯| |particleVelocity|[Box3Vector3](box3vector3.html)|ʵ�����������ӵij�ʼ�ٶ�| |particleVelocitySpread|[Box3Vector3](box3vector3.html)|����ʵ�����������ӳ�ʼ�ٶȵ������| |particleDamping|number|ʵ�����������ӵ�����ϵ��| |particleAcceleration|[Box3Vector3](box3vector3.html)|ʵ�����������ӵļ��ٶ�| |particleNoise|number|ʵ�����������Ӱڶ���������| |particleNoiseFrequency|number|ʵ�����������Ӱڶ���Ƶ��| |chatSound|[Box3SoundEffect](box3soundeffect.html)|ʵ�崥��˵���¼�ʱ���ŵ���Ч| |interactSound|[Box3SoundEffect](box3soundeffect.html)|ʵ�崥�������¼�ʱ���ŵ���Ч| |hurtSound|[Box3SoundEffect](box3soundeffect.html)|ʵ�崥�������¼�ʱ���ŵ���Ч| |dieSound|[Box3SoundEffect](box3soundeffect.html)|ʵ�崥�������¼�ʱ���ŵ���Ч| # Interface: Box3HurtOptions ����/�˺�����ز��� |����|����|˵�� |------ |**attacker**|[Box3Entity](box3entity.html)|����������ʵ��| |**damageType**|string|�˺����ͣ������ж���| # Class: Box3EntityContact ���ڷ�����ײ��ʵ�� --- ### other ? **other**: *[Box3Entity](box3entity.html)* ���ʵ����ײ����һ��ʵ�� --- ### axis ? **axis**: *[Box3Vector3](box3vector3.html)* ��ײ�ķ����ᣬҲ������ײ�����嵯�ɵķ��� --- ### force ? **force**: *[Box3Vector3](box3vector3.html)* ��ײ���������� # Class: Box3Player [Player ���](box3player.html)ָ���ǽ�����Ϸ���û����˽ӿڿ��ö�����Ϸ�е�������ԡ������ȵȡ��������һ�������[ʵ��](box3entity.html)�� ## ���� ### name ? **name**: *string* = "player" ��ҵ��dzơ��޷����Ƹ��ġ� ``` // ����������У�ͨ���������ɸѡ��ijһλ��� const myPlayer = world.querySelectorAll('player').filter(e => e.player.name === '������')[0]; ``` ``` // ���'������'��'ħ����'������Ϸ���ᱻ��С��0.25����������Ҳ���Ӱ�� const TEST_PLAYER = ['������', 'ħ����'] world.onPlayerJoin(({ entity }) => { if (!TEST_PLAYER.includes(entity.player.name)) return entity.player.scale = 0.25; }) ``` --- ### boxId ? **boxId**: *string* = "" ��ҵ�Box ID(3-15�ַ�)���޷����Ƹ��ġ� �ο͵�`boxID`ֵΪ��`""` �� --- ### userKey ? **userKey**: *string* = "" ��ҵ�Ψһʶ����(16�ַ�)���������ڴ洢�����Ϣ�����ݿ⣬�޷����Ƹ��ġ� �ο͵�`userKey`ֵΪ��`""` �� --- ### spawnPoint ? **spawnPoint**: *[Box3Vector3](box3vector3.html)<>* = new Box3Vector3(64, 140, 64) ��ҵij����㡣Ĭ�ϳ����������� `new Box3Vector3(64, 140, 64)` --- ### movementBounds ? **movementBounds**: *[Box3Bounds3](box3bounds3.html)<>* = new [Box3Bounds3](box3bounds3.html)(new [Box3Vector3](box3vector3.html)(-50, -50, -50), new [Box3Vector3](box3vector3.html)(178, 178, 178)); ��ҵĻ��Χ���ƣ��糬���˷�Χ���򴫻س����� --- ## ����ҷ�����Ϣ ### directMessage ? **directMessage**(`message`: string): *void* �����ֱ�ӷ���˽�� ``` world.onPlayerJoin(({ entity }) => { entity.player.directMessage(`${entity.player.name}, ��á�`); }) ``` --- ### onChat ? **onChat**: *[Box3EventChannel](box3eventchannel.html)<[Box3ChatEvent](box3chatevent.html)>* ? **nextChat**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3ChatEvent](box3chatevent.html)>* ����������ʱ���� ``` world.onChat(({ entity, message }) => { // ����ҷ��͡�grow�����ֵ�ʱ��Ŵ�2��������ҷ��͡�shrink�����ֵ�ʱ����С2�� if (entity && entity.isPlayer) { if (message === 'grow') { entity.player.scale *= 2; } else if (message === 'shrink') { entity.player.scale /= 2; } world.say('adjusting scale of ' + entity.player.name + ' to ' + entity.player.scale); } }) ``` --- ### muted ? **muted**: *boolean* = false ���Ϊ�棬����Ҳ������� --- ### dialog ? **dialog**: *[Box3DialogCall](box3dialogcall.html)* ����Ϸ����ʾһ���Ի��� **ʾ������ 1** ``` /* ��ҽ�����Ϸʱ������һ����ӭ�Ի��� */ world.onPlayerJoin(({entity}) => { entity.player.dialog({ type: Box3DialogType.TEXT, title: "������", content: `��ã�${entity.player.name}���ܸ�����ʶ�㡣`, }); }) ``` **ʾ������ 2** ``` // ���ڳ����з���һ������Ϊ NPC ��ʵ�塣 const npc = world.querySelector('#npc'); npc.enableInteract = true; npc.interactHint = npc.id; npc.interactRadius = 16; // �����ʵ����н���ʱ���� npc.onInteract(async ({entity}) => { const result = await entity.player.dialog({ type: Box3DialogType.SELECT, title: npc.id, lookTarget:npc, content: `${entity.player.name}�����볢����ս�����Ϸ��`, options: ['��Ȼ', '�´ΰɡ�'], }); console.log(`ѡ���˵� index: ${result.index} ��ѡ��: ${result.value}`) // ���ѡ�˵�һ��ѡ�Ҳ����'��Ȼ'���ͻ�ִ���ض��¼� if (result.index === 0){ npc.say(`${result.value}���Ǿ����ɣ�`); } }); ``` ### cancelDialogs ? **cancelDialogs**: *function* �رո���ҵ����д򿪵ĶԻ��� ``` entity.player.cancelDialogs(); ``` --- ## ������ҵ���� ### color ? **color**: *[Box3RGBColor](box3rgbcolor.html)<>* = new Box3RGBColor(1, 1, 1) ��ҵ���ɫ --- ### emissive ? **emissive**: *number* = 0 ��ҵķ���� **ʾ������** ``` world.onPlayerJoin(({ entity }) => { // ʹ��ҷ��� entity.player.emissive = 1; }) ``` --- ### invisible ? **invisible**: *boolean* = false ����Ƿ����� **ʾ������** ``` world.onPlayerJoin(({ entity }) => { // ��������� entity.player.invisible = true; }) ``` --- ### skinInvisible ? **skinInvisible**: *[Box3SkinInvisible](box3skininvisible.html)* �������ģ�Ͳ����ӿ� **ʾ������** ``` world.onPlayerJoin(({entity}) => { // ������ҵ�ͷ�� entity.player.skinInvisible.head = true; }) ``` --- ### showName ? **showName**: *boolean* = true ��������Ƿ���ʾ --- ### scale ? **scale**: *number* = 1 ��ҵ����ű��� **ʾ������1** ``` world.onPlayerJoin(({entity}) => { // ��ҽ�����Ϸ��ʱ����С��0.25�� entity.player.scale = 0.25; }) ``` --- ### metalness ? **metalness**: *number* = 0 ��ҵĽ����� --- ### shininess ? **shininess**: *number* = 0 ��ҵķ���� --- ### addWearable ? **addWearable**: *function* �����ij���岿λ���ϴ���������� #### ��������: ? (`spec`: Partial?[Box3Wearable](box3wearable.html)?): *[Box3Wearable](box3wearable.html)* **����:** |����|���� |------ |`spec`|Partial?[Box3Wearable](box3wearable.html)?| **ʾ������** ``` world.onPlayerJoin(({ entity }) => { entity.player.addWearable({ bodyPart: Box3BodyPart.TORSO, mesh: 'mesh/��ɫ���.vb', orientation: new Box3Quaternion(0, 1, 0, 0).rotateY(Math.PI/2), scale: new Box3Vector3(0.5, 0.5, 0.5), offset: new Box3Vector3(0, 0, -0.45), }); }); ``` --- ### removeWearable ? **removeWearable**: *function* ��������岿λ�Ѹ��ϵĴ����������ɾ�� **`wearable`** is the wearable to remove #### ��������: ? (`wearable`: [Box3Wearable](box3wearable.html)): *void* **����:** |����|���� |------ |`wearable`|[Box3Wearable](box3wearable.html)| **ʾ������** ``` // ����ҽ���Һ��ʱ�Ѵ������'DZˮ��'�����ͷ�ϸ��� world.onFluidEnter(({ entity }) => { if (!entity.isPlayer) return; entity.player.addWearable({ bodyPart: Box3BodyPart.HEAD, mesh: 'mesh/DZˮ��.vb', orientation: new Box3Quaternion(0, 1, 0, 0), scale: new Box3Vector3(1, 1, 1), offset: new Box3Vector3(0, 0, 0.5), }); }); // ������뿪Һ��ʱ�������ͷ�ϵĴ������ɾ�� world.onFluidLeave(({ entity }) => { if (!entity.isPlayer) return; const headWears = entity.player.wearables(Box3BodyPart.HEAD); // ����ֻ��1��װ�� `headWears[0]` entity.player.removeWearable(headWears[0]); }); ``` --- ### wearables ? **wearables**: *function* �о�����������еĴ���������� #### ��������: ? (`bodyPart?`: [Box3BodyPart](box3bodypart.html)): *[Box3Wearable](box3wearable.html)[]* **����:** |����|����|˵�� |------ |`bodyPart?`|[Box3BodyPart](box3bodypart.html)|ij������岿λ��ѡ��| **ʾ������** ``` // ����������в�λ�Ĵ������ const allWearables = entity.player.wearables(); // �������ͷ���Ĵ������ const wearablesOnHead = entity.player.wearables(Box3BodyPart.HEAD); ``` --- ## Web��� ### link ? **link**: *function* ����ҵ���һ���������š����ڣ�������ת��������ͼ���������ӡ���Ŀǰ֧��������뵺�����è��΢�����¡�Bilibili��Ƶ�����ӣ� #### ��������: ? (`href`: string): *void* **����:** |����|����|˵�� |------ |`href`|string|���� URL| **ʾ������** ``` //���ڵ�ͼ��һ����Ϊ���š���ģ�� //��Ҹ�����"���������ť���ͻᵯ��һ�������ţ��������ũ����ͼ const door = world.querySelector('#��'); door.enableInteract = true; door.interactHint = `תȥ ����ũ��`; door.interactRadius = 3; door.onInteract(async ({entity}) => { entity.player.link('https://box3.codemao.cn/p/0df19bb54f0527d04dae') // ����Ҵ��͵��˵�ͼ���� }); ``` --- ### url ? **url**: *[URL](url.html)* ��ȡ����ҽ����ͼʱ���õ�URL���ӵ�ַ, ��Ҫ���ڻ�ȡURL����, �Ա�����Դ���������� **ʾ������** ``` console.log(entity.player.url.searchParams) ``` --- ## ��ҵĸ�������� ### forceRespawn:() �����ǿ���������������س����� ? **forceRespawn**(): void --- ### onRespawn ��Ҹ���ʱ���õ��¼� ? **onRespawn**: *[Box3EventChannel](box3eventchannel.html)<[Box3RespawnEvent](box3respawnevent.md)>* ? **nextRespawn**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3RespawnEvent](box3respawnevent.md)>* --- ### dead ����Ƿ�������������ֵhp����0���������������ᵹ�ڵ��ϡ� ? **dead**: boolean = false ������Ϊֻ���������޸ġ� --- ## ��������ӽ� ### cameraEntity ? **cameraEntity**: *[Box3Entity](box3entity.html) | null* = null �ڵ�һ�˳��ӽ�(FPS)������˳Ƹ����ӽ�(FOLLOW)�£�����ӽ��������ʵ�� --- ### cameraMode ? **cameraMode**: *[Box3CameraMode](box3cameramode.html)* �ӽ�ģʽ - Box3CameraMode.FPS - `"fps"` - ��һ�˳��ӽ� - Box3CameraMode.FOLLOW - `"follow"` - �����˳Ƹ����ӽ�(Ĭ��) - Box3CameraMode.FIXED - `"fixed"` - �����˳ƹ̶��ӽ� **ʾ������** ``` // ʹ�õ�һ�˳��ӽ� world.onPlayerJoin(({ entity }) => { entity.player.cameraMode = Box3CameraMode.FPS; console.log('setting camera mode:', entity.player.cameraMode); }); console.log('fps mode enabled'); ``` --- ### cameraPosition ? **cameraPosition**: *[Box3Vector3](box3vector3.html)<>* = new Box3Vector3(0, 0, 0) �̶��ӽ�(FIXED)�£���ͷ���۾�λ�� --- ### cameraTarget ? **cameraTarget**: *[Box3Vector3](box3vector3.html)<>* = new Box3Vector3(0, 0, 0) �̶��ӽ�(FIXED)�¾�ͷ�������Ŀ��� --- ### cameraUp ? **cameraUp**: *[Box3Vector3](box3vector3.html)<>* = new Box3Vector3(0, 1, 0) �̶��ӽ�(FIXED)�£���ͷ���ϵ�ʸ�� --- ### enable3DCursor ? **enable3DCursor**: *boolean* = false ������ҵ�3D��� **ʾ������** ``` world.onPlayerJoin(({ entity }) => { entity.player.enable3DCursor = true; }) ``` --- ## ��ҵ�������Ϣ ### enableAction0 - **enableAction0**: *boolean* = true
    ���Ϊfalse�� �ر�Action0����PC��Ϊ���������ֻ��˲�����ʾA��ť�� **ʾ������** ``` world.onPlayerJoin(({ entity }) => { // ��ҽ����ʱ��ر�ActionA�� entity.player.enableAction0 = false; }) ``` ����������/�ƶ������ⰴťA�� --- ### enableAction1 - **enableAction1**: *boolean* = true
    ���Ϊfalse�� �ر�ActionB����PC��Ϊ����Ҽ����ֻ��˲�����ʾB��ť�� ��������Ҽ�/�ƶ������ⰴťB�� --- ### action0Button ? **action0Button**: *boolean* = false ������/�ƶ������ⰴťA�� --- ### action1Button ? **action1Button**: *boolean* = false ����Ҽ�/�ƶ������ⰴťB�� --- ### crouchButton ? **crouchButton**: *boolean* = false �¶װ�ť --- ### facingDirection ? **facingDirection**: *[Box3Vector3](box3vector3.html)<>* = new Box3Vector3(1, 0, 0) ��ҳ��� --- ### jumpButton ? **jumpButton**: *boolean* = false ��Ծ��ť --- ### onPress ? **onPress**: *[Box3EventChannel](box3eventchannel.html)<[Box3InputEvent](box3inputevent.html)>* ? **nextPress**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3InputEvent](box3inputevent.html)>* ����Ұ��°�ťʱ���� --- ### onRelease ? **onRelease**: *[Box3EventChannel](box3eventchannel.html)<[Box3InputEvent](box3inputevent.html)>* ? **nextRelease**: *[Box3EventFuture](box3eventchannel.html#type-box3eventfuture)<[Box3InputEvent](box3inputevent.html)>* ������ɿ���ťʱ���� --- ### walkButton ? **walkButton**: *boolean* = false ���а�ť --- ## ������ҵ��ж� ### canFly ? **canFly**: *boolean* = false ���Ϊ��(true)����������ҷ��� **ʾ������** ``` //����������ҷ��� world.onPlayerJoin(({ entity }) => { entity.player.canFly = true; }); ``` --- ### spectator ? **spectator**: *boolean* = false ���Ϊ��(true)���������һ�����飬���Դ�ǽ --- ### enableJump ? **enableJump**: *boolean* = true ���Ϊ��(false)�������������Ծ **ʾ������** ``` //�����������Ծ world.onPlayerJoin(({ entity }) => { entity.player.enableJump = false; }); ``` --- ### enableDoubleJump ? **enableDoubleJump**: *boolean* = true ���Ϊ��(false)����������Ҷ�����Ծ **ʾ������** ``` //��������Ҷ�����Ծ world.onPlayerJoin(({ entity }) => { entity.player.enableDoubleJump = false; }); ``` --- ### walkSpeed ? **walkSpeed**: *number* = 0.22 ������ٶ� --- ### runSpeed ? **runSpeed**: *number* = 0.4 ������ٶ� --- ### runAcceleration ? **runAcceleration**: *number* = 0.35 ���ܼ��ٶ� --- ### jumpPower ? **jumpPower**: *number* = 0.96 ��Ծ���� --- ### jumpSpeedFactor ? **jumpSpeedFactor**: *number* = 0.85 ��Ծ�ٶ� --- ### jumpAccelerationFactor ? **jumpAccelerationFactor**: *number* = 0.55 ��Ծ������ --- ### doubleJumpPower ? **doubleJumpPower**: *number* = 0.9 ���������� --- ### crouchSpeed ? **crouchSpeed**: *number* = 0.1 ������·���ٶ� --- ### crouchAcceleration ? **crouchAcceleration**: *number* = 0.09 ������·�ļ��ٶ� --- ### flySpeed ? **flySpeed**: *number* = 2 �������ٶ� --- ### flyAcceleration ? **flyAcceleration**: *number* = 2 ���м��ٶ� --- ### swimAcceleration ? **swimAcceleration**: *number* = 0.1 ��Ӿ���ٶ� --- ### swimSpeed ? **swimSpeed**: *number* = 0.4 �����Ӿ�ٶ� --- ### walkAcceleration ? **walkAcceleration**: *number* = 0.19 ���м��ٶ� --- ## �鿴��ҵ�״̬ ### moveState ? **moveState** = [Box3PlayerMoveState](box3playermovestate.html).FALL ��ҵ��˶�״̬����ʼֵΪ���� --- ### walkState ? **walkState** = [Box3PlayerWalkState](box3playerwalkstate.html).NONE ��ҵIJ���״̬����ʼֵΪ�Dz����� ``` // �������Ƿ����ڱ��ܻ������ߣ����ֶ�Ӧ������Ч�� world.onPlayerJoin(({ entity }) => { world.onTick((tick) => { PlayerUpdate(entity)}); }); // ��ɫ���� const particle_blueCrystal = { particleRate: 1000, particleLifetime: 2, particleSize: [8, 6, 4, 2, 0.5], particleColor: [ new Box3RGBColor(1,1,0), new Box3RGBColor(1,1,0), new Box3RGBColor(1,0,0), new Box3RGBColor(1,0,0), new Box3RGBColor(1,1,1)], } // �������� const particle_flame = { particleRate: 450, particleLifetime: 1.75, particleSize: [2, 0.65, 0.23], particleColor: [ new Box3RGBColor(0,0,1), new Box3RGBColor(0,1,1), new Box3RGBColor(1,1,1)], } function PlayerUpdate(entity) { // �ж�����״̬ switch (entity.player.walkState) { // ���ڱ��� case Box3PlayerWalkState.RUN: Object.assign(entity, particle_blueCrystal); break; // �������� case Box3PlayerWalkState.WALK: Object.assign(entity, particle_flame); break; // ����������״̬����ʾ���� default: Object.assign(entity, { particleRate: 0 }); }; }; ``` --- ## ������Ч ### Ԥ����Ч ### action0Sound ? **action0Sound**: *[Box3SoundEffect](box3soundeffect.html)??* = new Box3SoundEffect() ����Ұ��� `'action0'` ������������ / ���ⰴťA��ʱ�����ŵ���Ч�� --- ### action1Sound ? **action1Sound**: *[Box3SoundEffect](box3soundeffect.html)??* = new Box3SoundEffect() ����Ұ��� `'action1'` ����������Ҽ� / ���ⰴťB��ʱ�����ŵ���Ч�� --- ### crouchSound ? **crouchSound**: *[Box3SoundEffect](box3soundeffect.html)??* = new Box3SoundEffect() ����Ұ��� `'crouchButton '` �������ж���ʱ�����ŵ���Ч�� --- ### jumpSound ? **jumpSound**: *[Box3SoundEffect](box3soundeffect.html)??* = new Box3SoundEffect() ����Ұ��� `'jumpButton '` ����������Ծʱ�����ŵ���Ч��Ĭ��Ϊ `'audio/jump.mp3'` --- ### doubleJumpSound ? **doubleJumpSound**: *[Box3SoundEffect](box3soundeffect.html)??* = new Box3SoundEffect() ����Ҵ���������ʱ�����ŵ���Ч��Ĭ��Ϊ `'audio/double_jump.mp3'` --- ### landSound ? **landSound**: *[Box3SoundEffect](box3soundeffect.html)??* = new Box3SoundEffect() ������ʱ�����ŵ���Ч��Ĭ��Ϊ `'audio/land.mp3'` --- ### enterWaterSound ? **enterWaterSound**: *[Box3SoundEffect](box3soundeffect.html)??* = new Box3SoundEffect() ����ҽ���Һ��ʱ�����ŵ���Ч��Ĭ��Ϊ`'audio/dive.mp3'` --- ### leaveWaterSound ? **leaveWaterSound**: *[Box3SoundEffect](box3soundeffect.html)??* = new Box3SoundEffect() ������뿪Һ��ʱ�����ŵ���Ч��Ĭ��Ϊ`'audio/splash.mp3'` --- ### swimSound ? **swimSound**: *[Box3SoundEffect](box3soundeffect.html)??* = new Box3SoundEffect() �����������Ӿʱ�����ŵ���Ч��Ĭ��Ϊ`'audio/swim.mp3'` ע����Ӿ����Ч��ǰ��ʱ�Ż�ѭ�����š������ˮ�о�ֹ���������Ქ����Ч�� --- ### spawnSound ? **spawnSound**: *[Box3SoundEffect](box3soundeffect.html)??* = new Box3SoundEffect() ���������ʱ�����ŵ���Ч��Ĭ��Ϊ`'audio/spawn.mp3'`��ͨ��`player.onRespawn()`���� --- ### stepSound ? **stepSound**: *[Box3SoundEffect](box3soundeffect.html)??* = new Box3SoundEffect() ���������ʱ��ÿ����һ�������ŵ���Ч��Ĭ��Ϊ`'audio/step.mp3'` --- ### startFlySound ? **startFlySound**: *[Box3SoundEffect](box3soundeffect.html)??* = new Box3SoundEffect() ��ҿ�ʼ����ʱ����Ч�� --- ### stopFlySound ? **stopFlySound**: *[Box3SoundEffect](box3soundeffect.html)??* = new Box3SoundEffect() ��ҽ�������ʱ���ŵ���Ч�� --- ### ������Ч ### sound ? **sound**: *function* Ϊָ������Ҳ��������������������������������������޷������� **����:** spec:{sample, gain, pitch} | string
  • **sample** :string ��������ļ�·���������ļ����������ϴ��Զ����������� `'audio/chat.mp3'`

  • **gain** ?:number ��ѡ���������档����Ϊ1����ֵԽ������Խ�졣

  • **pitch** ?:number ��ѡ���������档����Ϊ1������1����������Խ�죬С��1����������Խ����

  • **ʾ������1** ``` // ��ҽ��뷶Χʱ������ `boost` ������Ч�� const area = world.addZone({ selector: 'player', bounds: { lo: [59, 8, 59], hi: [66, 20, 66], }, }) // ����ҽ������� area.onEnter(({ entity }) => { entity.player.sound('audio/whistle.mp3') }); // ������뿪���� area.onLeave(({ entity }) => { entity.player.sound('audio/boost.mp3') }); ``` **ʾ������2** ``` /* ��Ҷ�����·ʱ, �в�ͬ������������Ч��*/ // �������� const crouchSound = new Box3SoundEffect(); crouchSound.sample = 'audio/hurt.mp3'; // ������������ const crouchWalkSound = new Box3SoundEffect(); crouchWalkSound.sample = 'audio/land.mp3'; // ��ҽ�����Ϸʱ world.onPlayerJoin(({ entity }) => { // ����ԭʼ���������� lastStepSound = entity.player.stepSound // ���ö��°�ť����Ч entity.player.crouchSound = crouchSound // ���¶��°�ť entity.player.onPress(({ button }) => { if(button === Box3ButtonType.CROUCH){ // ����·�����滻Ϊ�������ߵ����� entity.player.stepSound = crouchWalkSound; } }); // �ɿ����°�ť entity.player.onRelease(({ button }) => { if(button === Box3ButtonType.CROUCH){ // ����·������ԭ��ʼ������ entity.player.stepSound = lastStepSound; } }); }); ``` --- ### music ? **music**: *[Box3SoundEffect](box3soundeffect.html)??* = new Box3SoundEffect() Ϊָ������Ҳ��ű������֣�ѭ�����ţ��������������������������������޷������� �������ֵ�����������û���[����-����]���ġ� ``` // ����ұ�����������Ϊ���� entity.player.music.sample = 'audio/electic.mp3'; entity.player.music.gain = 0.5; // ���� 50% ``` --- ## �����˾� ### colorLUT ? **colorLUT**: *string* = "" ������Ⱦ���������Ϸ�����ɫ�� **ʾ������** ``` world.onPlayerJoin(({ entity:{ player } }) => { // ��ҽ�����Ϸ��ʱ�����������Ϸ�����ɫ�� const luts = resources.ls('lut'); const randLut = luts[(luts.length * Math.random()) | 0].path; player.directMessage('lut = ' + randLut) player.colorLUT = randLut; }); ``` ## ���� ### player.animate ��������������趨��ҵĶ������仯��ɫ #### ��������: ? **animate**(`keyframes`: [Box3PlayerKeyframe](box3playerkeyframe.html)[], `playbackConfig`:Partial< [Box3AnimationPlaybackConfig](box3animationplaybackconfig.html) >): [Box3Animation](box3animation.html) **����ʾ��** ``` // �������ұ�ɫ world.onPress(({ entity, button })=>{ if (button === Box3ButtonType.ACTION0) { // ���úùؼ�֡ let frames = [{ duration: 1, // �ؼ�֡��ʱ����Ĭ��Ϊ1tick color: [1,1,1], },{ color: [1,0,0], }] // Ϊ��Ҷ������Ӷ��� entity.player.animate(frames, { duration: 50, // ����ʱ�� direction: Box3AnimationDirection.NORMAL, // ���ŷ��� ��ͨ iterations: Infinity, // ���Ŵ������޴� }) } }) ``` ``` // �������˸ world.sunPhase = 0.75//��� world.onPlayerJoin(({ entity }) => { entity.player.animate([ { emissive: 0.0 }, { emissive: 0.5 }, ], { iterations: Infinity,//����ѭ�� direction: Box3AnimationDirection.WRAP,//���ȷ�������С duration: 16 * 2,//2��1������(ÿ��16֡) }) }) ``` # Enumeration: Box3PlayerMoveState ��ҵ��˶�״̬ |����|ֵ|˵�� |------ |FLYING|'fly'|������| |GROUND|'ground'|�ڵ���| |SWIM|'swim'|��Ӿ��| |FALL|'fall'|������| |JUMP|'jump'|��Ծ��| |DOUBLE_JUMP|'jump2'|��������| # Enumeration: Box3PlayerWalkState ��ҵ�����״̬ |����|ֵ|˵�� |------ |NONE|''|��������| |CROUCH|'crouch'|�¶�����| |WALK|'walk'|��������| |RUN|'run'|����| # Class: Box3Wearable ������������岿λ�ɴ����������IJ����뺯�� ### ���� - [bodyPart](box3wearable.html#bodypart) - [color](box3wearable.html#color) - [emissive](box3wearable.html#emissive) - [mesh](box3wearable.html#mesh) - [metalness](box3wearable.html#metalness) - [offset](box3wearable.html#offset) - [orientation](box3wearable.html#orientation) - [player](box3wearable.html#player) - [scale](box3wearable.html#scale) - [shininess](box3wearable.html#shininess) ### ���� - [remove](box3wearable.html#remove) ## ���ƴ�������IJ��� ### bodyPart ? **bodyPart**: *[Box3BodyPart](box3bodypart.html)* = Box3BodyPart.HEAD �������������ϵIJ�λ --- ### color ? **color**: *[Box3RGBColor](box3rgbcolor.html)??* = new Box3RGBColor(1, 1, 1) �����������ɫ --- ### emissive ? **emissive**: *number* = 0 ��������ķ���� --- ### mesh ? **mesh**: *string* = "" �����������״���� e.g. `mesh = 'mesh/my-mesh.vb'` ע��: `'mesh/my-mesh.vb'` �������ļ��б��У�Tips: �Ƚ�ģ�ͼӵ���ͼ�ϣ���ɾ�����ɡ��� --- ### metalness ? **metalness**: *number* = 0 ��������Ľ����� --- ### offset ? **offset**: *[Box3Vector3](box3vector3.html)??* = new Box3Vector3(0, 0, 0) ���������λ�� --- ### orientation ? **orientation**: *[Box3Quaternion](box3quaternion.html)??* = new Box3Quaternion(0, 1, 0, 0) �����������ת�Ƕ� --- ### player ? **player**: *[Box3Player](box3player.html) | null* = null ������������ --- ### scale ? **scale**: *[Box3Vector3](box3vector3.html)??* = new Box3Vector3(1, 1, 1) ������������ű��� --- ### shininess ? **shininess**: *number* = 0 ��������ķ���� ## ���� ### remove ? **remove**(): *void* **Returns:** *void* **ʾ������** ``` // ������뿪Һ��ʱ��������������еĴ������ɾ�� world.onFluidLeave(({ entity }) => { if (entity.isPlayer) { const allWearables = entity.player.wearables(); allWearables.forEach((item) => { item.remove(); }); } }); ``` # Enumeration: Box3BodyPart ������岿λ������ |����|ֵ|˵�� |------ |HIPS|'hips'|�β�| |TORSO|'torso'|����| |NECK|'neck'|����| |HEAD|'head'|ͷ| |LEFT_SHOULDER|'leftShoulder'|���| |LEFT_UPPER_ARM|'leftUpperArm'|���ϱ�| |LEFT_LOWER_ARM|'leftLowerArm'|���±�| |LEFT_HAND|'leftHand'|����| |LEFT_UPPER_LEG|'leftUpperLeg'|������| |LEFT_LOWER_LEG|'leftLowerLeg'|������| |LEFT_FOOT|'leftFoot'|���| |RIGHT_SHOULDER|'rightShoulder'|�Ҽ��| |RIGHT_UPPER_ARM|'rightUpperArm'|���ϱ�| |RIGHT_LOWER_ARM|'rightLowerArm'|���±�| |RIGHT_HAND|'rightHand'|����| |RIGHT_UPPER_LEG|'rightUpperLeg'|������| |RIGHT_LOWER_LEG|'rightLowerLeg'|������| |RIGHT_FOOT|'rightFoot'|�ҽ�| # Interface: Box3SkinInvisible �����������صIJ�λ |����|����|˵�� |------ |hips|boolean|�β�| |torso|boolean|����| |neck|boolean|����| |head|boolean|ͷ| |leftShoulder|boolean|���| |leftUpperArm|boolean|���ϱ�| |leftLowerArm|boolean|���±�| |leftHand|boolean|����| |leftUpperLeg|boolean|������| |leftLowerLeg|boolean|������| |leftFoot|boolean|���| |rightShoulder|boolean|�Ҽ��| |rightUpperArm|boolean|���ϱ�| |rightLowerArm|boolean|���±�| |rightHand|boolean|����| |rightUpperLeg|boolean|������| |rightLowerLeg|boolean|������| |rightFoot|boolean|�ҽ�| ## Box3DialogCall **Box3DialogCall**: *function* ����Ϸ����ʾһ���Ի���
    Ŀǰ֧��3�ֶԻ�����ʽ��[�ı��� Text](box3dialogcall.html#box3textdialogparams) / [ѡ��� Select](box3dialogcall.html#box3selectdialogparams) / [����� Input](box3dialogcall.html#box3inputdialogparams) Box3DialogCall =
    ((params:[Box3TextDialogParams](box3dialogcall.html#box3textdialogparams)) => Promise<[Box3DialogResponse](box3dialogcall.html#box3dialogresponse) | null> & [Box3DialogCancelOption](box3dialogcall.html#box3dialogcanceloption)) |
    ((params:[Box3SelectDialogParams](box3dialogcall.html#box3selectdialogparams)) => Promise<[DialogSelectResponse](box3dialogcall.html#dialogselectresponse) | null> & [Box3DialogCancelOption](box3dialogcall.html#box3dialogcanceloption)) |
    ((params:[Box3InputDialogParams](box3dialogcall.html#box3inputdialogparams)) => Promise<[Box3DialogResponse](box3dialogcall.html#box3dialogresponse) | null> & [Box3DialogCancelOption](box3dialogcall.html#box3dialogcanceloption)) | --- ## [Box3DialogParams](box3dialogcall.html#box3dialogparams) �Ի������� - �ı��Ի��� [Box3TextDialogParams](box3dialogcall.html#box3textdialogparams) - ѡ��Ի��� [Box3SelectDialogParams](box3dialogcall.html#box3selectdialogparams) - ����Ի��� [Box3InputDialogParams](box3dialogcall.html#box3inputdialogparams) ## [Box3DialogResponse](box3dialogcall.html#box3dialogresponse) �Ի���������Ӧ - [DialogSelectResponse](box3dialogcall.html#dialogselectresponse) --- ## Box3DialogParams �Ի��������б� **Box3DialogParams**: *object* #### ��������:
  • **type**: *[Box3DialogType](box3dialogtype.html)*
    �Ի�������͡�Ŀǰ�����ֶԻ������ͣ�����ɲ鿴 [Box3DialogType](box3dialogcall.html#box3dialogparams)
  • **content**: *string*
    �Ի�����ʾ���������ݡ�֧��ʹ��'/n' ���С�
  • **contentBackgroundColor**? : *[Box3RGBAColor](box3rgbacolor.html)*
    �Ի������Ĵ��ڵı�����ɫ��
  • **contentTextColor**? : *[Box3RGBAColor](box3rgbacolor.html)*
    �Ի��������������ɫ��
  • **title**: *string*
    �Ի�����ʾ�ı������ơ�
  • **titleBackgroundColor** ? : *[Box3RGBAColor](box3rgbacolor.html)*
    �Ի�����ʾ�ı��ⴰ�ڱ�����ɫ��
  • **titleTextColor** ? : *[Box3RGBAColor](box3rgbacolor.html)*
    �Ի�����ʾ�ı���������ɫ��
  • **hasArrow** ? : *undefined | false | true*
    ��ѡ: ��������������µĶԻ����ڵ�ǰ�Ի������Ƿ���ʾ��ͷ��ʾ��
    �����ı��Ի���*[Box3DialogType.TEXT](box3dialogtype.html#text)* ��ʹ�á�
  • **confirmText** ? : *undefined | string*
    ��ѡ: ��������Ի��� *[Box3DialogType.INPUT](box3dialogtype.html#input)* ʹ�á�
    ȷ�ϰ�ť��ʾ���ı������Ϊ�գ���ť�ı�Ĭ����ʾΪ 'ȷ�� | Confirm'.
  • **options** ? : *string[]*
    ��ѡ: ����ѡ��Ի��� *[Box3DialogType.SELECT](box3dialogtype.html#select)* ��ʹ�á�
    �ڶԻ������ṩһЩ�ɹ����ѡ��ĶԻ�ѡ�
  • **placeholder** ? : *undefined | string*
    ��ѡ: ��������Ի��� *[Box3DialogType.INPUT](box3dialogtype.html#input)* ��ʹ�á�
    ������򱳾���ʾ����ʾ���֡�
  • **lookTarget** ?: *[Box3Vector3](box3vector3.html) | [Box3Entity](Box3Entity.md)*
    ��ѡ: ʹ�����ͷ����ָ��ʵ��������λ�á�
  • **lookTargetOffset** ?: *[Box3Vector3](box3vector3.html)*
    ��ѡ: ������ָ����ע��Ŀ�꣬�������û���Ŀ��λ�õ�ƫ�ơ�
  • **lookUp** ?: *[Box3Vector3](box3vector3.html)*
    ��ѡ: �������̧ͷ������ʹ�����������ҵߵ���
  • **lookEye** ?: *[Box3Vector3](box3vector3.html) | [Box3Entity](Box3Entity.md)*
    ��ѡ: ���������λ�á�
  • **lookEyeOffset** ?: *[Box3Vector3](box3vector3.html)*
    ��ѡ: ������λ��ָ����ʵ�壬�������û���Ŀ��λ�õ�ƫ�ơ�

  • **��ʾ��**�� ``` // ��ҽ�����Ϸʱ������һ���Ի��� world.onPlayerJoin(({ entity }) => { const dialog = entity.player.dialog({ type: Box3DialogType.TEXT, title: "������", content: `��ã�${entity.player.name}���ܸ�����ʶ�㡣`, }); }); ``` **ʵ�廥��ʾ��**�� ��ʵ�廥��֮ǰ���ڳ����б�������һ��ʵ�塣
    ��ģ���б��У���ѡһ����ϲ����ģ�ͣ����������ڳ����У�����סģ�͵����֡� ``` // ���ڳ����з���һ������Ϊ NPC ��ʵ�塣 const npc = world.querySelector('#NPC'); npc.enableInteract = true; // �������л��� npc.interactRadius = 16; // ʵ��Ļ�����Χ npc.interactHint = npc.id; // ������ʾ����ʾʵ������� npc.interactColor = new Box3RGBColor(1,1,1); // ������ʾ��������ɫ // �����ʵ����н���ʱ���� npc.onInteract(async({entity}) => { const result = await entity.player.dialog({ type: Box3DialogType.TEXT, // �Ի�������ͣ�TEXT���ı��� title: npc.id, // �Ի������ΪNPC���֣���ʾ����˵������NPC lookEye: entity, // ������������λ�� lookTarget: npc, // �����ͷ��׼NPC content: `��ã�${entity.player.name}���ܸ�����ʶ�㡣`, }); }); ``` --- ## Box3TextDialogParams �ı��Ի������ **Box3TextDialogParams**: *object* #### ��������:
  • **type**: *[Box3DialogType.TEXT](box3dialogtype.html#text)*
    �Ի������͡��ı��Ի���������� `Box3DialogType.TEXT`
  • **hasArrow** ? : *undefined | false | true*
    �Ƿ���ʾ��ͷ��ʾ
  • **content**: *string*
    �Ի�����ʾ���������ݡ�֧��ʹ��'/n' ���С�
  • **contentBackgroundColor** ? : *[Box3RGBAColor](box3rgbacolor.html)*
    ���ı�����ɫ
  • **contentTextColor** ? : *[Box3RGBAColor](box3rgbacolor.html)*
    ����������ɫ
  • **title**: *string*
    �Ի������
  • **titleBackgroundColor** ? : *[Box3RGBAColor](box3rgbacolor.html)*
    ���ⱳ����ɫ
  • **titleTextColor** ? : *[Box3RGBAColor](box3rgbacolor.html)*
    ����������ɫ
  • **lookTarget** ? : *[Box3Vector3](box3vector3.html) | [Box3Entity](Box3Entity.md)*
    ���ע�ӵ�ʵ��
  • **lookTargetOffset** ? : *[Box3Vector3](box3vector3.html)*
    �������ע�ӵ�λ��ƫ��
  • **lookUp** ? : *[Box3Vector3](box3vector3.html)*
    ���̧ͷ����
  • **lookEye** ?: *[Box3Vector3](box3vector3.html) | [Box3Entity](Box3Entity.md)*
    �����ͷ��λ��
  • **lookEyeOffset** ?: *[Box3Vector3](box3vector3.html)*
    �������λ�õ�ƫ��
  • ``` // ��ҽ�����Ϸʱ������һ���ı��Ի��� world.onPlayerJoin(({ entity }) => { const dialog = entity.player.dialog({ type: Box3DialogType.TEXT, title: "������", // �Ի�����⡣ͨ����Ӧ�ǽ����˵����֡� titleTextColor: new Box3RGBAColor(0, 0, 0, 1), // ����������ɫ�� titleBackgroundColor: new Box3RGBAColor(0.968, 0.702, 0.392, 1), // ���ⱳ����ɫ�� content: `��ã�${entity.player.name}���ܸ�����ʶ�㡣`, // �Ի������ݡ�Ҳ���ǶԻ����ڽ�ʲô�� contentTextColor: new Box3RGBAColor(0, 0, 0, 1), // �Ի���������ɫ�� contentBackgroundColor: new Box3RGBAColor(1, 1, 1, 1), // �Ի��򱳾���ɫ�� lookEye: entity.position.add(entity.player.facingDirection.scale(5)), // �������λ�ã�������ҳ����ǰ��5����롣 lookTarget: entity, // �������ͷ�������ʵ�塣 }); }); ``` --- ## Box3SelectDialogParams ѡ��Ի������ **Box3SelectDialogParams**: *object* #### ��������:
  • **type**: *[Box3DialogType.SELECT](box3dialogtype.html#select)*
    �Ի������͡�ѡ��Ի���������� `Box3DialogType.SELECT`
  • **options** ? : *string[]*
    ѡ���б�
  • **content**: *string*
    �Ի�����ʾ���������ݡ�֧��ʹ��'/n' ���С�
  • **contentBackgroundColor** ? : *[Box3RGBAColor](box3rgbacolor.html)*
    ���ı�����ɫ
  • **contentTextColor** ? : *[Box3RGBAColor](box3rgbacolor.html)*
    ����������ɫ
  • **title**: *string*
    �Ի������
  • **titleBackgroundColor** ? : *[Box3RGBAColor](box3rgbacolor.html)*
    ���ⱳ����ɫ
  • **titleTextColor** ? : *[Box3RGBAColor](box3rgbacolor.html)*
    ����������ɫ
  • **lookTarget** ? : *[Box3Vector3](box3vector3.html) | [Box3Entity](Box3Entity.md)*
    ���ע�ӵ�ʵ��
  • **lookTargetOffset** ? : *[Box3Vector3](box3vector3.html)*
    �������ע�ӵ�λ��ƫ��
  • **lookUp** ? : *[Box3Vector3](box3vector3.html)*
    ���̧ͷ����
  • **lookEye** ?: *[Box3Vector3](box3vector3.html) | [Box3Entity](Box3Entity.md)*
    �����ͷ��λ��
  • **lookEyeOffset** ?: *[Box3Vector3](box3vector3.html)*
    �������λ�õ�ƫ��

  • ``` // ��ҽ�����Ϸʱ������һ��ѡ��Ի��� world.onPlayerJoin(async({ entity }) => { const result = await entity.player.dialog({ type: Box3DialogType.SELECT, title: "������", titleTextColor: new Box3RGBAColor(0, 0, 0, 1), titleBackgroundColor: new Box3RGBAColor(0.968, 0.702, 0.392, 1), content: `${entity.player.name}������԰��Ҹ�æ��`, options: ['û���⣡', '����û�գ��´�һ����'], // ���ṩ���ѡ���ѡ���������� contentTextColor: new Box3RGBAColor(0, 0, 0, 1), contentBackgroundColor: new Box3RGBAColor(1, 1, 1, 1), lookEye: entity.position.add(entity.player.facingDirection.scale(5)), lookTarget: entity, }); // �����ҵ������Ļ��������ȡ���˶Ի��� if(!result || result === null){ entity.player.directMessage('���ƺ������˼�������'); return; } // �ж����ѡ��ʲôѡ� switch (result.index) { case 0: // ���ѡ���˵�һ�����'û����' entity.player.directMessage('�������е��ܿ��ģ���������һ���컨��'); entity.player.walkSpeed += 1 world.say(`${entity.player.name} �����˼�����������˼������Ľ�����[�����ٶȼӿ���]`) break; case 1: // ���ѡ���˵ڶ������'����û��' entity.player.directMessage('������ʧ�����뿪�ˡ�'); break; default: // ע�⣬ʹ�� switch ��֧��ʱ�򣬲�Ҫ©�˺���� break; } }); ``` --- ## Box3InputDialogParams ����Ի������ **Box3InputDialogParams**: *object* #### ��������:
  • **type**: *[Box3DialogType.INPUT](box3dialogtype.html#input)*
    �Ի������͡�����Ի���������� `Box3DialogType.INPUT`
  • **confirmText** ? : *undefined | string*
    ȷ�ϰ�ť����
  • **placeholder** ? : *undefined | string*
    �������ʾ����
  • **content**: *string*
    �Ի�����ʾ���������ݡ�֧��ʹ��'/n' ���С�
  • **contentBackgroundColor** ? : *[Box3RGBAColor](box3rgbacolor.html)*
    ���ı�����ɫ
  • **contentTextColor** ? : *[Box3RGBAColor](box3rgbacolor.html)*
    ����������ɫ
  • **title**: *string*
    �Ի������
  • **titleBackgroundColor** ? : *[Box3RGBAColor](box3rgbacolor.html)*
    ���ⱳ����ɫ
  • **titleTextColor** ? : *[Box3RGBAColor](box3rgbacolor.html)*
    ����������ɫ
  • **lookTarget** ? : *[Box3Vector3](box3vector3.html) | [Box3Entity](Box3Entity.md)*
    ���ע�ӵ�ʵ��
  • **lookTargetOffset** ? : *[Box3Vector3](box3vector3.html)*
    �������ע�ӵ�λ��ƫ��
  • **lookUp** ? : *[Box3Vector3](box3vector3.html)*
    ���̧ͷ����
  • **lookEye** ?: *[Box3Vector3](box3vector3.html) | [Box3Entity](Box3Entity.md)*
    �����ͷ��λ��
  • **lookEyeOffset** ?: *[Box3Vector3](box3vector3.html)*
    �������λ�õ�ƫ��

  • ``` // ��ҽ�����Ϸʱ������һ��ѡ��Ի��� world.onPlayerJoin(async({ entity }) => { const result = await entity.player.dialog({ type: Box3DialogType.INPUT, title: "������", titleTextColor: new Box3RGBAColor(1, 1, 1, 1), titleBackgroundColor: new Box3RGBAColor(0, 0, 0, 0.98), content: `${entity.player.name}����֪���������ص�ͼ�İ�����`, confirmText: 'ȷ��', // ȷ����ť��������֡�����ȷ����ť���ύ�ش� placeholder: '��˵����һ���dz��ɰ��ijƺ���', // ����򱳾��ϵ���ʾ���֡� contentTextColor: new Box3RGBAColor(1, 1, 1, 1), contentBackgroundColor: new Box3RGBAColor(0, 0, 0, 0.98), lookEye: entity.position.add(entity.player.facingDirection.scale(5)), lookTarget: entity, }); // �����ҵ������Ļ��������ȡ���˶Ի��� if(!result || result === null){ entity.player.directMessage('���ƺ������˼�������'); return; } entity.player.directMessage(`��ش���: ${result}` ); // �ж��������Ƿ�Ϊij��ֵ�������кܶ��֡� // ��ʽһ����ͨ�õĴ𰸷��������С�ֻҪ������������һ���ʹ����� const surprise = ['������', 'box3'] if(surprise.includes(result)){ entity.player.directMessage(`${result} ����Ӵ~` ); } // ��ʽ��������Ӧ�Ĵ𰸱�����JSON. // JSON �ĸ�ʽΪ { 'Key': Value, ... } // �����Key, �������Լ�����ʶ��Ĺؼ��ʡ� // �ұ���value, ������������д���ַ����𰸡� const cheat = { 'big' : '���', 'small' : '��С', 'cute' : '��ɰ�', }; switch (result) { case cheat.big: // ������������ '���' entity.player.directMessage('���'); entity.player.scale *= 3; break; case cheat.small: // ������������ '��С' entity.player.directMessage('��С��'); entity.player.scale /= 2; break; case cheat.cute: // ������������ '��ɰ�' entity.player.directMessage('��ɰ���'); entity.player.scale = 0.25; break; default: // ע�⣬ʹ�� switch ��֧��ʱ�򣬲�Ҫ©�˺���� break; } }); ``` --- ## Box3DialogResponse �Ի����Ӧ
    ���û����ɶԻ�������������ط���ʹ�Ի���ȡ�����򷵻� `null`
    ������ı��Ի��򣬻�Ӧ `'success'`
    �����ѡ��Ի��򣬻�Ӧ�������д�������ַ���
    �����ѡ��Ի��򣬻�Ӧ *[DialogSelectResponse](box3dialogcall.html##dialogselectresponse)* **Box3DialogResponse**: *[DialogSelectResponse](box3dialogcall.html##dialogselectresponse) | string = 'success' | null* --- ### DialogSelectResponse ѡ��Ի����Ӧ
    ��ѡ��Ի����У���ҵ���˰�ť����õ��Ի���Ļ�Ӧ�¼������ر���Ұ��µ�ѡ����Ϣ�� **DialogSelectResponse**: *object* #### ��������: - ѡ���� **index**: *number* ��zero-based ��0��ʼ������ - ѡ������ **value**: *string* --- **�ۺ�ʾ�� 1** ``` /* ��ʵ�廥��ʱ������һ���򵥵���϶Ի� */ // ���ڳ����з���һ������Ϊ �󶵶� ��ʵ�塣 const npc = world.querySelector('#�󶵶�'); npc.enableInteract = true; // �������л��� npc.interactRadius = 8; // ʵ��Ļ�����Χ npc.interactHint = npc.id; // ������ʾ����ʾʵ������� npc.interactColor = new Box3RGBColor(1,1,1); // ������ʾ��������ɫ // �����ʵ����н���ʱ���� npc.onInteract(async ({entity, targetEntity}) => { // ׼����̨�ʾ籾�������������С� const npcScript = [ { type: Box3DialogType.TEXT, title: targetEntity.id, content: "��ǰ�и�С���Ѻܻ�", hasArrow: true, }, { type: Box3DialogType.TEXT, title: targetEntity.id, content: "������������", hasArrow: true, }, { type: Box3DialogType.TEXT, title: targetEntity.id, content: "���������м���", }, { type: Box3DialogType.SELECT, title: targetEntity.id, content: `${entity.player.name}!! o((>��< ))o`, options: ["�����úó԰���", "�Ҷ��ˣ�"], }]; // ͨ��ѭ������ȡ����ij��ȣ����籾��˳�����Ի��� for (i=0; i < npcScript.length; i++){ // Ϊ�������ݳ�Ч������ʵ��Ҳ��˵���������Ǿ籾�����ݡ� targetEntity.say(npcScript[i].content); // �����Ի��� const dialog = await entity.player.dialog(npcScript[i]); // ����Ի�����ѡ�����ͶԻ��򣬾�����������¼��� if (!dialog || npcScript[i].type != Box3DialogType.SELECT) continue; // Ϊ�������ݳ�Ч������ʵ��Ҳ��˵�������������ѡ������� targetEntity.say(dialog.value); } }); ``` **�ۺ�ʾ�� 2** ``` /* ��ҽ�����Ϸʱ������һ���򵥵���϶Ի� */ world.onPlayerJoin(async({ entity }) => { npcScript = [ { type: Box3DialogType.TEXT, content: `��ã�${entity.player.name}�����ǵ�һ����������`, hasArrow: true, }, { type: Box3DialogType.SELECT, title: entity.player.name, options: ['��һ����', '������ֹһ���ˣ�'], }, { type: Box3DialogType.TEXT, content: `��ӭ�㡣`, }, { type: Box3DialogType.TEXT, content: `�����һ��������С����`, }, { type: Box3DialogType.TEXT, content: `�Ĵ������Ű���ϣ����`, }, { type: Box3DialogType.TEXT, content: `���������ﶼ�����Ҹ����ֵ����`, }, ]; for (i=0; i < npcScript.length; i++){ console.log('' + i + ' / ' + npcScript[i]); const dialog = await entity.player.dialog(npcScript[i]); if (i === 1 && dialog.value === '������ֹһ���ˣ�') { entity.player.directMessage('���������ε��߿��ˡ�'); return; } } }); ``` --- ### Box3DialogCancelOption **Box3DialogCancelOption**: *object* #### ��������: - **cancel**(): *function* �رնԻ��� --- **�ۺ�ʾ�� 1** ``` world.onPlayerJoin(async ({ entity }) => { // ��ҽ�����Ϸʱ������һ����ӭ�Ի��� const dialog = entity.player.dialog({ type: Box3DialogType.TEXT, title: "������", content: `��ã�${entity.player.name}���ܸ�����ʶ�㡣`, }); // �ȴ��κ�һ�� [��ҵ����رնԻ��� 3����Զ��ѶԻ���ر�] Promise.race([ dialog, (async () => { await sleep(3000); dialog.cancel(); })() ]).then( /* �κ�һ���������� */ ); }) ``` **�ۺ�ʾ�� 2** ``` world.onPlayerJoin(async ({ entity }) => { // ��ҽ�����Ϸʱ������һ����ӭ�Ի��� const dialog = entity.player.dialog({ type: Box3DialogType.TEXT, title: "������", content: `��ã�${entity.player.name}���ܸ�����ʶ�㡣`, }); // 3����Զ��ر� setTimeout(()=>{ dialog.cancel(); },3000); }) ``` --- # Enumeration: Box3DialogType �Ի�����ʽ���� |����|ֵ|˵�� |------ |TEXT|'text'|�ı���ʽ�Ի���| |INPUT|'input'|������ʽ�Ի���| |SELECT|'select'|ѡ����ʽ�Ի���| ### Type **Box3EventChannel** **EventChannel** �����ڼ���ָ��������¼��������¼�������`handler`������ȡ�����¼���������[token](box3eventhandlertoken.html) #### ��������: **Box3EventChannel**?EventType? = (`handler`:(`event`: EventType) => void) => *[Box3EventHandlerToken](box3eventhandlertoken.html)*; **����:** |����|˵�� |------ |`handler`|�¼�����ʱ���õĴ�����| **����ֵ:** |����|˵�� |------ |[Box3EventHandlerToken](box3eventhandlertoken.html)|������ȡ���¼�������| **ʾ������:** ``` // 1000�����ֹͣ��ʱ const token = world.onTick(() => console.log("tick !")); setTimeout(() => { console.log('cancel tick handler'); token.cancel();// ȡ����¼tick�¼� }, 1000); ``` ### Type **Box3EventFuture** ���߼��÷���Promises ����һ�ִ����¼��ķ�ʽ�������Խṹ���ij����������ϳ����¼����С� �������Ĵ�����򵥡��ɾ������������ʹ�á� ��Ϊ�첽�����ڵȴ�ʱ���ܻ��жϣ��ڴ��ڼ���������������Ѿ������˱仯��ͬʱ���첽�����з����Ĵ���û�ж�ջ׷��(Stack trace)���õ��Ա�ø����ӡ� ��ס�������⣬Ȼ��������promises�ɡ� #### ����ʾ�� ``` //�ȴ�2����ҽ������磬������game ready�� async function waitForPlayers (count) { while (world.querySelectorAll('player').length < 2) { const { entity } = await world.nextPlayerJoin(); world.say(entity.player.name + ' joined'); } } waitForPlayers().then(() => world.say('game ready')); ``` #### ��������: **Box3EventFuture**?EventType? = (`filter?`:(`event`: EventType) => boolean) => `Promise`< EventType >; **����:** |����|˵�� |------ |`filter?`|��ѡ����ڼ���¼����͵ĺ��������filterֵ��Ϊ�棬������¼�δ������������趨filter����Future������һ���¼����á�| |EventType|��EventFuture�������¼�����| **����ֵ:** |����|˵�� |------ |Promise|A promise which resolves once an event which matches the filter fires| **�¼��б�:** - [Box3TickEvent ʱ��](box3tickevent.html) - [Box3ClickEvent ���](box3clickevent.html) - [Box3InputEvent ����](box3inputevent.html) - [Box3ChatEvent ����](box3chatevent.html) - [Box3InteractEvent ����](box3interactevent.html) - [Box3EntityEvent ʵ�崴��/����](box3entityevent.html) - [Box3EntityContactEvent ʵ�崥��](box3entitycontactevent.html) - [Box3VoxelContactEvent ��������](box3voxelcontactevent.html) - [Box3FluidContactEvent ����Һ��](box3fluidcontactevent.html) - [Box3DamageEvent ʵ���˺�](box3damageevent.html) - [Box3DieEvent ʵ������](box3dieevent.html) - [Box3TriggerEvent ������](box3triggerevent.html) # Class: Box3TickEvent ÿһ��(tick)����һ�ε��¼����� [Box3World.onTick](box3world.html#onTick) ������ **ʾ������** ``` world.onTick((tickEvent) => { console.log(tickEvent.elapsedTimeMS); console.log(tickEvent.prevTick); console.log(tickEvent.skip); console.log(tickEvent.tick); }) ``` --- ### elapsedTimeMS ? **elapsedTimeMS**: *number* Wall clock time between ticks ����ʱ��֮���ʱ���� --- ### prevTick ? **prevTick**: *number* Last tick which was handled ��һ���Ѵ�����ʱ�� --- ### skip ? **skip**: *boolean* �Ƿ���Ϊ�����ӳٶ�������ijЩʱ�� --- ### tick ? **tick**: *number* �¼�����ʱ�� # Class: Box3EntityEvent ������������ʵ��ʱ�������¼��� �� [Box3World.onPlayerJoin](box3world.html#onPlayerJoin), [Box3World.onPlayerLeave](box3world.html#onPlayerLeave), [Box3World.onEntityCreate](box3world.html#onEntityCreate), [Box3World.onEntityDestroy](box3world.html#onEntityCreate) �� [Box3Entity.onDestroy](box3entity.html#onDestroy) ���� ``` world.onPlayerJoin((entityEvent) => { // entityEvent.entity // entityEvent.tick }); ``` --- ### entity ? **entity**: *[Box3Entity](box3entity.html)* ����/���ٵ�ʵ�� --- ### tick ? **tick**: *number* �¼�����ʱ�� # Class: Box3EntityContactEvent ������ʵ����ײʱ�������¼��� �� [Box3World.onEntityContact](box3world.html#onEntityContact), [Box3World.onEntitySeparate](box3world.html#onEntitySeparate), [Box3Entity.onEntityContact](box3entity.html#onEntityContact), [Box3Entity.onEntitySeparate](box3entity.html#onEntitySeparate) ���� --- ### axis ? **axis**: *[Box3Vector3](box3vector3.html)* ��ײ�ķ����ᣬҲ������ײ�����嵯�ɵķ��� --- ### entity ? **entity**: *[Box3Entity](box3entity.html)* ��ײ�еĵ�һ��ʵ�� --- ### force ? **force**: *[Box3Vector3](box3vector3.html)* ��ײ���������� --- ### other ? **other**: *[Box3Entity](box3entity.html)* ��ײ�еĵڶ���ʵ�� --- ### tick ? **tick**: *number* ����ʵ����ײ��ʱ�� # Class: Box3VoxelContactEvent ��ʵ�崥������ʱ�������¼��� �� [Box3World.onVoxelContact](box3world.html#onVoxelContact), [Box3World.onVoxelSeparate](box3world.html#onVoxelSeparate), [Box3Entity.onVoxelContact](box3entity.html#onVoxelContact), [Box3Entity.onVoxelSeparate](box3entity.html#onVoxelSeparate) ���� --- ### axis ? **axis**: *[Box3Vector3](box3vector3.html)* �����ķ����ᣬҲ���Ǵ��������嵯�ɵķ��� --- ### entity ? **entity**: *[Box3Entity](box3entity.html)* �����������ʵ�� --- ### force ? **force**: *[Box3Vector3](box3vector3.html)* ��ײ�� --- ### tick ? **tick**: *number* ʵ�崥�������ʱ�� --- ### voxel ? **voxel**: *number* �������ķ���id --- ### x ? **x**: *number* �����������x���� --- ### y ? **y**: *number* �����������y���� --- ### z ? **z**: *number* �����������z���� # Class: Box3FluidContactEvent ��ʵ�������뿪Һ��ʱ�������¼��� �� [Box3World.onFluidEnter](box3world.html#onFluidEnter), [Box3World.onFluidLeave](box3world.html#onFluidLeave), [Box3Entity.onFluidEnter](box3entity.html#onFluidEnter), [Box3Entity.onFluidLeave](box3entity.html#onFluidEnter) ���� ``` world.onFluidEnter(({entity, tick, voxel}) => { }) ``` --- ### entity ? **entity**: *[Box3Entity](box3entity.html)* ����Һ���ʵ�� --- ### tick ? **tick**: *number* ʵ�������뿪Һ���ʱ�� --- ### voxel ? **voxel**: *number* Һ�巽��id # Class: Box3TriggerEvent ��ʵ��/��Ҵ���������¼��� �� [Box3Zone.onEnter](box3zone.html#onEnter), [Box3Zone.onLeave](box3zone.html#onLeave), [Box3Zone.nextEnter](box3zone.html#nextEnter), [Box3Zone.nextLeave](box3zone.html#nextLeave) ���� ### ���� - [entity](box3triggerevent.html#entity) - [tick](box3triggerevent.html#tick) ## ���� ### entity ? **entity**: *[Box3Entity](box3entity.html)* �����¼���ʵ�� --- ### tick ? **tick**: *number* �����¼���ʱ�� # Class: Box3DamageEvent ��ʵ���յ��˺�ʱ�������¼�����[Box3World](box3world.html).[onTakeDamage](box3world.html#onTakeDamage)��[Box3Entity](box3entity.html).[onTakeDamage](box3entity.html#onTakeDamage)���� ### tick ? **tick**: *number* �¼�������ʱ�� --- ### entity ? **entity**: *[Box3Entity](box3entity.html)* �ܵ��˺���ʵ�� --- ### damage ? **damage**: *number* �˺�ֵ�Ĵ�С --- ### attacker ? **attacker**: *[Box3Entity](box3entity.html)*|null ������ --- ### damageType ? **damageType**: *string* �˺������� # Class: Box3DieEvent ��ʵ������ʱ�������¼�����[Box3World](box3world.html).[onDie](box3world.html#onDie)��[Box3Entity](box3entity.html).[onDie](box3entity.html#onDie)���� --- ### tick ? **tick**: *number* �¼�������ʱ�� --- ### entity ? **entity**: *[Box3Entity](box3entity.html)* ������ʵ�� --- ### attacker ? **attacker**: *[Box3Entity](box3entity.html)*|null ��ɱ�� --- ### damageType ? **damageType**: *string* �˺������� # Class: Box3ChatEvent �����촥�����¼� ͨ�� [Box3World.onChat](box3world.html#onChat) �� [Box3Entity.onChat](box3entity.html#onChat) ���� --- ### entity ? **entity**: *[Box3Entity](box3entity.html)* ���������ʵ�� --- ### message ? **message**: *string* �����¼���˵�������� --- ### tick ? **tick**: *number* �����¼�����ʱ�� --- # Class: Box3ClickEvent ������������ʵ��ʱ�������¼� --- ### button ? **button**: *[ACTION0](box3buttontype.html#action0) | [ACTION1](box3buttontype.html#action1)* ������İ�ť��ACTION0 = �����ACTION1 = �Ҽ� --- ### clicker ? **clicker**: *[Box3Entity](box3entity.html) & object* �������¼������ --- ### clickerPosition ? **clickerPosition**: *[Box3Vector3](box3vector3.html)* �������˲���������λ�� --- ### distance ? **distance**: *number* ��ҵ������ʵ��ľ��� --- ### entity ? **entity**: *[Box3Entity](box3entity.html)* �������ʵ�� --- ### raycast ? **raycast**: *[Box3RaycastResult](box3raycastresult.html)* ��� -> �����ʵ������߼���� --- ### tick ? **tick**: *number* ������¼�������ʱ�� # Class: Box3InputEvent �����¼�������Ұ��»��ɿ���ťʱ������ �¼�������ʱ�̣���Ϊ��Ұ���/�ɿ���ť��ͬһ�̡� �� [Box3World.onPress](box3world.html#onPress), [Box3World.onRelease](box3world.html#onRelease), [Box3Player.onPress](box3player.html#onPress), [Box3Player.onRelease](box3player.html#onRelease) ������ **ʾ������** ``` world.onPress(({button, entity, position, pressed, raycast, tick}) => { }) ``` �������������ָ��λ�õķ����滻Ϊʯͷ������Ҽ������ٷ��顣 ``` world.onPress(({button,raycast})=>{ let pos = raycast.voxelIndex if(button==='action0'){ voxels.setVoxel(pos.x,pos.y,pos.z,'stone') }else if(button==='action1'){ voxels.setVoxel(pos.x,pos.y,pos.z,'') } }) ``` --- ### button ? **button**: *[Box3ButtonType](box3buttontype.html)* �������İ�ť --- ### entity ? **entity**: *[Box3Entity](box3entity.html) & object* ָ����/�ɿ���ť����� --- ### position ? **position**: *[Box3Vector3](box3vector3.html)* ��Ұ���/�ɿ���ť��˲������λ�� --- ### pressed ? **pressed**: *boolean* ���Ϊ�棬���¼�Ϊ���°�ť������Ϊ�ɿ���ť�� --- ### raycast ? **raycast**: *[Box3RaycastResult](box3raycastresult.html)* ����/�ɿ���ť��˲�䣬������ӽ�Ͷ������߼������ --- ### tick ? **tick**: *number* ����/�ɿ���ť��ʱ�� # Class: Box3InteractEvent ### ���� - [entity](box3interactevent.html#entity) - [targetEntity](box3interactevent.html#targetentity) - [tick](box3interactevent.html#tick) ## ���� ### entity ? **entity**: *[Box3Entity](box3entity.html)* ���𻥶���ʵ�� --- ### targetEntity ? **targetEntity**: *[Box3Entity](box3entity.html)* �յ����������ʵ�� --- ### tick ? **tick**: *number* �¼�����ʱ�� # Enumeration: Box3ButtonType ��Ұ��µİ�ť���� |����|ֵ|˵�� |------ |WALK|'walk'|���а�ť| |RUN|'run'|���ܰ�ť| |CROUCH|'crouch'|�¶װ�ť| |JUMP|'jump'|��Ծ��ť| |DOUBLE_JUMP|'jump2|��������ť| |FLY|'fly'|���а�ť| |ACTION0|'action0'|������ / ���ⰴťA| |ACTION1|'action1'|����Ҽ� / ���ⰴťB| # Class: Box3AnimationEvent �����¼���ͨ��Box3Animation.onReady��Box3Animation.onFinish���� --- ### animation ? **animation**: *[Box3Animation](box3animation.html)?KeyframeType, TargetType?* �������� --- ### target ? **target**: TargetType ���Ŷ�����Ŀ����� --- ### tick ? **tick**: number �����¼�������ʱ�� --- ### cancelled ? **cancelled**: bool �����Ƿ�ȡ�� # Class: Box3EventHandlerToken ���¼�������������ʱ���� [Box3EventChannel](box3enventchannel.md) ���ص�token��������ȡ���¼��������� --- ### cancel ȡ���¼������� #### ��������: ? **cancel**(): *void* --- ### resume ���������¼������� #### ��������: ? **resume**(): *void* # Class: Box3Database Box3 �� SQL ���ݿ⡣ `db` ����������Box3 Database API����ڡ���ʹ�����ݿ�֮ǰ����Ҫ������һЩ���ڲ������ݿ�Ļ���֪ʶ�� --- ### sql ? **sql**: *function* �����ݿ�ִ��SQL��䡣ʹ��SQL���ʱ�����������ڷ����� ` ` ���档
    ������ `~ λ�ڼ������Ͻ� ESC ���·���С����������ߡ� ����ȹر��������뷨�����롣 ``` db.sql`SELECT * FROM users` ``` �������ñ���ʽ,����ʹ�� `${expression}`���б�ʾ�� ``` `SELECT * FROM users WHERE name=${entity.player.name}` ``` #### ��������: ? (`db.sql`: string): *[Box3QueryResult](box3queryresult.html)* ## ��ʾ�� ### �������� ``` // ������ async function createTable() { await db.sql`CREATE TABLE IF NOT EXISTS leaderboard ( name VARCHAR(50) PRIMARY KEY UNIQUE NOT NULL, record INT NOT NULL )`; } createTable(); ``` ### �������� ``` // �������� async function insertRecord(name, record) { try{ await db.sql` INSERT INTO leaderboard (name, record) VALUES (${name}, ${record}) `; } catch (e) { console.log(`insert sql error: ${e}`) ; } } insertRecord('������', 100) ``` ### �������� ``` // �� leaderboard ������� name ���Ҷ�Ӧ record �����м�¼��������¼�� record �������У�ѡȡǰ3���� async function getPlayerRecord(name) { for await (const row of db.sql`SELECT * FROM leaderboard WHERE name=${name} ORDER BY record ASC LIMIT 3`) { world.say(`${row.name} : ${row.record}`) } } getPlayerRecord('������') ``` ### �ڿ���̨������� ``` // ���������������̨ async function printRecord() { for await (const row of db.sql`SELECT * FROM leaderboard`) { console.log(`${row.name} : ${row.record}`) } } printRecord() ``` ### �������� ``` // �� leaderboard ���У����ض����ֵ�record��ȫ������Ϊvalue async function updatePlayersRecord(name, value) { try { await db.sql`UPDATE leaderboard SET record = ${value} WHERE name = ${name}`; } catch (e) { console.log(`update sql error: ${e}`) ; } } (async function() { try { // �������� await db.sql`INSERT INTO leaderboard (name, record) VALUES ('������', 15) `; await db.sql`INSERT INTO leaderboard (name, record) VALUES ('��������С���', 16) `; } catch (e) { console.log(`insert sql error: ${e}`) ; } // �������� await updatePlayersRecord('������', 99) } ``` ### ɾ������ **ʾ��1**�� ``` /* ɾ����������(��ɾ������) */ async function removeRecordAll () { await db.sql`DELETE FROM leaderboard` world.say(`���б������ѱ���գ�`) } removeRecordAll() ``` **ʾ��2**�� ``` /* ɾ��ָ��������� */ async function removePlayerRecord(name) { await db.sql`DELETE FROM leaderboard WHERE name = ${name}` world.say(`${name} �����а������ѱ�ɾ����`); } removePlayerRecord('������') ``` **ʾ��3**�� ``` /* ɾ�������ض����������� */ await db.sql`DELETE FROM leaderboard WHERE record>30` ``` ### ɾ������ ɾ��������޷��ٶԱ�����в�����ֻ�����´������ݱ���
    ����ؽ���ʹ�ã���Ҫ����ɾ������! ``` /* ɾ���� (�������������ݶ���ɾ��) */ async function dropTable() { await db.sql`DROP TABLE leaderboard` console.log(` players ����ɾ����`); } dropTable() ``` --- **ʾ������1** ������Ϸ��ʷ���а� 1. ��ȡ�Լ���ʷ��߷� 1. ��ȡ���а�ǰ10 1. ��ȡ���а��1 ``` let leader; // ��ǰ���а������ // �������а�� async function createTables () { // ������ await db.sql`CREATE TABLE IF NOT EXISTS leaderboard ( name VARCHAR(50) NOT NULL, record REAL NOT NULL )` } // �����а��������� async function insertLeaderboard(name, time) { try { await db.sql`INSERT INTO leaderboard VALUES (${name}, ${time})`; } catch (e) { console.log(`insert sql error: ${e}`) ; } } // ����������� async function removeAll() { await db.sql`DELETE FROM leaderboard` world.say(`leaderboard ���а������ѱ���գ�`); } // ��ȡ���а��һ�� async function getBestTime() { const rows = await db.sql`SELECT * FROM leaderboard ORDER BY record ASC LIMIT 1`; if (rows && !rows.length) { console.log('no record'); return {name:'������', record: '30.0'}; } world.say(rows[0].name + ' / ' + rows[0].record); return rows[0]; } // ��ȡ���а�Top10 async function getTop10() { const rows = await db.sql`SELECT * FROM leaderboard ORDER BY record ASC LIMIT 10`; // �ڿ���̨��ӡ���� console.log(`result = ${JSON.stringify(rows)}`); // �������Ľ������������ʾ for await (const row of rows) { world.say(row.name + ' | ' + row.record) } } // ��ȡ�����߷��� async function getMyBestTime(player) { const rows = await db.sql`SELECT * FROM leaderboard WHERE name=${player} ORDER BY record ASC LIMIT 1`; if (row && !row.length) { console.log('no record'); return null; } world.say(rows[0].name + ' / ' + rows[0].record); return rows[0]; } //----------------------------------------------------------------- // ����Ϸ��ʼ֮ǰ���������ݿ� (async function() { console.clear(); await createTables(); // �����а�������ʱ���Ե����� await insertLeaderboard('������', '22.8'); await insertLeaderboard('��������С���', '23.4'); await insertLeaderboard('�������ĺ�����', '23.6'); await insertLeaderboard('���������ھ�С��', '24'); await insertLeaderboard('���������ھ�С��', '25'); await insertLeaderboard('���������ھ�С��', '28'); // ������ѳɼ� leader = await getBestTime(); // ���û�����а����ݣ���߼�¼������Ϊ�������� world.say(`[��߼�¼������] ${leader.name?leader.name:'������'} : ${leader.record}s`) }()); // ͨ��������������ȡ��߼�¼ world.onChat(async ({entity:user,message})=>{ if(message==='top1'){ const personalBest = await getMyBestTime(user.player.name); // ������ѳɼ� const str = personalBest ? `��Ŀǰ��ѳɼ��ǣ�${personalBest.record}s` : `�㻹û����ս��¼��` await user.player.dialog({ type: Box3DialogType.TEXT, content: `${leader.name?leader.name:'������'}Ŀǰ��${leader.record?leader.record:'30.0'}s�ijɼ�������һ��\n ${str}`, }) }else if(message==='top10') { await getTop10(); }else if(message==='������а�') { await removeAll(); } }); ``` --- **ʾ������2** ��¼��ҽ�����Ϸ���뿪��Ϸ��ʱ�䡣
    �´��ٽ�����Ϸʱ����ʾ�����ϴε�¼�ж���ʱ�䡣 ``` console.clear() /// ������ async function createTable() { await db.sql`CREATE TABLE IF NOT EXISTS playerlogin ( name VARCHAR(50) NOT NULL, jointime REAL NOT NULL, leavetime REAL )` } // ��һ�ν�����Ϸʱ���½�������� async function insertPlayer(name, join, leave = 0) { try { await db.sql`INSERT INTO playerlogin VALUES (${name}, ${join}, ${leave})`; } catch (e) { console.log(`insert sql error: ${e}`) ; } } // ������ҽ�����Ϸʱ�� async function updatePlayerJoin(name, value) { try { await db.sql`UPDATE playerlogin SET jointime = ${value} WHERE name = ${name}`; } catch (e) { console.log(`[jointime] update sql error: ${e}`) ; } } // ��������뿪��Ϸʱ�� async function updatePlayerLeave(name, value) { try { await db.sql`UPDATE playerlogin SET leavetime = ${value} WHERE name = ${name}`; } catch (e) { console.log(`[leavetime] update sql error: ${e}`) ; } } // ��ѯ���ݡ�������ݲ����ڣ����ؿա� async function getPlayerData(name) { const rows = await db.sql`SELECT * FROM playerlogin WHERE name=${name}`; if (rows && !rows.length) { return null; } return rows[0]; } // ����������� async function clearLoginRecord () { await db.sql`DELETE FROM playerlogin` world.say(`������е�½���ݣ�`); } //------------------------------------------------------- // ��ҽ�����Ϸ world.onPlayerJoin( async ({entity}) => { const now = new Date().valueOf(); // ��ȡ��ʵ�����ʱ��� timestamp const playerData = await getPlayerData(entity.player.name); // ��ȡ�ϴε�¼��¼ // ������ݲ����ڣ�˵��ʱ��һ�ν�����Ϸ if (playerData === null) { insertPlayer(entity.player.name, now); // ����������� world.say(`${entity.player.name} ��һ�ν�����Ϸ��`); } else { updatePlayerJoin(entity.player.name, now); // ������ҽ�����Ϸʱ�� const leaveTime = (now - playerData.leavetime) / 1000; entity.player.directMessage(`${entity.player.name} �����ϴε�¼������ ${leaveTime.toFixed(2)} ��`); } }); // ����뿪��Ϸ world.onPlayerLeave( async ({entity}) => { const now = new Date().valueOf(); updatePlayerLeave(entity.player.name, now) }); ``` # Class: Box3QueryResult ʹ�� `db.sql` ִ��SQL���������ݿⷵ�صĽ���� ### ���� - [next](box3queryresult.html#next) - [return](box3queryresult.html#return) - [throw](box3queryresult.html#throw) ### next ? **next**: *function* : *Promise?object?* --- ### return ? **return**: *function* : *Promise?object?* --- ### throw ? **throw**: *function* ( 'err': any ): *Promise?object?* --- ### ���� - [[Symbol.asyncIterator]](box3queryresult.html#symbolasynciterator) - [then](box3queryresult.html#then) ### Symbol.asyncIterator ? **[Symbol.asyncIterator]** (): *this* --- ### then ? **then**('resolve': function, 'reject': function): *void* - **resolve**: *function* ( 'rows' : any[] ): *void* - **reject**: *function* ('err' : any ): *void* --- # Class: Box3Database # ���ݿ��� box3 �����û�����Ϸ�е����ݽ��д洢��ʹ�û�����Ϸ�����п�����ʱ��ȡ���ϴ�����������������ʹ���߽���ͼ�������У�����Ҳ�ᱻ���档��Ҫ�򵥵ؽ����������Ǵ����Ϥ��**�ƴ浵**���ܡ��ڴ浵�����Ҫ����ʲô���ݣ�����Ҫ���Ӵ�ҵ��������ˡ� �����ݿ���в���ʱʹ��SQL���ԡ�box 3֧�ֵ�SQL������SQLite 3���ڿ�ʼʹ�����ݿ�ǰ����Ҫ������һЩ����SQL���Ļ���֪ʶ�� ## ʲô�����ݿ� �򵥵�˵�����ݿ⣬���������洢���ݵIJֿ⡣�����еĻ���װ���˸�����ʳ����ߣ�����ı��������������Ϻ�ѩ�⡣ѧУ�̵������ļ������¼��ÿ��ѧ������Ϣ... ## ���ݿ���ʲô�ã� ���ݿ�����ã���Ҫ���������������ࡢɸѡijЩ��Ϣ�����磬��������ռ��༶��ÿ��ͬѧ�����ϣ�������ͳͳ����С�����ϣ������һ���򵥵����ݿ��ˡ� ���ݿ�����ÿ�����4������������**��ɾ���** 1. �������� 1. ɾ������ 1. �������� 1. �޸����� ## ���ݿ���ô�ã� ��ʹ�����ݿ�֮ǰ��������һЩ�������ݿ�Ļ������һЩרҵ������Ҫ�˽�һ�¡� ### **Table ��** ���������ݿ��У���Ҫ����ɡ�һ�����ݿ��У�ͨ�����������������磺ѧ���ı�����ʦ�ı��񣬰༶�ı����꼶�ı���... ��Ȼ����������ʲô���ݣ����԰����Լ���ϲ��ȥ���ࡣ ���磬�༶���� ``` ���� �Ա� �༶ ѧ�� ------------------------------ С�� �� һ�� 1 С�� Ů һ�� 2 С�� Ů һ�� 3 С�� �� һ�� 4 ``` ���磬������Ա��� ``` �û��� ְҵ ���� ���� ���� ���� ---------------------------------------------------------------------- ������ ������ 1 1 1 999 ��������ʵ�޻���ǿ��-1 �ػ��� 999 50 50 -1 ``` ���ڣ����������ݿ��еı�����ʲô��˼�˰ɣ� --- ### **Field �ֶ� : Value ����** �������������ǿ����ı���һ���������¼�Ÿ������ϡ����磬"����", "��ϵ�绰", "�Ա�"...��Щ���ԣ������ݿ���ͨ��������`Field �ֶ�`�������Ƕ�Ӧ�ľ�����Ϣ������Ϊ `Value`�������Ķ�������α��񣬿��������и����ٵ��˽⣺ ``` name gold exp level ------------------------------- player1 1 1 1 player2 50 60 2 player3 10 0 1 ``` ���������4�ּ򵥵����ݡ����б����� `name`, `gold`, `exp`, `level` �⼸���ؼ��ʾ��� Field������ľ������ݣ����� Value�� --- ### **Data Types ��������** �����������һ�������ݿ��е�����Ҳ��Ҫ���������������ݽ������֡�����ijЩ����ר�Ŵ����ı���ijЩר�Ŵ������֡��Ƚϳ��õ������¼��֣�������һ����Щ�ؼ��ʣ� - **TEXT** : �ı����͵��ַ��� - **INTEGER** : ���������� - **REAL** : ���������� - **NULL** : ��ֵ���� - **BLOB** : ���������� - **NUMERIC** : �������� �ı����ͣ�"Hello", "������뵺", "Box3", "������"... �������ı�չʾ���ַ�����
    ����������: -10, -1, 0, 1, 10, 233, 1093... ����**����С����**�����֡�
    ����������: -0.99, 0.1, 3.1415926... ����**����С����**�����֡� --- ### **Data Constraint ���ݹ涨** �ڱ����У����Զ�ÿ����������ֵ�������͹��򣬱����������ֵ������Ϊ�գ���ֵ�������ڱ��б�����Ψһ�ģ������������ظ��ȵ�... - **NOT NULL** : ��ֹΪ��ֵ - **UNIQUE** : ��ֹ������ֵͬ - **DEFAULT** : ���Ϊ��, ��Ĭ��ֵ - **PRIMARY KEY** : ����ֵ����Ϊ���� - **CHECK** �� ������������ֵ��� --- ### **SQL ��������** �����г�һЩ���õ�SQL����������������������ѧϰ����SQLite��ʹ�ã� - **CREATE TABLE** : �������� - **ALTER TABLE** : �޸ı��� - **DROP TABLE** : ɾ������ - **INSERT INTO** : ������������� - **SELECT** : �ڱ����в������� - **UPDATE** ���޸ı������е����� - **DELETE** ��ɾ���������е����� - **WHERE** ����������ɸѡ�������� --- ## ���ݿ⵽����ô�ã� ʹ��һ���ھ�����Ϸ��ʵ�� **��ʷ�߷ְ�** �����������ܡ� ## ������ �������ݿ��д���һ����Ϊ `leaderboard` �ı������洢�漸�����ݣ�
  • **name** �������
      1. ���ͣ�`VARCHAR(50)` �ı��ַ���,���Ȳ�����50���ַ��� 1. �涨��`NOT NULL`: ���������ֿ�ֵ
  • **record** ͨ�ؼ�¼
      1. ���ͣ�`REAL` ���������֡�����Ϊʱ�䵥λ����С������ 1. �涨��`NOT NULL`: ���������ֿ�ֵ
  • - ���ͣ�`REAL` ���������֡�����Ϊʱ�䵥λ����С������ - �涨��`NOT NULL`: ���������ֿ�ֵ ��SQL�﷨�У���Ҫ����������Ҫ��ô���� ``` CREATE TABLE IF NOT EXISTS leaderboard ( name VARCHAR(50) NOT NULL, record REAL NOT NULL ) ``` ����box3�У���Ҫʹ�� db.sql` ` ����SQL�﷨�������ã� ``` // �������а���� async function createTables() { await db.sql`CREATE TABLE IF NOT EXISTS leaderboard ( name VARCHAR(50) NOT NULL, record REAL NOT NULL )` } /* �ڽű���ʼ��ʱ��ִ�� */ (async function() { await createTables() }()); ``` ������һ���򵥵����ݿ���񣬾��½�����ˡ� ``` name record ------------------- ``` ## �������� 1. ʹ��SQL��� `INSERT INTO leaderboard VALUES`�������� ``` // �����а��������� async function insertLeaderboard(name, time) { try { await db.sql`INSERT INTO leaderboard VALUES (${name}, ${time})`; } catch (e) { console.log(`insert sql error: ${e}`) ; } } // �����б�����3������ insertLeaderboard('������', 15) insertLeaderboard('������', 16) insertLeaderboard('������', 17) ``` ``` name record ------------------- ������ 15 ������ 16 ������ 17 ``` ## ��ȡ���� **ʾ��1** 1. ʹ�� `SELECT * FROM leaderboard` ��ѯ�������������ݡ� 1. ���� `ORDER BY record ASC` �� record ������������(ASC: ���� / DESC: ����) 1. ���� `LIMIT 10` ֻѡ��10�����ݡ� ``` // ��ȡ���б�����ǰ10�� async function getTop10() { for await (const row of db.sql`SELECT * FROM leaderboard ORDER BY record ASC LIMIT 10`) { world.say(`${row.name} : ${row.record}`) } } getTop10() ``` --- **ʾ��2** 1. ʹ�� `WHERE` ��������ָ�������ļ�¼������ **WHERE record > 10** ���Dz��ҷ�������10�ļ�¼�� 1. �����������¼���᷵��һ�����顣 1. ���û�м�¼���򷵻�һ����ֵ�� ``` // ��ѯ�Լ�����ʷ��߷� async function getMyBestTime(player) { // �������� const rows = await db.sql`SELECT * FROM leaderboard WHERE name=${player} ORDER BY record ASC LIMIT 1`; // �Ҳ������� if (rows && !rows.length) { console.log('��û�б�����¼'); return null; } world.say(`${row[0].name} : ${row[0].record}`) return rows[0]; } // �����촰�ڻظ� '1', ��ѯ�Լ���ʷ��߷� world.onChat(async ({entity:user,message})=>{ if(message==='1'){ const personalBest = await getMyBestTime(user.player.name); msg = personalBest ? `�����ʷ��߷��� ${personalBest.record}` : `�㻹û�б�����¼` user.player.directMessage(msg) } }); ``` ## ������� ������ݺ󣬱�����Ȼ���ڣ����Լ����Ա�����в����� **ʾ��1** 1. ʹ�� `DELETE FROM leaderboard` ɾ�������¼ ``` // ��������������� (����ṹ����) async function removeAll () { await db.sql`DELETE FROM leaderboard` world.say(`���б������ѱ���գ�`) } removeAll() ``` --- **ʾ��2** 1. ʹ�� `WHERE record > 15` ֻɾ�������з�������15�ļ�¼ ``` // ɾ�����������ļ�¼ async function removeSlowRecord () { await db.sql`DELETE FROM leaderboard WHERE record > 15` world.say(`�������б���������15s����Ҽ�¼��`) } removeSlowRecord() ``` ## ɾ������ ɾ��������޷��ٶԱ�����в������������´������� ``` await db.sql`DROP TABLE leaderboard` ```
    ---
    ## ���� SQL �﷨ ������һЩ���ٵ�SQLʾ������Ƭ�Σ������ο���
  • **ALTER TABLE** �����еı������ӡ�ɾ�����޸��ֶΡ�
  • ``` /* ��players���������ֶ�score,����Ϊdouble,��󳤶�Ϊ3 */ await db.sql`ALTER TABLE players ADD score DOUBLE(3)` ``` ``` /* ��players���е�magic�ֶ�Ĭ��ֵ��Ϊ0 */ await db.sql`ALTER TABLE players ALTER magic SET DEFAULT 0` ``` ``` /* ��players���е�name�ֶ��������͸�Ϊchar,��󳤶�Ϊ10 */ await db.sql`ALTER TABLE players MODIFY name CHAR(10)` ``` ``` /* ��players���е�sanity�ֶ�ɾ�� */ await db.sql`ALTER TABLE players DROP sanity` ``` ``` /* ��players��������date�ֶΣ���������Ϊ������ */ await db.sql` ALTER TABLE players ADD date DATE` ``` ---
  • **SELECT** �ӱ�����ѡȡ���ݡ�
  • ``` /*��ѯ����ƽ��ֵ*/ await db.sql`SELECT AVG(record) AS avg FROM leaderboard` ``` ``` /*��ѯ�������ֵ*/ await db.sql`SELECT MAX(record) AS max FROM leaderboard` ``` ``` /*��ѯ���������ļ�¼����*/ await db.sql`SELECT COUNT(record) AS count FROM leaderboard` ``` ``` /*��ѯ�����������ۼ�����*/ await db.sql`SELECT SUM(record) AS sum FROM leaderboard` ``` ``` /*��ѯ������ߵ�ǰ3����ҵ������ͷ���*/ await db.sql`SELECT record, name FROM leaderboard ORDER BY name DESC LIMIT 3` ``` ``` /*�ж��Ƿ�ƥ�� (���ִ�Сд��ĸ)*/ await db.sql`SELECT BINARY 'abc' LIKE 'ABC' ` ``` ``` /*�ж��Ƿ�ƥ�� (�����ִ�Сд��ĸ)*/ await db.sql`SELECT 'abc' LIKE 'ABC'` ``` ---
  • **UPDATE** �Ӹ��±��еļ�¼
  • ``` /*�����б��У�����С��20�������ƺ��ֶθ�Ϊ"�������"*/ await db.sql`UPDATE leaderboard SET honour='�������' WHERE record<20` ``` ``` /*�����б��У��������ƺ��а���"�������XXX"�ļ�¼��level��Ϊ99*/ await db.sql`UPDATE leaderboard SET level = 99 WHERE honour LIKE '�������%' ` ``` --- �����﷨֧����������������SQL�Ľ̳�ѧϰ�� # PostgreSQL���� ## ����������ݱ� ``` async function initTable() {//����������ݱ� return await db.sql` CREATE TABLE IF NOT EXISTS "player" ( "coin" INT NOT NULL,--��� "exp" INT NOT NULL,--���� "item" TEXT NOT NULL,--��Ʒ�б� "userKey" CHAR(16) PRIMARY KEY UNIQUE NOT NULL --�û�ʶ���� ) `; } ``` ## �浵 ``` async function saveUser(user) {//��Ҵ浵 await db.sql` INSERT INTO "player" (-- player��Ȼ��Сд, ����ͳһ��""��ס "exp",-- ���� "coin",-- ��� "item",-- ���� "userKey"-- �û�ʶ���� ) VALUES ( ${user.exp}, --�����½�����ֵ ${user.coin}, --�����½����ֵ ${JSON.stringify(user.item)}, --�����½�����ֵ ${user.player.userKey} --�����½���ǰ���ʶ���� ) ON CONFLICT("userKey") -- ����Ѿ�����ͬ�����û�ʶ���� DO UPDATE SET "exp"=excluded."exp",-- ���¾���ֵ "coin"=excluded."coin",-- ��Ȼ��Сд, ����ͳһ��""��ס "item"=excluded."item"-- ��Ȼ��Сд, ����ͳһ��""��ס ` } ``` ## ���� ``` async function loadUser(user) {//��Ҷ��� const [data] = await db.sql`SELECT * FROM "player" WHERE "userKey"=${user.player.userKey} LIMIT 1` if (data) {//����������Ѿ��д浵 user.exp = data.exp user.coin = data.coin user.item = JSON.parse(data.item) } else {//����޴浵 saveUser(user) } } ``` ## ɾ�� ``` async function deleteUser(user) {//ɾ����Ҵ浵 await db.sql`DELETE FROM "player" WHERE "userKey"=${user.player.userKey}` } ``` ## ��ʾ��������� ``` async function showAllPlaySideUser() {//��ʾ������������, ��ͼ���������вŲ��ᱨ�� for (const e of await db.sql`SELECT * FROM play."player"`) { console.log(JSON.stringify(e)) } } ``` ## ��ʾ�༭������ ``` async function showAllEditSideUser() {//��ʾ�༭��������� for (const e of await db.sql`SELECT * FROM edit."player"`) { console.log(JSON.stringify(e)) } } ``` ## �������Ϸ���������Ĺ��� ``` async function poll(fn, msg) {//������ѯִ��sql���ֱ���ɹ� while (true) { try { return await fn()//һ���ɹ�ִ��, ֹͣ������ѯ, �����ز�ѯ��� } catch (e) { const m = e.message//��Ҫ������ʾ���쳣��Ϣ //sqlż����ִ�г�ʱ, �����������ʾtimeout 15������һֱ��ͣ, ��������ݿ���˹���ֻ�ܵȹٷ��޸� if (m.includes('timeout')) { world.say(m) } else { world.say(msg || e.stack)//���sqlִ�г���, �㲥������Ϣ, �����Ų����ԭ�� } } await sleep(2000) //ÿ2������һ�� } } poll(initTable, '�ȴ�pg���ݿ�������...') world.onPlayerJoin(async ({ entity }) => { //��ʼ��������� entity.exp = 0 entity.coin = 50 entity.item = ['��', '��'] await loadUser(entity)//���Զ�ȡ�浵 entity.onVoxelContact(() => {//ÿ��1������1���� entity.exp += 1 }) entity.player.onPress(async ({ button }) => {//�Ҽ���ʾ״̬�� if (button == Box3ButtonType.ACTION1) { const sel = await entity.player.dialog({ type: Box3DialogType.SELECT, content: ` ���:${entity.coin} ����:${entity.exp} ����:[${entity.item}] `, options: ['����','ɾ��','���������','�༭������'], }) if (sel) { if (sel.value == '����') { await saveUser(entity) entity.player.directMessage('�������') } else if (sel.value == 'ɾ��') { await deleteUser(entity) entity.player.directMessage('ɾ�����') } else if (sel.value == '���������') { await showAllPlaySideUser() } else if (sel.value == '�༭������') { await showAllEditSideUser() } } } }) }) ``` ## ע������: 1. pg���ֶ���Ĭ�ϻ�ǿ��ת����Сд, ����userKey�ᱻ����userkey, �õ���д��ĸ������Ҫ��""��ס����, ����"userKey". ���������ֶ���/����, ���۴�Сд����""��ס 1. ��ʱ��ͼ������, pg��δ����, ��Ҫ��ѯ�ȴ�pg��λ 1. pg��ʱ��Ϊ����ԭ���������, sql��ִ�в��ɹ�(����query timeout), ��Ҫ��ѯִ��sql���ȷ����������ݿ⵽λ�����ִ�� 1. pg��INT�����ֶ����ϸ��λ������, �������޽�����, ��1e+53��������ֵ�Ǵ治��ȥ��, ���ȥ֮ǰ��Ҫ����ֵ���Ƶ���Ч��ֵ��Χ(2147483647����) 1. pg��INT�����ֶλ�����һ������, ���Dz����������С���������, ����3.14���������ִ��ȥ�ᱨ��, ��Ҫ��Math.floor()����ֵת������3�ٴ��� 1. pg����ַ���ֻ����''��ס, ������""��ס, ""��pgֻ����֧�ִ�д���� 1. ����õ�BIGINT����, �����ص����ַ�����������, �ڶ�ȡʱ��Ҫ��parseInt()ת����js������� 1. ����������sql���ִ��ʧ��, ���Է��������poll����, ��try/catch�Ѵ�����Ϣ��world.say��ʾ���� # Class: Box3Vector3 ## ���캯�� **new Box3Vector3**(`x`: number, `y`: number, `z`: number): *[Box3Vector3](box3vector3.html)* **����:** |����|���� |------ |`x`|number| |`y`|number| |`z`|number| **����ֵ:** *[Box3Vector3](box3vector3.html)* ## ���� |����|���� |------ |`x`|number| |`y`|number| |`z`|number| ## ���� ### add ? **add**(`v`: [Box3Vector3](box3vector3.html)): *[Box3Vector3](box3vector3.html)* **����:** |����|���� |------ |`v`|[Box3Vector3](box3vector3.html)| **����ֵ:** *[Box3Vector3](box3vector3.html)* --- ### angle ? **angle**(`v`: [Box3Vector3](box3vector3.html)): *number* **����:** |����|���� |------ |`v`|[Box3Vector3](box3vector3.html)| **����ֵ:** *number* --- ### clone ? **clone**(): *[Box3Vector3](box3vector3.html)* **����ֵ:** *[Box3Vector3](box3vector3.html)* --- ### copy ? **copy**(`v`: [Box3Vector3](box3vector3.html)): *void* **����:** |����|���� |------ |`v`|[Box3Vector3](box3vector3.html)| **����ֵ:** *void* --- ### cross ? **cross**(`v`: [Box3Vector3](box3vector3.html)): *[Box3Vector3](box3vector3.html)* **����:** |����|���� |------ |`v`|[Box3Vector3](box3vector3.html)| **����ֵ:** *[Box3Vector3](box3vector3.html)* --- ### distance ? **distance**(`v`: [Box3Vector3](box3vector3.html)): *number* **����:** |����|���� |------ |`v`|[Box3Vector3](box3vector3.html)| **����ֵ:** *number* --- ### div ? **div**(`v`: [Box3Vector3](box3vector3.html)): *[Box3Vector3](box3vector3.html)* **����:** |����|���� |------ |`v`|[Box3Vector3](box3vector3.html)| **����ֵ:** *[Box3Vector3](box3vector3.html)* --- ### dot ? **dot**(`v`: [Box3Vector3](box3vector3.html)): *number* **����:** |����|���� |------ |`v`|[Box3Vector3](box3vector3.html)| **����ֵ:** *number* --- ### equals ? **equals**(`v`: [Box3Vector3](box3vector3.html), `tolerance`: number): *boolean* **����:** |����|����|Default |------ |`v`|[Box3Vector3](box3vector3.html)|-| |`tolerance`|number|0.0001| **����ֵ:** *boolean* --- ### exactEquals ? **exactEquals**(`v`: [Box3Vector3](box3vector3.html)): *boolean* **����:** |����|���� |------ |`v`|[Box3Vector3](box3vector3.html)| **����ֵ:** *boolean* --- ### lerp ? **lerp**(`v`: [Box3Vector3](box3vector3.html), `n`: number): *[Box3Vector3](box3vector3.html)* **����:** |����|���� |------ |`v`|[Box3Vector3](box3vector3.html)| |`n`|number| **����ֵ:** *[Box3Vector3](box3vector3.html)* --- ### mag ? **mag**(): *number* **����ֵ:** *number* --- ### max ? **max**(`v`: [Box3Vector3](box3vector3.html)): *[Box3Vector3](box3vector3.html)* **����:** |����|���� |------ |`v`|[Box3Vector3](box3vector3.html)| **����ֵ:** *[Box3Vector3](box3vector3.html)* --- ### min ? **min**(`v`: [Box3Vector3](box3vector3.html)): *[Box3Vector3](box3vector3.html)* **����:** |����|���� |------ |`v`|[Box3Vector3](box3vector3.html)| **����ֵ:** *[Box3Vector3](box3vector3.html)* --- ### mul ? **mul**(`v`: [Box3Vector3](box3vector3.html)): *[Box3Vector3](box3vector3.html)* **����:** |����|���� |------ |`v`|[Box3Vector3](box3vector3.html)| **����ֵ:** *[Box3Vector3](box3vector3.html)* --- ### normalize ? **normalize**(): *[Box3Vector3](box3vector3.html)* **����ֵ:** *[Box3Vector3](box3vector3.html)* --- ### scale ? **scale**(`n`: number): *[Box3Vector3](box3vector3.html)* **����:** |����|���� |------ |`n`|number| **����ֵ:** *[Box3Vector3](box3vector3.html)* --- ### set ? **set**(`x`: number, `y`: number, `z`: number): *void* **����:** |����|���� |------ |`x`|number| |`y`|number| |`z`|number| **����ֵ:** *void* --- ### sqrMag ? **sqrMag**(): *number* **����ֵ:** *number* --- ### sub ? **sub**(`v`: [Box3Vector3](box3vector3.html)): *[Box3Vector3](box3vector3.html)* **����:** |����|���� |------ |`v`|[Box3Vector3](box3vector3.html)| **����ֵ:** *[Box3Vector3](box3vector3.html)* --- ### toString ? **toString**(): *string* **����ֵ:** *string* --- ### towards ? **towards**(`v`: [Box3Vector3](box3vector3.html)): *[Box3Vector3](box3vector3.html)* **����:** |����|���� |------ |`v`|[Box3Vector3](box3vector3.html)| **����ֵ:** *[Box3Vector3](box3vector3.html)* # Class: Box3Bounds3 Box3Bounds����ָ��������һ��������ռ����� ## ���캯�� + **new Box3Bounds3**(`lo`: [Box3Vector3](box3vector3.html), `hi`: [Box3Vector3](box3vector3.html)): *[Box3Bounds3](box3bounds3.html)* �½�һ������ **����:** |����|����|˵�� |------ |`lo`|[Box3Vector3](box3vector3.html)|����ĵʹ�����|| |`hi`|[Box3Vector3](box3vector3.html)|����ĸߴ�����|| **����ֵ:** *[Box3Bounds3](box3bounds3.html)* ## ���� ### hi ����ĸߴ����� ? **hi**: *[Box3Vector3](box3vector3.html)* --- ### lo ����ĵʹ����� ? **lo**: *[Box3Vector3](box3vector3.html)* ## ���� ### copy ? **copy**(`b`: [Box3Bounds3](box3bounds3.html)): *[Box3Bounds3](box3bounds3.html)* **����:** |����|���� |------ |`b`|[Box3Bounds3](box3bounds3.html)|| **����ֵ:** *[Box3Bounds3](box3bounds3.html)* --- ### set ? **set**(`lox`: number, `loy`: number, `loz`: number, `hix`: number, `hiy`: number, `hiz`: number): *void* **����:** |����|���� |------ |`lox`|number|| |`loy`|number|| |`loz`|number|| |`hix`|number|| |`hiy`|number|| |`hiz`|number|| **����ֵ:** *void* --- ### intersect ? **intersect**(`b`: [Box3Bounds3](box3bounds3.html)): *[Box3Bounds3](box3bounds3.html)* **����:** |����|����|˵�� |------ |`b`|[Box3Bounds3](box3bounds3.html)|������˰�Χ���ཻ�IJ���|| --- ### intersects ? **intersects**(`b`: [Box3Bounds3](box3bounds3.html)): *boolean* **����:** |����|����|˵�� |------ |`b`|[Box3Bounds3](box3bounds3.html)|����Ƿ���˰�Χ���ཻ|| **����ֵ:** *boolean* --- ### contains ? **contains**(`b`: [Box3Vector3](box3vector3.html)): *boolean* **����:** |����|����|˵�� |------ |`b`|[Box3Vector3](box3vector3.html)|����Ƿ��Χ�����3d��|| **����ֵ:** *boolean* --- ### containsBounds ? **containsBounds**(`b`: [Box3Bounds3](box3bounds3.html)): *boolean* **����:** |����|����|˵�� |------ |`b`|[Box3Bounds3](box3bounds3.html)|����Ƿ���ȫ��Χ�˴˺�|| **����ֵ:** *boolean* --- ### toString ? **toString**(): *string* **����ֵ:** *string* --- ### `Static` fromPoints ? **fromPoints**(`...points`: <[Box3Vector3](box3vector3.html)>): *[Box3Bounds3](box3bounds3.html)* **����:** |����|����|˵�� |------ |`...points`|<[Box3Vector3](box3vector3.html)>|����������3d�����, �����γɰ�Χ��|| **����ֵ:** *[Box3Bounds3](box3bounds3.html)* # Box3CameraMode ### Enumeration - [FIXED](box3cameramode.html#fixed) - [FOLLOW](box3cameramode.html#follow) - [FPS](box3cameramode.html#fps) ## Enumeration ���� ### FIXED ? **FIXED**: = "fixed" --- ### FOLLOW ? **FOLLOW**: = "follow" --- ### FPS ? **FPS**: = "fps" # Class: Box3Quaternion ## ���캯�� + **new Box3Quaternion**(`w`: number, `x`: number, `y`: number, `z`: number): *[Box3Quaternion](box3quaternion.html)* **����:** |����|���� |------ |`w`|number|| |`x`|number|| |`y`|number|| |`z`|number|| **����ֵ:** *[Box3Quaternion](box3quaternion.html)* ## ���� |����|���� |------ |`w`|number|| |`x`|number|| |`y`|number|| |`z`|number|| ## ���� ### add ? **add**(`v`: [Box3Quaternion](box3quaternion.html)): *[Box3Quaternion](box3quaternion.html)* **����:** |����|���� |------ |`v`|[Box3Quaternion](box3quaternion.html)|| **����ֵ:** *[Box3Quaternion](box3quaternion.html)* --- ### angle ? **angle**(`q`: [Box3Quaternion](box3quaternion.html)): *number* **����:** |����|���� |------ |`q`|[Box3Quaternion](box3quaternion.html)|| **����ֵ:** *number* --- ### clone ? **clone**(): *[Box3Quaternion](box3quaternion.html)* **����ֵ:** *[Box3Quaternion](box3quaternion.html)* --- ### copy ? **copy**(`q`: [Box3Quaternion](box3quaternion.html)): *[Box3Quaternion](box3quaternion.html)* **����:** |����|���� |------ |`q`|[Box3Quaternion](box3quaternion.html)|| **����ֵ:** *[Box3Quaternion](box3quaternion.html)* --- ### div ? **div**(`q`: [Box3Quaternion](box3quaternion.html)): *[Box3Quaternion](box3quaternion.html)??* **����:** |����|���� |------ |`q`|[Box3Quaternion](box3quaternion.html)|| **����ֵ:** *[Box3Quaternion](box3quaternion.html)??* --- ### dot ? **dot**(`q`: [Box3Quaternion](box3quaternion.html)): *number* **����:** |����|���� |------ |`q`|[Box3Quaternion](box3quaternion.html)|| **����ֵ:** *number* --- ### equals ? **equals**(`q`: [Box3Quaternion](box3quaternion.html), `tolerance`: number): *boolean* **����:** |����|����|Default |------ |`q`|[Box3Quaternion](box3quaternion.html)|-|| |`tolerance`|number|0.0001|| **����ֵ:** *boolean* --- ### getAxisAngle ? **getAxisAngle**(`q`: any): *object* **����:** |����|���� |------ |`q`|any|| **����ֵ:** *object*
  • **angle**: *number*
  • **axis**: *[Box3Vector3](box3vector3.html)*
  • --- ### inv ? **inv**(): *[Box3Quaternion](box3quaternion.html)* **����ֵ:** *[Box3Quaternion](box3quaternion.html)* --- ### mag ? **mag**(): *number* **����ֵ:** *number* --- ### mul ? **mul**(`q`: [Box3Quaternion](box3quaternion.html)): *[Box3Quaternion](box3quaternion.html)* **����:** |����|���� |------ |`q`|[Box3Quaternion](box3quaternion.html)|| **����ֵ:** *[Box3Quaternion](box3quaternion.html)* --- ### normalize ? **normalize**(): *[Box3Quaternion](box3quaternion.html)* **����ֵ:** *[Box3Quaternion](box3quaternion.html)* --- ### rotateX ? **rotateX**(`_rad`: number): *[Box3Quaternion](box3quaternion.html)* **����:** |����|���� |------ |`_rad`|number|| **����ֵ:** *[Box3Quaternion](box3quaternion.html)* ``` const ENTITY_QUAT = new Box3Quaternion(0,0,0,1) //ʵ��ר�ó�ʼ��Ԫ��, ������ʵ�干ͬʹ�� world.querySelectorAll('*').forEach((entity)=>{ entity.meshOrientation = ENTITY_QUAT.rotateX(Math.PI/2) //ʵ��X����ת90�� }) ``` --- ### rotateY ? **rotateY**(`_rad`: number): *[Box3Quaternion](box3quaternion.html)* **����:** |����|���� |------ |`_rad`|number|| **����ֵ:** *[Box3Quaternion](box3quaternion.html)* ``` const ENTITY_QUAT = new Box3Quaternion(0,0,0,1) //ʵ��ר�ó�ʼ��Ԫ��, ������ʵ�干ͬʹ�� world.querySelectorAll('*').forEach((entity)=>{ entity.meshOrientation = ENTITY_QUAT.rotateY(Math.PI/2) //ʵ��Y����ת90�� }) ``` --- ### rotateZ ? **rotateZ**(`_rad`: number): *[Box3Quaternion](box3quaternion.html)* **����:** |����|���� |------ |`_rad`|number|| **����ֵ:** *[Box3Quaternion](box3quaternion.html)* ``` const ENTITY_QUAT = new Box3Quaternion(0,0,0,1) //ʵ��ר�ó�ʼ��Ԫ��, ������ʵ�干ͬʹ�� world.querySelectorAll('*').forEach((entity)=>{ entity.meshOrientation = ENTITY_QUAT.rotateZ(Math.PI/2) //ʵ��Z����ת90�� }) ``` --- ### set ? **set**(`w`: number, `x`: number, `y`: number, `z`: number): *[Box3Quaternion](box3quaternion.html)* **����:** |����|���� |------ |`w`|number|| |`x`|number|| |`y`|number|| |`z`|number|| **����ֵ:** *[Box3Quaternion](box3quaternion.html)* --- ### slerp ? **slerp**(`q`: [Box3Quaternion](box3quaternion.html), `n`: number): *[Box3Quaternion](box3quaternion.html)* **����:** |����|���� |------ |`q`|[Box3Quaternion](box3quaternion.html)|| |`n`|number|| **����ֵ:** *[Box3Quaternion](box3quaternion.html)* --- ### sqrMag ? **sqrMag**(): *number* **����ֵ:** *number* --- ### sub ? **sub**(`v`: [Box3Quaternion](box3quaternion.html)): *[Box3Quaternion](box3quaternion.html)* **����:** |����|���� |------ |`v`|[Box3Quaternion](box3quaternion.html)|| **����ֵ:** *[Box3Quaternion](box3quaternion.html)* --- ### toString ? **toString**(): *string* **����ֵ:** *string* --- ### `Static` fromAxisAngle ? **fromAxisAngle**(`axis`: [Box3Vector3](box3vector3.html), `rad`: number): *[Box3Quaternion](box3quaternion.html)* **����:** |����|���� |------ |`axis`|[Box3Vector3](box3vector3.html)|| |`rad`|number|| **����ֵ:** *[Box3Quaternion](box3quaternion.html)* --- ### `Static` fromEuler ? **fromEuler**(`x`: number, `y`: number, `z`: number): *[Box3Quaternion](box3quaternion.html)* **����:** |����|���� |------ |`x`|number|| |`y`|number|| |`z`|number|| **����ֵ:** *[Box3Quaternion](box3quaternion.html)* --- ### `Static` rotationBetween ? **rotationBetween**(`a`: [Box3Vector3](box3vector3.html), `b`: [Box3Vector3](box3vector3.html)): *[Box3Quaternion](box3quaternion.html)* **����:** |����|���� |------ |`a`|[Box3Vector3](box3vector3.html)|| |`b`|[Box3Vector3](box3vector3.html)|| **����ֵ:** *[Box3Quaternion](box3quaternion.html)* # Class: Box3RGBAColor ## Box3RGBAColor **new Box3RGBAColor**(`r`: number, `g`: number, `b`: number, `a`: number): *[Box3RGBAColor](box3rgbacolor.html)* **����:** |����|���� |------ |`r`|number (0-1)|| |`g`|number (0-1)|| |`b`|number (0-1)|| |`a`|number (0-1)|| **ʾ������** ``` let red = new Box3RGBAColor(1, 0, 0, 1) ``` ע�⣬�˴��������ɫֵ��Χ��(0-1) ֮�䡣
    �����Ҫʹ�� RGB 255�����Խ���ɫֵ����255�����ɵõ�0-1����ֵ�� ``` function rgba(r, g, b, a = 255) { return new Box3RGBAColor(r / 255, g / 255, b / 255, a / 255); } let red = rgba(255, 0, 0, 1) // return Box3RGBAColor(1, 0, 0, 1) ``` --- ## ���� ### add ? **add**(`rgba`: [Box3RGBAColor](box3rgbacolor.html)): *[Box3RGBAColor](box3rgbacolor.html)* **����:** |����|���� |------ |`rgba`|[Box3RGBAColor](box3rgbacolor.html)|| **����ֵ:** *[Box3RGBAColor](box3rgbacolor.html)* --- ### addTo ? **addTo**(`rgb`: [Box3RGBColor](box3rgbcolor.html)): *[Box3RGBColor](box3rgbcolor.html)* **����:** |����|���� |------ |`rgb`|[Box3RGBColor](box3rgbcolor.html)|| **����ֵ:** *[Box3RGBColor](box3rgbcolor.html)* --- ### clone ? **clone**(): *[Box3RGBAColor](box3rgbacolor.html)* **����ֵ:** *[Box3RGBAColor](box3rgbacolor.html)* --- ### copy ? **copy**(`c`: [Box3RGBAColor](box3rgbacolor.html)): *[Box3RGBAColor](box3rgbacolor.html)* **����:** |����|���� |------ |`c`|[Box3RGBAColor](box3rgbacolor.html)|| **����ֵ:** *[Box3RGBAColor](box3rgbacolor.html)* --- ### div ? **div**(`rgba`: [Box3RGBAColor](box3rgbacolor.html)): *[Box3RGBAColor](box3rgbacolor.html)* **����:** |����|���� |------ |`rgba`|[Box3RGBAColor](box3rgbacolor.html)|| **����ֵ:** *[Box3RGBAColor](box3rgbacolor.html)* --- ### equals ? **equals**(`rgba`: [Box3RGBAColor](box3rgbacolor.html), `tolerance`: number): *boolean* **����:** |����|����|Default |------ |`rgba`|[Box3RGBAColor](box3rgbacolor.html)|-|| |`tolerance`|number|0.0001|| **����ֵ:** *boolean* --- ### lerp ? **lerp**(`rgba`: [Box3RGBAColor](box3rgbacolor.html), `n`: number): *[Box3RGBAColor](box3rgbacolor.html)* **����:** |����|���� |------ |`rgba`|[Box3RGBAColor](box3rgbacolor.html)|| |`n`|number|| **����ֵ:** *[Box3RGBAColor](box3rgbacolor.html)* --- ### mul ? **mul**(`rgba`: [Box3RGBAColor](box3rgbacolor.html)): *[Box3RGBAColor](box3rgbacolor.html)* **����:** |����|���� |------ |`rgba`|[Box3RGBAColor](box3rgbacolor.html)|| **����ֵ:** *[Box3RGBAColor](box3rgbacolor.html)* --- ### set ? **set**(`r`: number, `g`: number, `b`: number, `a`: number): *[Box3RGBAColor](box3rgbacolor.html)* **����:** |����|���� |------ |`r`|number|| |`g`|number|| |`b`|number|| |`a`|number|| **����ֵ:** *[Box3RGBAColor](box3rgbacolor.html)* --- ### sub ? **sub**(`rgba`: [Box3RGBAColor](box3rgbacolor.html)): *[Box3RGBAColor](box3rgbacolor.html)* **����:** |����|���� |------ |`rgba`|[Box3RGBAColor](box3rgbacolor.html)|| **����ֵ:** *[Box3RGBAColor](box3rgbacolor.html)* --- ### toString ? **toString**(): *string* **����ֵ:** *string* # Class: Box3RGBColor ## Box3RGBColor + **new Box3RGBColor**(`r`: number, `g`: number, `b`: number): *[Box3RGBColor](box3rgbcolor.html)* **����:** |����|���� |------ |`r`|number|| |`g`|number|| |`b`|number|| **ʾ������** ``` let red = new Box3RGBColor(1, 0, 0) ``` ע�⣬�˴��������ɫֵ��Χ��(0-1) ֮�䡣
    �����Ҫʹ�� RGB 255�����Խ���ɫֵ����255�����ɵõ�0-1����ֵ�� ``` function rgb(r, g, b) { return new Box3RGBColor(r / 255, g / 255, b / 255); } let red = rgb(255, 0, 0) // return Box3RGBColor(1, 0, 0) ``` --- ## ���� ### add ? **add**(`rgb`: [Box3RGBColor](box3rgbcolor.html)): *[Box3RGBColor](box3rgbcolor.html)* **����:** |����|���� |------ |`rgb`|[Box3RGBColor](box3rgbcolor.html)|| **����ֵ:** *[Box3RGBColor](box3rgbcolor.html)* --- ### clone ? **clone**(): *[Box3RGBColor](box3rgbcolor.html)* **����ֵ:** *[Box3RGBColor](box3rgbcolor.html)* --- ### copy ? **copy**(`c`: [Box3RGBAColor](box3rgbacolor.html)): *[Box3RGBColor](box3rgbcolor.html)* **����:** |����|���� |------ |`c`|[Box3RGBAColor](box3rgbacolor.html)|| **����ֵ:** *[Box3RGBColor](box3rgbcolor.html)* --- ### div ? **div**(`rgb`: [Box3RGBColor](box3rgbcolor.html)): *[Box3RGBColor](box3rgbcolor.html)* **����:** |����|���� |------ |`rgb`|[Box3RGBColor](box3rgbcolor.html)|| **����ֵ:** *[Box3RGBColor](box3rgbcolor.html)* --- ### equals ? **equals**(`rgb`: [Box3RGBColor](box3rgbcolor.html), `tolerance`: number): *boolean* **����:** |����|����|Default |------ |`rgb`|[Box3RGBColor](box3rgbcolor.html)|-|| |`tolerance`|number|0.0001|| **����ֵ:** *boolean* --- ### lerp ? **lerp**(`rgb`: [Box3RGBColor](box3rgbcolor.html), `n`: number): *[Box3RGBColor](box3rgbcolor.html)* **����:** |����|���� |------ |`rgb`|[Box3RGBColor](box3rgbcolor.html)|| |`n`|number|| **����ֵ:** *[Box3RGBColor](box3rgbcolor.html)* --- ### mul ? **mul**(`rgb`: [Box3RGBColor](box3rgbcolor.html)): *[Box3RGBColor](box3rgbcolor.html)* **����:** |����|���� |------ |`rgb`|[Box3RGBColor](box3rgbcolor.html)|| **����ֵ:** *[Box3RGBColor](box3rgbcolor.html)* --- ### set ? **set**(`r`: number, `g`: number, `b`: number, `a`: number): *[Box3RGBColor](box3rgbcolor.html)* **����:** |����|���� |------ |`r`|number|| |`g`|number|| |`b`|number|| |`a`|number|| **����ֵ:** *[Box3RGBColor](box3rgbcolor.html)* --- ### sub ? **sub**(`rgb`: [Box3RGBColor](box3rgbcolor.html)): *[Box3RGBColor](box3rgbcolor.html)* **����:** |����|���� |------ |`rgb`|[Box3RGBColor](box3rgbcolor.html)|| **����ֵ:** *[Box3RGBColor](box3rgbcolor.html)* --- ### toRGBA ? **toRGBA**(): *[Box3RGBAColor](box3rgbacolor.html)* **����ֵ:** *[Box3RGBAColor](box3rgbacolor.html)* --- ### toString ? **toString**(): *string* **����ֵ:** *string* --- ### `Static` random ? **random**(): *[Box3RGBColor](box3rgbcolor.html)* **����ֵ:** *[Box3RGBColor](box3rgbcolor.html)* # type Box3SelectorString type **Box3SelectorString** = string; ѡ����(Selectors)���Է���������Ϸ�ڵ�ȫ������Box3��ѡ�����ӿ��Dz��� DOM APIs ���衣 ``` const entities = world.querySelector('*'); // �����е�ȫ��ʵ�� const theChair = world.querySelector('#chair'); // ģ������Ϊ"chair"���׸�ʵ�� const players = world.querySelectorAll('player'); // ��Ϸ�е�ȫ����� const boxes = world.querySelectorAll('.box'); // ��ǩ����"box"��ȫ��ʵ�� const redBox = world.querySelector('.box .red');// ��ǩͬʱ����"box"�͡�red�����׸�ʵ�� ``` # Class: Box3SoundEffect ʹ�� `Sound()`������������ʱ������IJ����� - [sample](box3soundeffect.html#sample) - [gain](box3soundeffect.html#gain) - [gainRange](box3soundeffect.html#gainrange) - [pitch](box3soundeffect.html#pitch) - [pitchRange](box3soundeffect.html#pitchrange) - [radius](box3soundeffect.html#radius) ``` world.sound('audio/chat.mp3') ``` ## ���� ### sample ? **sample**: *string* = "" �����ļ�·���������ļ����������ϴ��Զ����������� `'audio/chat.mp3'`
    ��ָ�������ļ�·��ʱ������ȷ���ļ��Ѿ��ϴ����ļ��������С� --- ### radius ? **radius**: *number* = 32 ������Χ��Ĭ��Ϊ32������ʵ��Խ������������Խ������ --- ### gain ? **gain**: *number* = 1 �������档����Ϊ1����ֵԽ������Խ�졣 --- ### gainRange ? **gainRange**: *number* = 0 �������淽����㹫ʽΪ��`effect.gain + (Math.random() - 0.5) * effect.gainRange` --- ### pitch ? **pitch**: *number* = 1 �������档����Ϊ1������1����������Խ�졣С��1����������Խ���� --- ### pitchRange ? **pitchRange**: *number* = 0 �������淽����㹫ʽΪ��`effect.pitch + (Math.random() - 0.5) * effect.pitchRange` --- ## ��Ч�б� ``` // ��������������Ϊ������ world.ambientSound.sample = 'audio/rain.mp3'; ``` ### [World Sound ������Ч](box3world.html#������Ч) |����|Ĭ����Ƶ�ļ�|˵�� |------ |[ambientSound](box3world.html#ambientsound)||ѭ�����ŵı������֡�| |[playerJoinSound](box3world.html#playerjoinsound)||����ҽ�����Ϸ��ͨ��`world.onPlayerJoin()`����| |[playerLeaveSound](box3world.html#playerleavesound)||������뿪��Ϸ��ͨ��`world.onPlayerLeave()`����| |[chatSound](box3world.html#chatsound)||����Ƶ���յ��µ���Ϣ��ͨ��`world.onChat()`����| |[placeVoxelSound](box3world.html#placevoxelsound)|'audio/place_block.mp3'|���鱻���á�ͨ��`world.setVoxel()`����| |[breakVoxelSound](box3world.html#breavoxelsound)|'audio/break_block.mp3'|���鱻�ƻ���ͨ��`world.setVoxel()`����| ### [Entity Sound ʵ����Ч](box3entity.html#������Ч) |����|Ĭ����Ƶ�ļ�|˵�� |------ |[chatSound](box3entity.html#chatsound)||ʵ��˵��ʱ��ͨ�� `entity.say()`����| |[hurtSound](box3entity.html#hurtsound)||ʵ������ʱ��ͨ�� `entity.onTakeDamage()`����| |[dieSound](box3entity.html#diesound)||ʵ������ʱ��ͨ�� `entity.onDie()`����| |[interactSound](box3entity.html#interactsound)||ʵ�屻����ʱ��ͨ�� `entity.onInteract()`����| ### [Player Sound �����Ч](box3player.html#������Ч) |����|Ĭ����Ƶ�ļ�|˵�� |------ |[spawnSound](box3player.html#spawnsound)|'audio/spawn.mp3'|��Ҹ���ʱ��| |[jumpSound](box3player.html#jumpsound)|'audio/jump.mp3'|�����Ծʱ��| |[doubleJumpSound](box3player.html#doublejumpsound)|'audio/double_jump.mp3'|��Ҷ�����ʱ��| |[landSound](box3player.html#landsound)|'audio/land.mp3'|������ʱ��| |[enterWaterSound](box3player.html#enterwatersound)|'audio/dive.mp3'|��ҽ���Һ��ʱ��| |[leaveWaterSound](box3player.html#leavewatersound)|'audio/splash.mp3'|����뿪Һ��ʱ��| |[stepSound](box3player.html#stepsound)|'audio/step.mp3'|����������ߣ�����һ��ʱ��| |[swimSound](box3player.html#swimsound)|'audio/swim.mp3'|���������Ӿ����ǰ����ʱ��| |[crouchSound](box3player.html#crouchsound)||����¶�ʱ��| |[startFlySound](box3player.html#startflysound)||��ҿ�ʼ����ʱ��| |[stopFlySound](box3player.html#stopflysound)||��ҽ�������ʱ��| |[action0Sound](box3player.html#action0sound)||��Ұ���������/���ⰴťAʱ��| |[action1Sound](box3player.html#action1sound)||��Ұ�������Ҽ�/���ⰴťBʱ��| --- ## �ϴ���Ч �༭��Ŀǰ������34����Ч�������ڲ˵�- **[�ļ�����]** ������ `.mp3` �鿴������ļ��󣬻ᵯ�������ļ����������ԡ���� **λ��** ���ɸ����ļ�·�����ڽű���ʹ�ö�Ӧ�ķ������š� �����ϴ��Զ��������������� **[�ļ�����]** ���ڣ�������½Ǹ����ļӺŰ�ť- **[�ϴ���Ƶ]** �� --- ## �������������ʵ���Ч �ڻ�������������Чʱ��ϣ����ע�ذ�Ȩ��ʶ��ʹ����ij�����ߵ���Ʒ�����������Ʒ����ҳע����Դ�� �����Ƽ�һЩ��Ȩ�ز���վ��ֻҪ������վ��ʹ��Э�飬�����Խ�����������������Ʒ�С��󲿷���վ������վ�㣬�����Խ�����������빤�ߣ������Ķ��� - [ħ����](http://en.maoudamashii.com/) - [zapsplat](https://www.zapsplat.com/) - [soundbible](http://soundbible.com/) - [OpenGameArt](https://opengameart.org/art-search-advanced?keys=&field_art_type_tid%5B%5D=13&sort_by=count&sort_order=DESC) - [Сɭƽ�������Ч](https://taira-komori.jpn.org/freesoundtw.html) - [Free SFX](https://www.freesfx.co.uk/) - [FreeSound](https://freesound.org/) - [SoundJay](https://www.soundjay.com/) --- # Interface: Box3RaycastOptions �������߼��IJ������� |����|����|˵�� |------ |**maxDistance**|number|�������ߴ�Խ��������| |**ignoreFluid**|boolean|���Ϊ�棬����������Һ��| |**ignoreVoxel**|boolean|���Ϊ�棬���������ӷ���| |**ignoreEntities**|boolean|���Ϊ�棬����������ʵ��| # Class: Box3RaycastResult ���߼��(raycast)�Ľ�����������ߺ�������Ŀ�����Ϣ�� ### direction ? **direction**: *[Box3Vector3](box3vector3.html)* ���ߵķ��� --- ### distance ? **distance**: *number* ���ߴ�Խ�ľ��� --- ### hit ? **hit**: *boolean* ���Ϊ�棬�����߻���Ŀ�� --- ### hitEntity ? **hitEntity**: *[Box3Entity](box3entity.html) | null* ���������е�ʵ�� --- ### hitPosition ? **hitPosition**: *[Box3Vector3](box3vector3.html)* ���߻��е�λ�� --- ### hitVoxel ? **hitVoxel**: *number* ���������еķ���id (��δ���з��飬��Ϊ0) --- ### normal ? **normal**: *[Box3Vector3](box3vector3.html)* ����������ƽ��ķ����� --- ### origin ? **origin**: *[Box3Vector3](box3vector3.html)* ���ߵ���� --- ### voxelIndex ? **voxelIndex**: *[Box3Vector3](box3vector3.html)* ������߻��е��Ƿ��飬�򷵻������з�����������ꡣ # Class: Box3Animation Animation �������ɶ�World���硢Entityʵ�弰Player��ҵȶ������Ӷ������������ڱ��ز������У���ø��õ����ܣ����Ÿ�������ƽ���� ### ʾ������ �������� ��Ȧ��ɫ
    //�ȴ�ģ�Ϳ�����"����"��ģ��, ���������볡����
    const elevator = world.querySelector('#����-1') //��ȡ���ݰ�ʵ��
    elevator.fixed = true//��������Ӱ��
    elevator.collides = true//������ײ
    const startPos = [64, 11, 64]//���ݵ����λ��
    const endPos = [64, 50, 64]//���ݵ����λ��
    
    const ani = elevator.animate([// 1+5+1+2=9, ��ʱ��15�뱻�г�9��
        { position: startPos, duration: 1 },// 1/9 ��ʱ��ͣ���ڵ���
        { position: startPos, duration: 5 },// 5/9 ��ʱ�����ڵ�����¥���ƶ�
        { position: endPos, duration: 1 },// 1/9 ��ʱ��ͣ����¥��
        { position: endPos, duration: 2 },// 2/9 ��ʱ���¥���ص�����
    ], {
        duration: 16 * 15, //����һ��ѭ������ʱ15��,
        iterations: 1,//����ֻ����1��
        direction: Box3AnimationDirection.WRAP,//�ö���ʵ����յ�ص����
    })
    
    ani.onReady(() => {//��������ʼ����ʱ
        world.say('����׼������')
    })
    
    ani.onFinish(() => {//��������������ʱ
        world.say('�����Լ�ͣ��')
    })
    
    world.onPress(({ button }) => {
        if (button === Box3ButtonType.ACTION0) {//������²��Ŷ���
            ani.play({
                duration: 16 * 15, //����һ��ѭ������ʱ15��(ÿ��16֡),
                iterations: Infinity,//�������޴�ѭ������
                direction: Box3AnimationDirection.WRAP,//�ö���ʵ����յ�ص����
            })
        }
        else if (button === Box3ButtonType.ACTION1) {//�Ҽ�ֹͣ����
            ani.cancel()
        }
    })
    

    ��������

    //�ȴ�ģ�Ϳ�����"����"��ģ��, ���������볡����
    const elevator = world.querySelector('#����-1') //��ȡ���ݰ�ʵ��
    elevator.fixed = true//��������Ӱ��
    elevator.collides = true//������ײ
    const startPos = [64, 11, 64]//���ݵ����λ��
    const endPos = [64, 50, 64]//���ݵ����λ��
    
    const ani = elevator.animate([// 1+5+1+2=9, ��ʱ��15�뱻�г�9��
        { position: startPos, duration: 1 },// 1/9 ��ʱ��ͣ���ڵ���
        { position: startPos, duration: 5 },// 5/9 ��ʱ�����ڵ�����¥���ƶ�
        { position: endPos, duration: 1 },// 1/9 ��ʱ��ͣ����¥��
        { position: endPos, duration: 2 },// 2/9 ��ʱ���¥���ص�����
    ], {
        duration: 16 * 15, //����һ��ѭ������ʱ15��,
        iterations: 1,//����ֻ����1��
        direction: Box3AnimationDirection.WRAP,//�ö���ʵ����յ�ص����
    })
    
    ani.onReady(() => {//��������ʼ����ʱ
        world.say('����׼������')
    })
    
    ani.onFinish(() => {//��������������ʱ
        world.say('�����Լ�ͣ��')
    })
    
    world.onPress(({ button }) => {
        if (button === Box3ButtonType.ACTION0) {//������²��Ŷ���
            ani.play({
                duration: 16 * 15, //����һ��ѭ������ʱ15��(ÿ��16֡),
                iterations: Infinity,//�������޴�ѭ������
                direction: Box3AnimationDirection.WRAP,//�ö���ʵ����յ�ص����
            })
        }
        else if (button === Box3ButtonType.ACTION1) {//�Ҽ�ֹͣ����
            ani.cancel()
        }
    })
    

    ��Ȧ��ɫ

    //�ȴ�ģ�Ϳ�����"��Ԫ����"��ģ��, ���������볡����
    const vox = world.querySelector('#��Ԫ����-1') //��ȡʵ��
    vox.meshScale = vox.meshScale.scale(4) //��ʵ����4��
    
    const ani = vox.animate([
        { position: [0, 12, 0], meshColor: [1, 1, 0, 1] },
        { position: [0, 12, 127], meshColor: [1, 0, 0, 1] },
        { position: [127, 12, 127], meshColor: [0, 1, 0, 1] },
        { position: [127, 12, 0], meshColor: [0, 0, 1, 1] },
    ], {
        iterations: 3,//��3Ȧ
        direction: Box3AnimationDirection.WRAP,//���յ�ص����
        duration: 16 * 5, //��һȦ5��(ÿ��16֡)
    })
    
    ani.onReady(() => {//��������ʼ����ʱ
        world.say('��ʼ��Ȧ')
    })
    
    ani.onFinish(() => {//��������������ʱ
        world.say('��Ȧ����')
    })
    
    ``` //�ȴ�ģ�Ϳ�����"����"��ģ��, ���������볡���� const elevator = world.querySelector('#����-1') //��ȡ���ݰ�ʵ�� elevator.fixed = true//��������Ӱ�� elevator.collides = true//������ײ const startPos = [64, 11, 64]//���ݵ����λ�� const endPos = [64, 50, 64]//���ݵ����λ�� const ani = elevator.animate([// 1+5+1+2=9, ��ʱ��15�뱻�г�9�� { position: startPos, duration: 1 },// 1/9 ��ʱ��ͣ���ڵ��� { position: startPos, duration: 5 },// 5/9 ��ʱ�����ڵ�����¥���ƶ� { position: endPos, duration: 1 },// 1/9 ��ʱ��ͣ����¥�� { position: endPos, duration: 2 },// 2/9 ��ʱ���¥���ص����� ], { duration: 16 * 15, //����һ��ѭ������ʱ15��, iterations: 1,//����ֻ����1�� direction: Box3AnimationDirection.WRAP,//�ö���ʵ����յ�ص���� }) ani.onReady(() => {//��������ʼ����ʱ world.say('����׼������') }) ani.onFinish(() => {//��������������ʱ world.say('�����Լ�ͣ��') }) world.onPress(({ button }) => { if (button === Box3ButtonType.ACTION0) {//������²��Ŷ��� ani.play({ duration: 16 * 15, //����һ��ѭ������ʱ15��(ÿ��16֡), iterations: Infinity,//�������޴�ѭ������ direction: Box3AnimationDirection.WRAP,//�ö���ʵ����յ�ص���� }) } else if (button === Box3ButtonType.ACTION1) {//�Ҽ�ֹͣ���� ani.cancel() } }) ``` ### ��Ȧ��ɫ ## ���� ### currentTime ? **currentTime**: *number* = 0 �����ĵ�ǰ����ʱ�䣨���ٶ���֡�� --- ### playState ? **playState**: *[Box3AnimationPlaybackState](../enums/box3animationplaybackstate.md)* = Box3AnimationPlaybackState.PENDING ��ǰ��������״̬ --- ### playbackRate ? **playbackRate**: *number* = 1 ÿtick���������ٶ� --- ### startTime ? **startTime**: *number* = 0 ������ʼ��ʱ��tick --- ### target ? **target**: *TargetType* �������õĶ��󣨿�Ϊworld��player��entity�� --- ## ���ƶ������� ### play ? **play**: *function* ���Ż��߻ָ������IJ��� #### ��������: ? (`playback?`: Partial?[Box3AnimationPlaybackConfig](../interfaces/box3animationplaybackconfig.md)?): *void* **����:** |����|����| |------ |`playback?`|Partial?[Box3AnimationPlaybackConfig](../interfaces/box3animationplaybackconfig.md)?| --- ### cancel ? **cancel**: *function ȡ����ǰ���ŵĶ��� --- ## �Ͷ����йص��¼� ### onFinish ? **onFinish**: *[Box3EventChannel](../globals.md#box3eventchannel)?[Box3AnimationEvent](box3animationevent.html)?KeyframeType, TargetType??* ? **nextFinish**: *[Box3EventFuture](../globals.md#box3eventfuture)?[Box3AnimationEvent](box3animationevent.html)?KeyframeType, TargetType??* ��������������ʱ���� --- ### onReady ? **onReady**: *[Box3EventChannel](../globals.md#box3eventchannel)?[Box3AnimationEvent](box3animationevent.html)?KeyframeType, TargetType??* ? **nextReady**: *[Box3EventFuture](../globals.md#box3eventfuture)?[Box3AnimationEvent](box3animationevent.html)?KeyframeType, TargetType?? ��������ʼ����ʱ���� --- ## ���� ### keyframes ? **keyframes**: *function* �������еĶ����ؼ�֡ #### ���������� ? (): *Partial?KeyframeType?[]* --- ### then ? **then**?**T**?(`resolve`: function, `reject?`: undefined | function): *any* ���Ͳ��� ? **T** **����:** ? **resolve**: *function* ? (`event`: [Box3AnimationEvent](box3animationevent.html)?KeyframeType, TargetType?): *T* **����:** |����|����| |------ |`event`|[Box3AnimationEvent](box3animationevent.html)?KeyframeType, TargetType?| ?`��ѡ` **reject**: *undefined | function* **����ֵ:** *any* # Enumeration: Box3AnimationDirection �����IJ��ŷ��� |����|ֵ|˵�� |------ |ALTERNATE|'alternate'|����| |ALTERNATE_REVERSE|'alternate-reverse'|���浹��| |NORMAL|'normal'|��ͨ| |REVERSE|'reverse'|����| |WRAP|'wrap'|ѭ��| |WRAP_REVERSE|'wrap-reverse'|ѭ������| # Interface: Box3AnimationPlaybackConfig ���ڶ����������õIJ����� |����|����|˵�� |------ |delay|number|�����ӳ�| |direction|[Box3AnimationDirection](box3AnimationDirection.md)|���ŷ���| |duration|number|����ʱ��| |endDelay|number|�����ӳ�| |iterationStart|number|�������ſ�ʼʱ��| |iterations|number|�������Ŵ���| |startTick|number|��ʼʱ��| # Enumeration: Box3AnimationPlaybackState ��������״̬ |����|ֵ|˵�� |------ |FINISHED|'finished'|�����| |PENDING|'pending'|����ȴ�| |RUNNING|'running'|������| # Interface: Box3EntityKeyframe Entityʵ�嶯���ؼ�֡�������ɶ�Entity����Ч��Ĵ󲿷�����������Ч��������λ�ơ���С��ģ�͡���ɫ�ȵ� |����|����|˵�� |------ |duration|number|����ʱ��| |easeIn|[Box3Easing](box3easing.html)|����Ч��| |easeOut|[Box3Easing](box3easing.html)|����Ч��| |velocity|[Box3Vector3](box3vector3.html)|ʵ�峯��ij�������˶���������| |collides|boolean|ʵ���Ƿ����ײ| |mesh|string|mesh������ʵ������Ρ�`'mesh/*.vb'`| |meshColor|[Box3RGBAColor](box3rgbacolor.html)|ʵ�����ɫ| |meshScale|[Box3Vector3](box3vector3.html)|ʵ������ű���| |meshOrientation|Box3Quaternion|ʵ�����ת�Ƕ�| |meshMetalness|number|ʵ��Ľ�����| |meshEmissive|number|ʵ��ķ����| |meshShininess|number|ʵ��ķ����| |gravity|boolean|ʵ���Ƿ������| |fixed|boolean|ʵ���λ���Ƿ�̶�����| |mass|number|ʵ������| |friction|number|ʵ���ճ��(0 = ����1 = ճ)| |restitution|number|ʵ��ĵ���(0 = ��, 1 = ��)| |enableInteract|boolean|����ʵ����л���| |interactRadius|number|����ʵ�廥���ķ�Χ����ΧԽС�����������| |interactHint|string|����ʵ�廥����Χʱ��ʵ�����ϳ��ֵ���ʾ�ı�| |interactColor|[Box3RGBAColor](box3rgbacolor.html)|����ʵ�廥����Χʱ����ʾ�ı���������ɫ| |particleRate|number|ʵ��ÿ��������ӵ�����| |particleRateSpread|number|����ʵ��ÿ��������������������| |particleLimit|number|ʵ��ɲ�����������������| |particleLifetime|number|ʵ�������������ܴ�������| |particleLifetimeSpread|number|����ʵ�����������Ӵ��ʱ��������| |particleSize|number[]|ʵ�����������ӵĴ�С�仯| |particleSizeSpread|number|����ʵ�����������Ӵ�С�������| |particleColor|Box3RGBColor[]|ʵ�����������ӵ���ɫ�仯| |particleVelocity|[Box3Vector3](box3vector3.html)|ʵ�����������ӵij�ʼ�ٶ�| |particleVelocitySpread|[Box3Vector3](box3vector3.html)|����ʵ�����������ӳ�ʼ�ٶȵ������| |particleDamping|number|ʵ�����������ӵ�����ϵ��| |particleAcceleration|[Box3Vector3](box3vector3.html)|ʵ�����������ӵļ��ٶ�| |particleNoise|number|ʵ�����������Ӱڶ���������| |particleNoiseFrequency|number|ʵ�����������Ӱڶ���Ƶ��| # Interface: Box3PlayerKeyframe Player��Ҷ����ؼ�֡�������ɶ�Player�Ĵ󲿷�����������Ч��������ߴ硢��ɫ�������ȵ� |����|����|˵�� |------ |duration|number|����ʱ��| |easeIn|[Box3Easing](box3easing.html)|����Ч��| |easeOut|[Box3Easing](box3easing.html)|����Ч��| |cameraEntity|[Box3Entity](box3entity.html)|�ڵ�һ�˳��ӽ�(FPS)������˳Ƹ����ӽ�(FOLLOW)�£�����ӽ��������ʵ��| |cameraMode|[Box3CameraMode](box3cameramode.html)|�ӽ�ģʽ| |cameraPosition|[Box3Vector3](box3vector3.html)|�̶��ӽ�(FIXED)�£���ͷ���۾�λ��| |cameraTarget|[Box3Vector3](box3vector3.html)|�̶��ӽ�(FIXED)�¾�ͷ�������Ŀ���| |cameraUp|[Box3Vector3](box3vector3.html)|�̶��ӽ�(FIXED)�£���ͷ���ϵ�ʸ��| |scale|[Box3Vector3](box3vector3.html)|��ҵ����ű���| |color|[Box3RGBColor](box3rgbcolor.html)|��ҵ���ɫ| |colorLUT|string|������Ⱦ���������Ϸ�����ɫ��| |invisible|boolean|����Ƿ�����| |emissive|number|��ҵķ����| |metalness|number|��ҵĽ�����| |shininess|number|��ҵķ����| |showName|boolean|��������Ƿ���ʾ| # Interface: Box3WorldKeyframe World���綯���ؼ�֡�������ɶ�World�Ĵ󲿷�����������Ч���������������ꡢ����ѩ�����յȵ� |����|����|˵�� |------ |duration|number|����ʱ��| |easeIn|[Box3Easing](box3easing.html)|����Ч��| |easeOut|[Box3Easing](box3easing.html)|����Ч��| |gravity|number|��������| |airFriction|number|��������| |maxFog|number|�������| |fogColor|[Box3RGBColor](box3rgbcolor.html)|������ɫ| |fogHeightFalloff|number|��˥��������| |fogHeightOffset|number|����ʼ�߶�| |fogStartDistance|number|����ʼ����| |fogUniformDensity|number|�������ܶ�| |rainColor|[Box3RGBAColor](box3rgbacolor.html)|�����ɫ| |rainDensity|number|����ܶ�| |rainDirection|number|��ķ���| |rainInterference|number|����Ŷ�����| |rainSizeHi|number|��ε����ֱ��| |rainSizeLo|number|��ε���Сֱ��| |rainSpeed|number|����ٶ�| |snowColor|[Box3RGBAColor](box3rgbacolor.html)|ѩ����ɫ| |snowDensity|number|ѩ���ܶ�| |snowFallSpeed|number|ѩ���ٶ�| |snowSizeHi|number|ѩ�����ֱ��| |snowSizeLo|number|ѩ����Сֱ��| |snowSpinSpeed|number|ѩ�������ٶ�| |snowTexture|string|ѩ������| |lightMode|string|��������պͻ��������������| |sunFrequency|number|̫���˶���Ƶ��| |sunDirection|number|̫������������| |sunLight|number|̫������ɫ����| |sunPhase|number|̫�������������£�����յ�λ��| |lunarPhase|number|��������λ| |skyLeftLight|number|��������-X�᷽�����ɫ����| |skyRightLight|number|��������+X�᷽�����ɫ����| |skyBottomLight|number|��������-Y�᷽�����ɫ����| |skyTopLight|number|��������+Y�᷽�����ɫ����| |skyFrontLight|number|��������+Z�᷽�����ɫ����| |skyBackLight|number|��������-Z�᷽�����ɫ����| # Enumeration: Box3Easing �����Ļ���Ч����EaseIn���룬EaseOut���� |����|ֵ|˵�� |------ |BACK|'back'|����| |BOUNCE|'bounce'|����| |CIRCLE|'circle'|Բ| |ELASTIC|'elastic'|��Ƥ��| |EXP|'exp'|ָ��| |LINEAR|'linear'|����| |NONE|'none'|��| |QUADRATIC|'quadratic'|���η�| |SINE|'sine'|���Ҳ�| # Class: URL ���ڽ���URL�ĸ������� ���˽������Ϣ, ���Բ��� [https://developer.mozilla.org/zh-CN/docs/Web/API/URL](https://developer.mozilla.org/zh-CN/docs/Web/API/URL) ### hash ? **hash**: *string* �Ӿ���(#)��ʼ��URL���� ``` var url = new URL('https://jijimiao:12345678@shequ.codemao.cn:80/community?board=3#root') console.log(url.hash) // #root ``` --- ### host ? **host**: *string* �������͵�ǰURL�Ķ˿ں� ``` var url = new URL('https://jijimiao:12345678@shequ.codemao.cn:80/community?board=3#root') console.log(url.host) // shequ.codemao.cn:80 ``` --- ### hostname ? **hostname**: *string* ��ǰURL�������� ``` var url = new URL('https://jijimiao:12345678@shequ.codemao.cn:80/community?board=3#root') console.log(url.hostname) // shequ.codemao.cn ``` --- ### port ? **port**: *string* ��ǰURL�Ķ˿ں� ``` var url = new URL('https://jijimiao:12345678@shequ.codemao.cn:80/community?board=3#root') console.log(url.port) // 80 ``` --- ### href ? **href**: *string* ������URL ``` var url = new URL('https://jijimiao:12345678@shequ.codemao.cn:80/community?board=3#root') console.log(url.href) // https://jijimiao:12345678@shequ.codemao.cn:80/community?board=3#root ``` --- ### origin (ֻ��) ? **origin**: *string* ҳ����Դ������ ``` var url = new URL('https://jijimiao:12345678@shequ.codemao.cn:80/community?board=3#root') console.log(url.origin) // https://shequ.codemao.cn:80 ``` --- ### username ? **username**: *string* URL������ǰ���û��� ``` var url = new URL('https://jijimiao:12345678@shequ.codemao.cn:80/community?board=3#root') console.log(url.username) // jijimiao ``` --- ### password ? **password**: *string* URL������ǰ������ ``` var url = new URL('https://jijimiao:12345678@shequ.codemao.cn:80/community?board=3#root') console.log(url.password) // 12345678 ``` --- ### pathname ? **pathname**: *string* ��ǰURL��·������ ``` var url = new URL('https://jijimiao:12345678@shequ.codemao.cn:80/community?board=3#root') console.log(url.pathname) // /community ``` --- ### protocol ? **protocol**: *string* ��ǰURL��Э�� ``` var url = new URL('https://jijimiao:12345678@shequ.codemao.cn:80/community?board=3#root') console.log(url.protocol) // https: ``` --- ### search ? **search**: *string* ���ʺ�(?)��ʼ��URL�����б� ``` var url = new URL('https://jijimiao:12345678@shequ.codemao.cn:80/community?board=3#root') console.log(url.search) // ?board=3 ``` --- ### searchParams ? **searchParams**: *[URLSearchParams](urlsearchparams.html)* URL�����б���URLSearchParams��ʽ ``` var url = new URL('https://jijimiao:12345678@shequ.codemao.cn:80/community?board=3#root') console.log(url.searchParams) // board=3 ``` ``` // �������������в��� var boxUrl = new URL('https://box3.codemao.cn/?a=1&b=2&c=3') for (const [key, value] of boxUrl.searchParams) { console.log(key, value) } /* ���: a 1 b 2 c 3 */ ``` --- # Class: URLSearchParams URL�����IJ����б�, �� [https://box3.codemao.cn/?a=1&b=2&c=3](https://box3.codemao.cn/?a=1&b=2&c=3) Ϊ��, a=1&b=2&c=3�������URL���Ӹ����IJ����б�, �б�����a b c��3������, a b cҲ��Ϊ`����`(key), ���Ƕ�Ӧ��`ֵ`(value)�ֱ���1 2 3. �����ַ�����ʽ�IJ����б�, URLSearchParams�ṩһϵ�з���, �����ȡ���޸IJ����б�������� ���˽������Ϣ, ���Բ��� [https://developer.mozilla.org/zh-CN/docs/Web/API/URLSearchParams](https://developer.mozilla.org/zh-CN/docs/Web/API/URLSearchParams) ### append ? **append**(`name`: string, `value`: string): *void* �������б�β�������µ�`����`��`ֵ` ``` var params = new URLSearchParams() params.append('money','50') params.append('hp','100') params.append('atk','20') params.append('def','10') console.log(params)//���: money=50&hp=100&atk=20&def=10 ``` --- ### delete ? **delete**(`name`: string): *void* ɾ���ض�`����`�IJ��� ``` var params = new URLSearchParams({money:50,hp:100}) params.delete('money') console.log(params)//���: hp=100 ``` --- ### get ? **get**(`name`: string): *string* ��ȡ�ض�`����`��`ֵ` ``` var params = new URLSearchParams({money:50,hp:100}) params.delete('money') console.log(params)//���: hp=100 ``` --- ### getAll ? **getAll**(`name`: string): *string* ��ȡ�ض�`����`������ֵ ``` var params = new URLSearchParams() params.append('item','��') params.append('item','��') params.append('item','ͷ��') console.log(params.getAll('item')) ``` --- ### forEach ? **forEach**((`value`: string,`key`: string)=>any): *void* �������в�����`����`��`ֵ` ``` var params = new URLSearchParams({a:1,b:2,c:3}) params.forEach((value,key)=>{ console.log(value,key) }) ``` --- ### set ? **set**(`name`: string,`value`: string): *string* �����ض����ֲ�����`ֵ` ``` var params = new URLSearchParams({money:50, hp:100}) params.set('money',999) console.log(params) ``` --- ### has ? **has**(`name`: string): *boolean* ����Ƿ����ij��`����` ``` var params = new URLSearchParams({money:50, hp:100}) console.log(params.has('money')) // true console.log(params.has('atk')) // false ``` --- ### keys ? **keys**(): *Iterator* ��ȡ`����`������ ``` var params = new URLSearchParams({a:1,b:2,c:3}) var list = [...params.keys()] // ������ת������ console.log(JSON.stringify(list)) // ["a","b","c"] ``` --- ### values ? **values**(): *Iterator* ��ȡ`ֵ`������ ``` var params = new URLSearchParams({a:1,b:2,c:3}) var list = [...params.values()] // ������ת������ console.log(JSON.stringify(list)) // ["1","2","3"] ``` --- ### entries ? **entries**(): *Iterator* ��ȡ`��ֵ��`������ ``` var params = new URLSearchParams({a:1,b:2,c:3}) var list = [...params.entries()] // ������ת������ console.log(JSON.stringify(list)) // [["a","1"],["b","2"],["c","3"]] ``` --- ### sort ? **sort**(): *Iterator* ����`����`������������б� ``` var params = new URLSearchParams({b:2,c:3,a:1,e:1}) console.log(params) // b=2&c=3&a=1&e=1 params.sort() console.log(params) // a=1&b=2&c=3&e=1 ``` --- # Box3World �����ٲ��

    ����

    ��Ϣ�㲥

      - [world.say](box3world.html#worldsay) �����緢����Ϣ��������Ҷ���������Ƶ������

    ������Ƶ

      - [world.sound](box3world.html#worldsound) �����粥��������������ҿ���������

    ����ʵ��

      - [world.createEntity](box3world.html#worldcreateentity) ����ʵ�� - [world.entityQuota](box3world.html#worldentityquota) ���ص�ǰ�Կɴ�����ʵ������

    ����ʵ��

      - [world.querySelector](box3world.html#worldqueryselector) �������������ĵ�һ��ʵ�� - [world.querySelectorAll](box3world.html#worldqueryselectorall) ������������������ʵ�� - [world.searchBox](box3world.html#worldsearchbox) ����λ�÷�Χ�ڵ�����ʵ��

    ������

      - [world.addZone](box3world.html#worldaddzone) �������򴥷��� - [world.removeZone](box3world.html#worldremovezone) �Ƴ����򴥷��� - [world.zones](box3world.html#worldzones) ���ص�ǰ�������򴥷���

    ���߼��

      - [world.raycast](box3world.html#worldraycast) ��ָ��������һ�����ε�����
    ## ������Ƶ - [world.sound](box3world.html#worldsound) �����粥��������������ҿ��������� ## ����ʵ�� - [world.querySelector](box3world.html#worldqueryselector) �������������ĵ�һ��ʵ�� - [world.querySelectorAll](box3world.html#worldqueryselectorall) ������������������ʵ�� - [world.searchBox](box3world.html#worldsearchbox) ����λ�÷�Χ�ڵ�����ʵ�� ## ���߼�� - [world.raycast](box3world.html#worldraycast) ��ָ��������һ�����ε�����

    �¼�

    ��������

      - [world.onTick](box3world.html#worldontick) ��Ϸÿʱÿ�̸��� - [world.nextTick](box3world.html#worldontick) ��Ϸÿʱÿ�̸���(Promise)

    �����Ҽ���/�뿪

      - [world.onPlayerJoin](box3world.html#worldonplayerjoin) ��Ҽ�����Ϸ - [world.onPlayerLeave](box3world.html#worldonplayerleave) ��Ҽ�����Ϸ - [world.nextPlayerJoin](box3world.html#worldonplayerjoin) ��Ҽ�����Ϸ(Promise) - [world.nextPlayerLeave](box3world.html#worldonplayerleave) ����뿪��Ϸ(Promise)

    �����ҽ���

      - [world.onChat](box3world.html#worldonchat) ��ҷ������� - [world.nextChat](box3world.html#worldnextchat) ��ҷ�������(Promise)

    ��������ʵ�廥��

      - [world.onInteract](box3world.html#worldoninteract) �����ʵ����л��� - [world.nextInteract](box3world.html#worldoninteract) �����ʵ����л���(Promise)

    ����������

      - [world.onClick](box3world.html#worldonclick) ��ҵ������ʵ�� - [world.onPress](box3world.html#worldonpress) ��Ұ������ⰴť - [world.onRelease](box3world.html#worldonrelease) ����ɿ����ⰴť - [world.nextClick](box3world.html#worldonclick) ��ҵ������ʵ��(Promise) - [world.nextPress](box3world.html#worldonpress) ��Ұ������ⰴť(Promise) - [world.nextRelease](box3world.html#worldonrelease) ����ɿ����ⰴť(Promise)

    ���ս���¼�

      - [world.onTakeDamage](box3world.html#worldontakedamage) ʵ������ - [world.onDie](box3world.html#worldondie) ʵ������ - [world.onRespawn](box3world.html#worldonrespawn) ʵ�帴�� - [world.nextTakeDamage](box3world.html#worldonrespawn) ʵ������(Promise) - [world.nextDie](box3world.html#worldnextdie) ʵ������(Promise) - [world.nextRespawn](box3world.html#worldnextdie) ʵ�帴��(Promise)

    ���ʵ�屻����/����

      - [world.onEntityCreate](box3world.html#worldonentitycreate) ʵ�屻���� - [world.onEntityDestroy](box3world.html#worldonentitydestroy) ʵ�屻���� - [world.nextEntityCreate](box3world.html#worldonentitycreate) ʵ�屻����(Promise) - [world.nextEntityDestroy](box3world.html#worldonentitydestroy) ʵ�屻����(Promise)

    ���ʵ���ʵ����ײ

      - [world.onEntityContact](box3world.html#worldonentitycontact) ��ʵ�忪ʼ��ײ - [world.onEntitySeparate](box3world.html#worldonentityseparate) ��ʵ�������ײ - [world.nextEntityContact](box3world.html#worldonentitycontact) ��ʵ�忪ʼ��ײ(Promise) - [world.nextEntitySeparate](box3world.html#worldonentityseparate) ��ʵ�������ײ(Promise)

    ���ʵ��ͷ�����ײ

      - [world.onVoxelContact](box3world.html#worldonvoxelcontact) �뷽�鿪ʼ��ײ - [world.onVoxelSeparate](box3world.html#worldonvoxelseparate) �뷽�������ײ - [world.nextVoxelContact](box3world.html#worldonvoxelcontact) �뷽�鿪ʼ��ײ(Promise) - [world.nextVoxelSeparate](box3world.html#worldonvoxelseparate) �뷽�������ײ(Promise)

    ���ʵ���Һ����ײ

      - [world.onFluidEnter](box3world.html#worldonfluidenter) ��Һ�忪ʼ��ײ - [world.onFluidLeave](box3world.html#worldonfluidleave) ��Һ�������ײ - [world.nextFluidEnter](box3world.html#worldonfluidenter) ��Һ�忪ʼ��ײ(Promise) - [world.nextFluidLeave](box3world.html#worldonfluidleave) ��Һ�������ײ(Promise)
    ## �����Ҽ���/�뿪 - [world.onPlayerJoin](box3world.html#worldonplayerjoin) ��Ҽ�����Ϸ - [world.onPlayerLeave](box3world.html#worldonplayerleave) ��Ҽ�����Ϸ - [world.nextPlayerJoin](box3world.html#worldonplayerjoin) ��Ҽ�����Ϸ(Promise) - [world.nextPlayerLeave](box3world.html#worldonplayerleave) ����뿪��Ϸ(Promise) ## ��������ʵ�廥�� - [world.onInteract](box3world.html#worldoninteract) �����ʵ����л��� - [world.nextInteract](box3world.html#worldoninteract) �����ʵ����л���(Promise) ## ���ս���¼� - [world.onTakeDamage](box3world.html#worldontakedamage) ʵ������ - [world.onDie](box3world.html#worldondie) ʵ������ - [world.onRespawn](box3world.html#worldonrespawn) ʵ�帴�� - [world.nextTakeDamage](box3world.html#worldonrespawn) ʵ������(Promise) - [world.nextDie](box3world.html#worldnextdie) ʵ������(Promise) - [world.nextRespawn](box3world.html#worldnextdie) ʵ�帴��(Promise) ## ���ʵ���ʵ����ײ - [world.onEntityContact](box3world.html#worldonentitycontact) ��ʵ�忪ʼ��ײ - [world.onEntitySeparate](box3world.html#worldonentityseparate) ��ʵ�������ײ - [world.nextEntityContact](box3world.html#worldonentitycontact) ��ʵ�忪ʼ��ײ(Promise) - [world.nextEntitySeparate](box3world.html#worldonentityseparate) ��ʵ�������ײ(Promise) ## ���ʵ���Һ����ײ - [world.onFluidEnter](box3world.html#worldonfluidenter) ��Һ�忪ʼ��ײ - [world.onFluidLeave](box3world.html#worldonfluidleave) ��Һ�������ײ - [world.nextFluidEnter](box3world.html#worldonfluidenter) ��Һ�忪ʼ��ײ(Promise) - [world.nextFluidLeave](box3world.html#worldonfluidleave) ��Һ�������ײ(Promise)

    ����

    ��Ŀ

      - [world.projectName](box3world.html#worldprojectname) ��ͼ��Ŀ������ - [world.currentTick](box3world.html#worldcurrenttick) ����Ŀ�½��ۼƵ�Tick����

    ����

      - [world.gravity](box3world.html#worldgravity) ���� - [world.airFriction](box3world.html#worldairfriction) ��������

    ��������

      - [world.lightMode](box3world.html#worldlightmode) ����ģʽ - [world.sunFrequency](box3world.html#worldsunfrequency) ̫����̫�����е�Ƶ�� - [world.sunPhase](box3world.html#worldsunphase) ̫����λ�� - [world.lunarPhase](box3world.html#worldlunarphase) ��������λ - [world.sunDirection](box3world.html#worldsundirection) �չⷽ�� - [world.sunLight](box3world.html#worldsunlight) �չ����� - [world.skyLight](box3world.html#worldskyleftlight) ��ո�����������

    ��������

      - [world.maxFog](box3world.html#worldmaxfog) ������ - [world.fogColor](box3world.html#worldfogcolor) ������ɫ - [world.fogStartDistance](box3world.html#worldfogstartdistance) ����ʼ���� - [world.fogHeightOffset](box3world.html#worldfogheightoffset) ����ʼ�߶� - [world.fogUniformDensity](box3world.html#worldfoguniformdensity) �������ܶ� - [world.fogHeightFalloff](box3world.html#worldfogheightfalloff) ��˥������

    ��������

      - [world.rainSpeed](box3world.html#worldraindpeed) �������ٶ� - [world.rainColor](box3world.html#worldraincolor) �����ɫ - [world.rainDirection](box3world.html#worldraindirection) ��ķ��� - [world.rainDensity](box3world.html#worldraindensity) ����ܶ� - [world.rainInterference](box3world.html#worldraininterference) ����Ŷ���С - [world.rainSizeLo](box3world.html#worldrainsizelo) ��ε���Сֱ�� - [world.rainSizeHi](box3world.html#worldrainsizehi) ��ε����ֱ��

    ������ѩ

      - [world.snowColor](box3world.html#worldsnowcolor) ѩ����ɫ - [world.snowTexture](box3world.html#worldsnowcolor) ѩ������ - [world.snowDensity](box3world.html#worldsnowdensity) ѩ���ܶ� - [world.snowFallSpeed](box3world.html#worldsnowfallspeed) ѩ�������ٶ� - [world.snowSpinSpeed](box3world.html#worldsnowfallspeed) ѩ�������ٶ� - [world.snowSizeLo](box3world.html#worldsnowsizelo) ѩ����Сֱ�� - [world.snowSizeHi](box3world.html#worldsnowsizehi) ѩ�����ֱ��

    ����

      - [world.ambientSound](box3world.html#worldambientsound) �������� - [world.playerJoinSound](box3world.html#worldplayerjoinsound) ����ҽ�����Ϸ - [world.playerLeaveSound](box3world.html#worldplayerleavesound) ������뿪��Ϸ - [world.placeVoxelSound](box3world.html#worldplacevoxelsound) ���鱻���� - [world.breakVoxelSound](box3world.html#worldbreakvoxelsound) ���鱻�ƻ�
    ## ���� - [world.gravity](box3world.html#worldgravity) ���� - [world.airFriction](box3world.html#worldairfriction) �������� ## �������� - [world.maxFog](box3world.html#worldmaxfog) ������ - [world.fogColor](box3world.html#worldfogcolor) ������ɫ - [world.fogStartDistance](box3world.html#worldfogstartdistance) ����ʼ���� - [world.fogHeightOffset](box3world.html#worldfogheightoffset) ����ʼ�߶� - [world.fogUniformDensity](box3world.html#worldfoguniformdensity) �������ܶ� - [world.fogHeightFalloff](box3world.html#worldfogheightfalloff) ��˥������ ## ������ѩ - [world.snowColor](box3world.html#worldsnowcolor) ѩ����ɫ - [world.snowTexture](box3world.html#worldsnowcolor) ѩ������ - [world.snowDensity](box3world.html#worldsnowdensity) ѩ���ܶ� - [world.snowFallSpeed](box3world.html#worldsnowfallspeed) ѩ�������ٶ� - [world.snowSpinSpeed](box3world.html#worldsnowfallspeed) ѩ�������ٶ� - [world.snowSizeLo](box3world.html#worldsnowsizelo) ѩ����Сֱ�� - [world.snowSizeHi](box3world.html#worldsnowsizehi) ѩ�����ֱ��