≡
Products
▼
Support
▼
Company
▼
Forum
Ambiera Forum
Discussions, Help and Support.
Create a new account
,
Search
, or Login:
Create reply in
Randomize the positions of some scene nodes
Posted by:
(you are not logged in)
Enter the missing letter in: "Inte?national"
(you are not logged in)
Text:
[quote][b][/b] wrote: Here you go - a behavior that randomizes position (and optionally rotation) of all children of given mesh node and attaches them to its surface (doesn't work for terrain however). You can also specify minimal distance between the positions. Keep in mind that it may be slow for complex surfaces! It uses the JavaScript API Wrapper ([url]https://github.com/pkorzeniewski/ccb-js-api-wrapper[/url]) Let me know if something doesn't work :) [code] /* <behavior jsname="behavior_RandomizeNodesPositions" description="Randomize Nodes Positions"> <property name="RandomizeRotation" type="bool" default="false" /> <property name="MinimalDistance" type="int" default="0" /> </behavior> */ behavior_RandomizeNodesPositions = function() {}; behavior_RandomizeNodesPositions.prototype.onAnimate = function(_node) { this.onAnimate = function() {}; var self = this; var node = ccb.node.get(_node); var bbox = node.getWorldBBox(); var positions = []; function createPosition() { return new ccb.vector(ccb.core.randRange(bbox.min.x, bbox.max.x), node.getWorldPosition().y, ccb.core.randRange(bbox.min.z, bbox.max.z)); } function findPosition() { var position = createPosition(); if(self.MinimalDistance > 0) { _.every(positions, function(_position) { if(position.getDistanceTo(_position) < self.MinimalDistance) { position = findPosition(); return false; } return true; }); } return position; } _.each(node.getChildren(), function(child) { var position = findPosition(); var line = new ccb.line(position.clone().sub(new ccb.vector(0, 5000, 0)), position.clone().add(new ccb.vector(0, 10000, 0))); var intersection = node.getIntersectionWithLine(line); if(intersection) { position.y = intersection.y; } if(self.RandomizeRotation) { var rotation = child.getRotation().clone(); rotation.y = ccb.core.randRange(0, 360); child.setRotation(rotation); } child.setPosition(node.transformWorldPointToLocal(position)); positions.push(position); }); }; [/code][/quote]
Possible Codes
Feature
Code
Link
[url] www.example.com [/url]
Bold
[b]bold text[/b]
Image
[img]http://www.example.com/image.jpg[/img]
Quote
[quote]quoted text[/quote]
Code
[code]source code[/code]
Emoticons
Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact